How to use _assert_handler method in gabbi

Best Python code snippet using gabbi_python

test_handlers.py

Source:test_handlers.py Github

copy

Full Screen

...32 self.test.content_type = "text/plain"33 self.test.json_data = None34 self.test.test_data = {'response_strings': ['alpha', 'beta']}35 self.test.output = 'alpha\nbeta\n'36 self._assert_handler(handler)37 def test_response_strings_fail(self):38 handler = handlers.StringResponseHandler(self.test_class)39 self.test.content_type = "text/plain"40 self.test.json_data = None41 self.test.test_data = {'response_strings': ['alpha', 'beta']}42 self.test.output = 'alpha\nbta\n'43 with self.assertRaises(AssertionError):44 self._assert_handler(handler)45 def test_response_strings_fail_big_output(self):46 handler = handlers.StringResponseHandler(self.test_class)47 self.test.content_type = "text/plain"48 self.test.json_data = None49 self.test.test_data = {'response_strings': ['alpha', 'beta']}50 self.test.output = 'alpha\nbta\n' * 100051 with self.assertRaises(AssertionError) as cm:52 self._assert_handler(handler)53 msg = str(cm.exception)54 self.assertEqual(2036, len(msg))55 def test_response_strings_fail_big_payload(self):56 handler = handlers.StringResponseHandler(self.test_class)57 self.test.content_type = "application/json"58 self.test.test_data = {'response_strings': ['foobar']}59 self.test.json_data = {60 'objects': [{'name': 'cw',61 'location': 'barn'},62 {'name': 'chris',63 'location': 'house'}] * 10064 }65 self.test.output = json.dumps(self.test.json_data)66 with self.assertRaises(AssertionError) as cm:67 self._assert_handler(handler)68 msg = str(cm.exception)69 self.assertEqual(2038, len(msg))70 # Check the pprint of the json71 self.assertIn(' "location": "house"', msg)72 def test_response_json_paths(self):73 handler = handlers.JSONResponseHandler(self.test_class)74 self.test.content_type = "application/json"75 self.test.test_data = {'response_json_paths': {76 '$.objects[0].name': 'cow',77 '$.objects[1].location': 'house',78 }}79 self.test.json_data = {80 'objects': [{'name': 'cow',81 'location': 'barn'},82 {'name': 'chris',83 'location': 'house'}]84 }85 self._assert_handler(handler)86 def test_response_json_paths_fail_data(self):87 handler = handlers.JSONResponseHandler(self.test_class)88 self.test.content_type = "application/json"89 self.test.test_data = {'response_json_paths': {90 '$.objects[0].name': 'cow',91 '$.objects[1].location': 'house',92 }}93 self.test.json_data = {94 'objects': [{'name': 'cw',95 'location': 'barn'},96 {'name': 'chris',97 'location': 'house'}]98 }99 with self.assertRaises(AssertionError):100 self._assert_handler(handler)101 def test_response_json_paths_fail_path(self):102 handler = handlers.JSONResponseHandler(self.test_class)103 self.test.content_type = "application/json"104 self.test.test_data = {'response_json_paths': {105 '$.objects[1].name': 'cow',106 }}107 self.test.json_data = {108 'objects': [{'name': 'cow',109 'location': 'barn'},110 {'name': 'chris',111 'location': 'house'}]112 }113 with self.assertRaises(AssertionError):114 self._assert_handler(handler)115 def test_response_headers(self):116 handler = handlers.HeadersResponseHandler(self.test_class)117 self.test.response = {'content-type': 'text/plain'}118 self.test.test_data = {'response_headers': {119 'content-type': 'text/plain',120 }}121 self._assert_handler(handler)122 self.test.test_data = {'response_headers': {123 'Content-Type': 'text/plain',124 }}125 self._assert_handler(handler)126 def test_response_headers_regex(self):127 handler = handlers.HeadersResponseHandler(self.test_class)128 self.test.test_data = {'response_headers': {129 'content-type': '/text/plain/',130 }}131 self.test.response = {'content-type': 'text/plain; charset=UTF-8'}132 self._assert_handler(handler)133 def test_response_headers_fail_data(self):134 handler = handlers.HeadersResponseHandler(self.test_class)135 self.test.test_data = {'response_headers': {136 'content-type': 'text/plain',137 }}138 self.test.response = {'content-type': 'application/json'}139 with self.assertRaises(AssertionError) as failure:140 self._assert_handler(handler)141 self.assertIn("Expect header content-type with value text/plain,"142 " got application/json",143 str(failure.exception))144 def test_response_headers_fail_header(self):145 handler = handlers.HeadersResponseHandler(self.test_class)146 self.test.test_data = {'response_headers': {147 'location': '/somewhere',148 }}149 self.test.response = {'content-type': 'application/json'}150 with self.assertRaises(AssertionError) as failure:151 self._assert_handler(handler)152 self.assertIn("'location' header not present in response:",153 str(failure.exception))154 def _assert_handler(self, handler):155 # Instantiate our contained test class by naming its test156 # method and then run its tests to confirm.157 test = self.test('test_request')...

Full Screen

Full Screen

sing_up_test.py

Source:sing_up_test.py Github

copy

Full Screen

...7 def setUp(self):8 self.page_url = DOMAIN + "/signup"9 self.driver.delete_all_cookies()10 self.go_to_page()11 def _assert_handler(self):12 self.assertEqual([], self.driver.get_cookies())13 self.assertEqual(self.page_url, self.driver.current_url)14 def _sing_up_with_duplicate_val(self):15 self.go_to_page()16 self.set_username()17 self.set_email()18 self.set_password()19 self.set_confirm_password()20 self.sign_up()21 self.alert_handling(f'Duplicate field value: "{DEFAULT_EMAIL}". Please use another value!')22 def test_sing_up(self):23 self.set_username()24 self.set_email()25 self.set_password()26 self.set_confirm_password()27 self.sign_up()28 self.wait.until(ec.url_to_be(DOMAIN + "/me"))29 self.assertEqual(DOMAIN + "/me", self.driver.current_url)30 # sign up with duplicate credentials31 self._sing_up_with_duplicate_val()32 # clean up after successfully signed up33 self.login = LoginPage(self.driver)34 self.login.login()35 self.delete_account()36 def test_sing_up_with_no_username(self):37 self.set_username(username="")38 self.set_email()39 self.set_password()40 self.set_confirm_password()41 self.sign_up()42 self._assert_handler()43 def test_sing_up_with_no_email(self):44 self.set_username()45 self.set_email(email="")46 self.set_password()47 self.set_confirm_password()48 self.sign_up()49 self.assertEqual([], self.driver.get_cookies())50 self.assertEqual(self.page_url, self.driver.current_url)51 def test_sing_up_with_no_password(self):52 self.set_username()53 self.set_email()54 self.set_password(password="")55 self.set_confirm_password()56 self.sign_up()57 self._assert_handler()58 def test_sing_up_with_no_conf_password(self):59 self.set_username()60 self.set_email()61 self.set_password()62 self.set_confirm_password(password="")63 self.sign_up()64 self._assert_handler()65 def test_sing_up_with_wrong_conf_password(self):66 self.set_username()67 self.set_email()68 self.set_password()69 self.set_confirm_password(password="somerandompassword")70 self.sign_up()71 self._assert_handler()72 self.alert_handling('Invalid input data. Passwords are not the same!')73 def test_sing_up_with_wrong_email(self):74 self.set_username()75 self.set_email(email="test@gmail")76 self.set_password()77 self.set_confirm_password()78 self.sign_up()79 self._assert_handler()80 self.alert_handling('Invalid input data. Please provide a valid email')81 def test_sing_up_with_empty_fields(self):82 self.set_username(username="")83 self.set_email(email="")84 self.set_password(password="")85 self.set_confirm_password(password="")86 self.sign_up()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run gabbi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful