Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 7f279edb61bf72174f77642d7994624923c75fdf @peritus committed Aug 13, 2011
Showing with 341 additions and 0 deletions.
  1. +113 −0 bootstrap.py
  2. +22 −0 buildout.cfg
  3. +26 −0 setup.py
  4. +82 −0 src/robotframework_httplib/__init__.py
  5. +4 −0 tests/__init__.txt
  6. +94 −0 tests/simple.txt
@@ -0,0 +1,113 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 102545 2009-08-06 14:49:47Z chrisw $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+ help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+ action="store_true", dest="distribute", default=True,
+ help="Use Disribute rather than Setuptools.")
+
+options, args = parser.parse_args()
+
+if options.version is not None:
+ VERSION = '==%s' % options.version
+else:
+ VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
+try:
+ import pkg_resources
+ if not hasattr(pkg_resources, '_distribute'):
+ to_reload = True
+ raise ImportError
+except ImportError:
+ ez = {}
+ if USE_DISTRIBUTE:
+ exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+ else:
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ if to_reload:
+ reload(pkg_resources)
+ else:
+ import pkg_resources
+
+if sys.platform == 'win32':
+ def quote(c):
+ if ' ' in c:
+ return '"%s"' % c # work around spawn lamosity on windows
+ else:
+ return c
+else:
+ def quote (c):
+ return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws = pkg_resources.working_set
+
+if USE_DISTRIBUTE:
+ requirement = 'distribute'
+else:
+ requirement = 'setuptools'
+
+if is_jython:
+ import subprocess
+
+ assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+ quote(tmpeggs), 'zc.buildout' + VERSION],
+ env=dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ).wait() == 0
+
+else:
+ assert os.spawnle(
+ os.P_WAIT, sys.executable, quote (sys.executable),
+ '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout' + VERSION)
+import zc.buildout.buildout
+zc.buildout.buildout.main(args)
+shutil.rmtree(tmpeggs)
@@ -0,0 +1,22 @@
+[buildout]
+newest = false
+
+extensions = buildout-versions
+
+develop = .
+
+parts = develop-eggs robotframework
+
+[develop-eggs]
+recipe = zc.recipe.egg
+eggs = robotframework-httplib
+
+[robotframework]
+recipe = zc.recipe.egg
+eggs =
+ robotframework
+entry-points = robotframework=robot:run_from_cli
+initialization =
+ import robot.runner
+arguments = sys.argv[1:], robot.runner.__doc__
+
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+from distutils.core import setup
+
+CLASSIFIERS = """
+Programming Language :: Python
+Topic :: Software Development :: Testing
+"""[1:-1]
+
+setup(
+ name = 'robotframework-httplib',
+ version = "0.0.1",
+ description = 'Robot Framework wrapper for livetest',
+ long_description = "Robot Framework wrapper for livetest",
+ author = 'Filip Noetzel',
+ author_email = 'filip+rfhttplib@j03.de',
+ url = 'http://code.google.com/p/robotframework-seleniumlibrary',
+ license = 'Beerware',
+ keywords = 'robotframework testing testautomation web http livetest webtest',
+ platforms = 'any',
+ classifiers = CLASSIFIERS.splitlines(),
+ package_dir = {'' : 'src'},
+ install_requires = ['robotframework', 'livetest'],
+ packages = ['robotframework_httplib']
+)
+
@@ -0,0 +1,82 @@
+import livetest
+
+class HTTP:
+
+ # internal
+
+ def __init__(self):
+ self._app = None
+ self._response = None
+
+ @property
+ def app(self):
+ if not self._app:
+ raise Exception('Not connected to any HTTP Host. Use "Connect" keyword first.')
+ return self._app
+
+ @property
+ def response(self):
+ if not self._response:
+ raise Exception('No request available, use e.g. GET to create one.')
+ return self._response
+
+ # setup
+
+ def connect(self, host):
+ self._app = livetest.TestApp(host)
+
+
+ # request
+
+ def GET(self, url):
+ self._response = self.app.get(url)
+
+ def POST(self, url):
+ self._response = self.app.post(url)
+
+ def follow_response(self):
+ self._response = self.response.follow()
+
+ # status code
+
+ def response_should_succeed(self):
+ assert int(self.response.status[0:3]) < 400, \
+ 'Response should have been success, but was "%s"' % self.response.status
+
+ def response_should_not_succeed(self):
+ assert int(self.response.status[0:3]) > 399, \
+ 'Response should have been success, but was "%s"' % self.response.status
+
+ def response_status_code_should_equal(self, code):
+ assert self.response.status.startswith(code), \
+ '"%s" does not start with "%s"' % (self.response.status, code)
+
+ def response_status_code_should_not_equal(self, code):
+ assert not self.response.status.startswith(code), \
+ '"%s" does start with "%s", but should not' % (self.response.status, code)
+
+ # headers
+
+ def response_should_have_header(self, header_name):
+ assert header_name in self.response.headers,\
+ 'Response did not have "%s" header, but should have' % header_name
+
+ def response_should_not_have_header(self, header_name):
+ assert not header_name in self.response.headers,\
+ 'Response did have "%s" header, but should not have' % header_name
+
+ def get_response_header(self, header_name):
+ self.response_should_have_header(header_name)
+ return self.response.headers[header_name]
+
+ def response_header_should_equal(self, header_name, expected):
+ self.response_should_have_header(header_name)
+ actual = self.response.headers[header_name]
+ assert actual == expected,\
+ 'Response header "%s" should have been "%s" but was "%s"' % (
+ header_name, expected, actual)
+
+ # debug
+
+ def show_response_in_browser(self, url):
+ self._response.showbrowser()
@@ -0,0 +1,4 @@
+*** Setting ***
+
+Library robotframework_httplib.HTTP
+
@@ -0,0 +1,94 @@
+*** Setting ***
+
+Library robotframework_httplib.HTTP
+
+*** Test Cases ***
+
+Error if GET before connect
+ ${msg}= Run Keyword And Expect Error * GET /
+ Should Start With ${msg} Not connected to any HTTP Host
+
+Test Should Work
+ [Setup] Connect httpstat.us
+ GET /
+
+GET 200
+ [Setup] Connect httpstat.us
+ GET /200
+ Response Status Code Should Equal 200
+
+GET 302
+ [Setup] Connect httpstat.us
+ GET /302
+ Response Status Code Should Equal 302
+
+GET 302 with follow
+ [Setup] Connect httpstat.us
+ GET /302
+ Follow Response
+ Response Status Code Should Equal 200
+
+GET 418
+ [Setup] Connect httpstat.us
+ GET /418
+ Response Status Code Should Equal 418 Unknown Error
+
+Response Should Succeed OK
+ [Setup] Connect httpstat.us
+ GET /200
+ Response Should Succeed
+
+Response Should Succeed FAIL
+ [Setup] Connect httpstat.us
+ GET /404
+ Run Keyword And Expect Error * Response Should Succeed
+
+Response Should Not Succeed OK
+ [Setup] Connect httpstat.us
+ GET /503
+ Response Should Not Succeed
+
+Response Should Not Succeed FAIL
+ [Setup] Connect httpstat.us
+ GET /201
+ Run Keyword And Expect Error * Response Should Not Succeed
+
+Response Should Have Header OK
+ [Setup] Connect httpstat.us
+ GET /302
+ Response Should Have Header Location
+
+Response Should Have Header FAIL
+ [Setup] Connect httpstat.us
+ GET /200
+ Run Keyword And Expect Error * Response Should Have Header Krytzmyk
+
+Response Should Not Have Header OK
+ [Setup] Connect httpstat.us
+ GET /404
+ Response Should Not Have Header Location
+
+Response Should Not Have Header FAIL
+ [Setup] Connect httpstat.us
+ GET /302
+ Run Keyword And Expect Error * Response Should Not Have Header Location
+
+Response Header Should Equal OK
+ [Setup] Connect httpstat.us
+ GET /302
+ Response Header Should Equal Location http://httpstat.us
+
+Response Header Should Equal FAIL
+ [Setup] Connect httpstat.us
+ GET /302
+ Run Keyword And Expect Error * Response Header Should Equal Location http://some.other.host/
+
+Response Header Should Not Equal OK
+ [Setup] Connect httpstat.us
+ GET /302
+ Response Header Should Not Equal Location http://and.another.host/
+
+Response Header Should Not Equal FAIL
+ [Setup] Connect httpstat.us
+ GET /302
+ Run Keyword And Expect Error * Response Header Should Not Equal Location http://httpstat.us

0 comments on commit 7f279ed

Please sign in to comment.