本文整理汇总了Python中splinter.request_handler.request_handler.RequestHandler类的典型用法代码示例。如果您正苦于以下问题:Python RequestHandler类的具体用法?Python RequestHandler怎么用?Python RequestHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RequestHandlerTestCase
class RequestHandlerTestCase(unittest.TestCase):
def setUp(self):
self.request = RequestHandler()
self.request.connect(EXAMPLE_APP)
def test_should_receive_an_url_and_get_a_success_response(self):
self.assertTrue(self.request.status_code.is_success())
def test_should_start_a_request_with_localhost_and_get_localhost_as_hostname(self):
self.assertEqual("localhost", self.request.host)
def test_should_start_a_request_with_localhost_in_port_5000_and_get_5000_as_port(self):
self.assertEqual(5000, self.request.port)
def test_should_visit_alert_page_and_get_a_success_response(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "alert")
self.assertTrue(request.status_code.is_success())
def test_should_compare_app_index_with_404_and_get_false(self):
self.assertFalse(self.request.status_code == 404)
def test_should_get_an_absent_url_and_get_false_when_call_to_is_success(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
self.assertFalse(request.status_code.is_success())
def test_should_get_an_absent_url_and_raise_an_exception(self):
with self.assertRaises(HttpResponseError):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
request.ensure_success_response()
def test_should_get_an_exception_and_format_it_using_the_exception_attrs(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
try:
request.ensure_success_response()
except HttpResponseError as e:
exception = e.msg
self.assertEqual("404 - Not Found", exception)
def test_should_be_able_to_represent_exception_as_string(self):
"HttpResponseError exception should be representable as string"
error = HttpResponseError(404, "Not Found")
self.assertEqual("404 - Not Found", str(error))
def test_should_not_connect_to_non_http_protocols(self):
mockfile_path = "file://%s" % os.path.join(TESTS_ROOT, "mockfile.txt")
request = RequestHandler()
request.connect(mockfile_path)
self.assertTrue(request.status_code.is_success())
def test_should_connect_to_pages_with_query_string(self):
request = RequestHandler()
url = EXAMPLE_APP + "query?model"
request.connect(url)
self.assertTrue(request.status_code.is_success())
示例2: test_should_connect_to_https_protocols
def test_should_connect_to_https_protocols(self):
# We do not run an HTTPS server, but we know we handle https
# if we get an SSLError accessing a non-HTTPS site.
with self.assertRaises(SSLError):
request = RequestHandler()
url = EXAMPLE_APP.replace('http', 'https')
request.connect(url)
self.assertEqual(request.scheme, 'https')
示例3: test_should_get_an_exception_and_format_it
def test_should_get_an_exception_and_format_it(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
try:
request.ensure_success_response()
except HttpResponseError as e:
exception = e.msg
self.assertEqual("404 - Not Found", exception)
示例4: _transcripts_are_downloaded
def _transcripts_are_downloaded():
world.wait_for_ajax_complete()
request = RequestHandler()
DOWNLOAD_BUTTON = world.css_find(TRANSCRIPTS_BUTTONS["download_to_edit"][0]).first
url = DOWNLOAD_BUTTON["href"]
request.connect(url)
return request.status_code.is_success()
示例5: test_should_get_an_exception_and_format_it_using_the_exception_attrs
def test_should_get_an_exception_and_format_it_using_the_exception_attrs(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
try:
request.ensure_success_response()
except HttpResponseError as e:
exception = "I failed with code %d and reason %s" % (e.status_code, e.reason)
assert_equals(exception, "I failed with code 404 and reason Not Found")
示例6: RequestHandlerTestCase
class RequestHandlerTestCase(unittest.TestCase):
def setUp(self):
self.request = RequestHandler()
self.request.connect(EXAMPLE_APP)
def test_should_receive_an_url_and_get_a_success_response(self):
assert_true(self.request.status_code.is_success())
def test_should_start_a_request_with_localhost_and_get_localhost_as_hostname(self):
assert_equals(self.request.host, "localhost")
def test_should_start_a_request_with_localhost_in_port_5000_and_get_5000_as_port(self):
assert_equals(self.request.port, 5000)
def test_should_visit_alert_page_and_get_a_success_response(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "alert")
assert_true(request.status_code.is_success())
def test_should_compare_app_index_with_404_and_get_false(self):
assert_false(self.request.status_code == 404)
def test_should_get_an_absent_url_and_get_false_when_call_to_is_success(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
assert_false(request.status_code.is_success())
@raises(HttpResponseError)
def test_should_get_an_absent_url_and_raise_an_exception(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
request.ensure_success_response()
def test_should_get_an_exception_and_format_it_using_the_exception_attrs(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
try:
request.ensure_success_response()
except HttpResponseError as e:
exception = "I failed with code %d and reason %s" % (e.status_code, e.reason)
assert_equals(exception, "I failed with code 404 and reason Not Found")
示例7: test_should_be_able_to_connect_with_basic_auth
def test_should_be_able_to_connect_with_basic_auth(self):
request = RequestHandler()
url = 'http://admin:[email protected]:5000/authenticate'
request.connect(url)
self.assertEqual(b'Success!', request.response.read())
示例8: test_should_set_user_agent
def test_should_set_user_agent(self):
request = RequestHandler()
url = EXAMPLE_APP + 'useragent'
request.connect(url)
self.assertEqual(b'python/splinter', request.response.read())
示例9: test_should_connect_to_pages_with_query_string
def test_should_connect_to_pages_with_query_string(self):
request = RequestHandler()
url = EXAMPLE_APP + "query?model"
request.connect(url)
self.assertTrue(request.status_code.is_success())
示例10: test_should_not_connect_to_non_http_protocols
def test_should_not_connect_to_non_http_protocols(self):
mockfile_path = "file://%s" % os.path.join(TESTS_ROOT, "mockfile.txt")
request = RequestHandler()
request.connect(mockfile_path)
self.assertTrue(request.status_code.is_success())
示例11: test_should_get_an_absent_url_and_raise_an_exception
def test_should_get_an_absent_url_and_raise_an_exception(self):
with self.assertRaises(HttpResponseError):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
request.ensure_success_response()
示例12: test_is_success_should_be_false_when_url_does_not_exists
def test_is_success_should_be_false_when_url_does_not_exists(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
self.assertFalse(request.status_code.is_success())
示例13: test_should_visit_alert_page_and_get_a_success_response
def test_should_visit_alert_page_and_get_a_success_response(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "alert")
self.assertTrue(request.status_code.is_success())
示例14: setUp
def setUp(self):
self.request = RequestHandler()
self.request.connect(EXAMPLE_APP)
示例15: RequestHandlerTestCase
class RequestHandlerTestCase(unittest.TestCase):
def setUp(self):
self.request = RequestHandler()
self.request.connect(EXAMPLE_APP)
def test_should_receive_an_url_and_get_a_success_response(self):
self.assertTrue(self.request.status_code.is_success())
def test_should_start_a_request_with_localhost(self):
self.assertEqual("127.0.0.1", self.request.host)
def test_should_start_a_request_with_port_5000(self):
self.assertEqual(5000, self.request.port)
def test_should_visit_alert_page_and_get_a_success_response(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "alert")
self.assertTrue(request.status_code.is_success())
def test_should_compare_app_index_with_404_and_get_false(self):
self.assertFalse(self.request.status_code == 404)
def test_is_success_should_be_false_when_url_does_not_exists(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
self.assertFalse(request.status_code.is_success())
def test_should_get_an_absent_url_and_raise_an_exception(self):
with self.assertRaises(HttpResponseError):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
request.ensure_success_response()
def test_should_get_an_exception_and_format_it(self):
request = RequestHandler()
request.connect(EXAMPLE_APP + "page-that-doesnt-exists")
try:
request.ensure_success_response()
except HttpResponseError as e:
exception = e.msg
self.assertEqual("404 - Not Found", exception)
def test_should_be_able_to_represent_exception_as_string(self):
"HttpResponseError exception should be representable as string"
error = HttpResponseError(404, "Not Found")
self.assertEqual("404 - Not Found", str(error))
def test_should_not_connect_to_non_http_protocols(self):
mockfile_path = "file://%s" % os.path.join(TESTS_ROOT, "mockfile.txt")
request = RequestHandler()
request.connect(mockfile_path)
self.assertTrue(request.status_code.is_success())
def test_should_connect_to_pages_with_query_string(self):
request = RequestHandler()
url = EXAMPLE_APP + "query?model"
request.connect(url)
self.assertTrue(request.status_code.is_success())
def test_should_connect_to_https_protocols(self):
# We do not run an HTTPS server, but we know we handle https
# if we get an SSLError accessing a non-HTTPS site.
with self.assertRaises(SSLError):
request = RequestHandler()
url = EXAMPLE_APP.replace('http', 'https')
request.connect(url)
self.assertEqual(request.scheme, 'https')
def test_should_set_user_agent(self):
request = RequestHandler()
url = EXAMPLE_APP + 'useragent'
request.connect(url)
self.assertEqual(b'python/splinter', request.response.read())
def test_should_be_able_to_connect_with_basic_auth(self):
request = RequestHandler()
url = 'http://admin:[email protected]:5000/authenticate'
request.connect(url)
self.assertEqual(b'Success!', request.response.read())