Skip to content

Commit 7f279ed

Browse files
committed
Initial commit
0 parents  commit 7f279ed

File tree

6 files changed

+341
-0
lines changed

6 files changed

+341
-0
lines changed

bootstrap.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
##############################################################################
2+
#
3+
# Copyright (c) 2006 Zope Corporation and Contributors.
4+
# All Rights Reserved.
5+
#
6+
# This software is subject to the provisions of the Zope Public License,
7+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11+
# FOR A PARTICULAR PURPOSE.
12+
#
13+
##############################################################################
14+
"""Bootstrap a buildout-based project
15+
16+
Simply run this script in a directory containing a buildout.cfg.
17+
The script accepts buildout command-line options, so you can
18+
use the -c option to specify an alternate configuration file.
19+
20+
$Id: bootstrap.py 102545 2009-08-06 14:49:47Z chrisw $
21+
"""
22+
23+
import os, shutil, sys, tempfile, urllib2
24+
from optparse import OptionParser
25+
26+
tmpeggs = tempfile.mkdtemp()
27+
28+
is_jython = sys.platform.startswith('java')
29+
30+
# parsing arguments
31+
parser = OptionParser()
32+
parser.add_option("-v", "--version", dest="version",
33+
help="use a specific zc.buildout version")
34+
parser.add_option("-d", "--distribute",
35+
action="store_true", dest="distribute", default=True,
36+
help="Use Disribute rather than Setuptools.")
37+
38+
options, args = parser.parse_args()
39+
40+
if options.version is not None:
41+
VERSION = '==%s' % options.version
42+
else:
43+
VERSION = ''
44+
45+
USE_DISTRIBUTE = options.distribute
46+
args = args + ['bootstrap']
47+
48+
to_reload = False
49+
try:
50+
import pkg_resources
51+
if not hasattr(pkg_resources, '_distribute'):
52+
to_reload = True
53+
raise ImportError
54+
except ImportError:
55+
ez = {}
56+
if USE_DISTRIBUTE:
57+
exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
58+
).read() in ez
59+
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
60+
else:
61+
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
62+
).read() in ez
63+
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
64+
65+
if to_reload:
66+
reload(pkg_resources)
67+
else:
68+
import pkg_resources
69+
70+
if sys.platform == 'win32':
71+
def quote(c):
72+
if ' ' in c:
73+
return '"%s"' % c # work around spawn lamosity on windows
74+
else:
75+
return c
76+
else:
77+
def quote (c):
78+
return c
79+
80+
cmd = 'from setuptools.command.easy_install import main; main()'
81+
ws = pkg_resources.working_set
82+
83+
if USE_DISTRIBUTE:
84+
requirement = 'distribute'
85+
else:
86+
requirement = 'setuptools'
87+
88+
if is_jython:
89+
import subprocess
90+
91+
assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
92+
quote(tmpeggs), 'zc.buildout' + VERSION],
93+
env=dict(os.environ,
94+
PYTHONPATH=
95+
ws.find(pkg_resources.Requirement.parse(requirement)).location
96+
),
97+
).wait() == 0
98+
99+
else:
100+
assert os.spawnle(
101+
os.P_WAIT, sys.executable, quote (sys.executable),
102+
'-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
103+
dict(os.environ,
104+
PYTHONPATH=
105+
ws.find(pkg_resources.Requirement.parse(requirement)).location
106+
),
107+
) == 0
108+
109+
ws.add_entry(tmpeggs)
110+
ws.require('zc.buildout' + VERSION)
111+
import zc.buildout.buildout
112+
zc.buildout.buildout.main(args)
113+
shutil.rmtree(tmpeggs)

buildout.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[buildout]
2+
newest = false
3+
4+
extensions = buildout-versions
5+
6+
develop = .
7+
8+
parts = develop-eggs robotframework
9+
10+
[develop-eggs]
11+
recipe = zc.recipe.egg
12+
eggs = robotframework-httplib
13+
14+
[robotframework]
15+
recipe = zc.recipe.egg
16+
eggs =
17+
robotframework
18+
entry-points = robotframework=robot:run_from_cli
19+
initialization =
20+
import robot.runner
21+
arguments = sys.argv[1:], robot.runner.__doc__
22+

setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
from distutils.core import setup
4+
5+
CLASSIFIERS = """
6+
Programming Language :: Python
7+
Topic :: Software Development :: Testing
8+
"""[1:-1]
9+
10+
setup(
11+
name = 'robotframework-httplib',
12+
version = "0.0.1",
13+
description = 'Robot Framework wrapper for livetest',
14+
long_description = "Robot Framework wrapper for livetest",
15+
author = 'Filip Noetzel',
16+
author_email = '[email protected]',
17+
url = 'http://code.google.com/p/robotframework-seleniumlibrary',
18+
license = 'Beerware',
19+
keywords = 'robotframework testing testautomation web http livetest webtest',
20+
platforms = 'any',
21+
classifiers = CLASSIFIERS.splitlines(),
22+
package_dir = {'' : 'src'},
23+
install_requires = ['robotframework', 'livetest'],
24+
packages = ['robotframework_httplib']
25+
)
26+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import livetest
2+
3+
class HTTP:
4+
5+
# internal
6+
7+
def __init__(self):
8+
self._app = None
9+
self._response = None
10+
11+
@property
12+
def app(self):
13+
if not self._app:
14+
raise Exception('Not connected to any HTTP Host. Use "Connect" keyword first.')
15+
return self._app
16+
17+
@property
18+
def response(self):
19+
if not self._response:
20+
raise Exception('No request available, use e.g. GET to create one.')
21+
return self._response
22+
23+
# setup
24+
25+
def connect(self, host):
26+
self._app = livetest.TestApp(host)
27+
28+
29+
# request
30+
31+
def GET(self, url):
32+
self._response = self.app.get(url)
33+
34+
def POST(self, url):
35+
self._response = self.app.post(url)
36+
37+
def follow_response(self):
38+
self._response = self.response.follow()
39+
40+
# status code
41+
42+
def response_should_succeed(self):
43+
assert int(self.response.status[0:3]) < 400, \
44+
'Response should have been success, but was "%s"' % self.response.status
45+
46+
def response_should_not_succeed(self):
47+
assert int(self.response.status[0:3]) > 399, \
48+
'Response should have been success, but was "%s"' % self.response.status
49+
50+
def response_status_code_should_equal(self, code):
51+
assert self.response.status.startswith(code), \
52+
'"%s" does not start with "%s"' % (self.response.status, code)
53+
54+
def response_status_code_should_not_equal(self, code):
55+
assert not self.response.status.startswith(code), \
56+
'"%s" does start with "%s", but should not' % (self.response.status, code)
57+
58+
# headers
59+
60+
def response_should_have_header(self, header_name):
61+
assert header_name in self.response.headers,\
62+
'Response did not have "%s" header, but should have' % header_name
63+
64+
def response_should_not_have_header(self, header_name):
65+
assert not header_name in self.response.headers,\
66+
'Response did have "%s" header, but should not have' % header_name
67+
68+
def get_response_header(self, header_name):
69+
self.response_should_have_header(header_name)
70+
return self.response.headers[header_name]
71+
72+
def response_header_should_equal(self, header_name, expected):
73+
self.response_should_have_header(header_name)
74+
actual = self.response.headers[header_name]
75+
assert actual == expected,\
76+
'Response header "%s" should have been "%s" but was "%s"' % (
77+
header_name, expected, actual)
78+
79+
# debug
80+
81+
def show_response_in_browser(self, url):
82+
self._response.showbrowser()

tests/__init__.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*** Setting ***
2+
3+
Library robotframework_httplib.HTTP
4+

tests/simple.txt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
*** Setting ***
2+
3+
Library robotframework_httplib.HTTP
4+
5+
*** Test Cases ***
6+
7+
Error if GET before connect
8+
${msg}= Run Keyword And Expect Error * GET /
9+
Should Start With ${msg} Not connected to any HTTP Host
10+
11+
Test Should Work
12+
[Setup] Connect httpstat.us
13+
GET /
14+
15+
GET 200
16+
[Setup] Connect httpstat.us
17+
GET /200
18+
Response Status Code Should Equal 200
19+
20+
GET 302
21+
[Setup] Connect httpstat.us
22+
GET /302
23+
Response Status Code Should Equal 302
24+
25+
GET 302 with follow
26+
[Setup] Connect httpstat.us
27+
GET /302
28+
Follow Response
29+
Response Status Code Should Equal 200
30+
31+
GET 418
32+
[Setup] Connect httpstat.us
33+
GET /418
34+
Response Status Code Should Equal 418 Unknown Error
35+
36+
Response Should Succeed OK
37+
[Setup] Connect httpstat.us
38+
GET /200
39+
Response Should Succeed
40+
41+
Response Should Succeed FAIL
42+
[Setup] Connect httpstat.us
43+
GET /404
44+
Run Keyword And Expect Error * Response Should Succeed
45+
46+
Response Should Not Succeed OK
47+
[Setup] Connect httpstat.us
48+
GET /503
49+
Response Should Not Succeed
50+
51+
Response Should Not Succeed FAIL
52+
[Setup] Connect httpstat.us
53+
GET /201
54+
Run Keyword And Expect Error * Response Should Not Succeed
55+
56+
Response Should Have Header OK
57+
[Setup] Connect httpstat.us
58+
GET /302
59+
Response Should Have Header Location
60+
61+
Response Should Have Header FAIL
62+
[Setup] Connect httpstat.us
63+
GET /200
64+
Run Keyword And Expect Error * Response Should Have Header Krytzmyk
65+
66+
Response Should Not Have Header OK
67+
[Setup] Connect httpstat.us
68+
GET /404
69+
Response Should Not Have Header Location
70+
71+
Response Should Not Have Header FAIL
72+
[Setup] Connect httpstat.us
73+
GET /302
74+
Run Keyword And Expect Error * Response Should Not Have Header Location
75+
76+
Response Header Should Equal OK
77+
[Setup] Connect httpstat.us
78+
GET /302
79+
Response Header Should Equal Location http://httpstat.us
80+
81+
Response Header Should Equal FAIL
82+
[Setup] Connect httpstat.us
83+
GET /302
84+
Run Keyword And Expect Error * Response Header Should Equal Location http://some.other.host/
85+
86+
Response Header Should Not Equal OK
87+
[Setup] Connect httpstat.us
88+
GET /302
89+
Response Header Should Not Equal Location http://and.another.host/
90+
91+
Response Header Should Not Equal FAIL
92+
[Setup] Connect httpstat.us
93+
GET /302
94+
Run Keyword And Expect Error * Response Header Should Not Equal Location http://httpstat.us

0 commit comments

Comments
 (0)