http.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2013 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. from lettuce import *
  16. import urllib
  17. # Basic request
  18. @step('request the URL (.*)')
  19. def request_url(step, url):
  20. """
  21. Performs one basic HTTP GET request. The resulting HTTPResponse object
  22. will we placed in world.last_http_response
  23. Parameters:
  24. url: the full URL to query
  25. """
  26. world.last_http_response = urllib.urlopen(url)
  27. @step('last http response status code should be ([0-9]+)')
  28. def check_last_response_code(step, code):
  29. """
  30. Checks whether the last call to request_url resulted in a response
  31. with the given (numeric) status code
  32. Fails if it does not, or if there never was a complete request_url
  33. operation
  34. """
  35. assert world.last_http_response != None, "No HTTP request made yet"
  36. assert int(code) == world.last_http_response.getcode(),\
  37. code + " != " +\
  38. str(world.last_http_response.getcode())