How to use _assert_response_code method in Django Test Plus

Best Python code snippet using django-test-plus_python

taskflow_testcase.py

Source:taskflow_testcase.py Github

copy

Full Screen

...146 if response is None and self.last_response is not None:147 return self.last_response148 else:149 return response150 def _assert_response_code(self, status_code, response=None, msg=None):151 response = self._which_response(response)152 self.assertEqual(response.status_code, status_code, msg)153 def response_200(self, response=None, msg=None):154 """Given response has status_code 200"""155 self._assert_response_code(200, response, msg)156 def response_201(self, response=None, msg=None):157 """Given response has status_code 201"""158 self._assert_response_code(201, response, msg)159 def response_204(self, response=None, msg=None):160 """Given response has status_code 204"""161 self._assert_response_code(204, response, msg)162 def response_301(self, response=None, msg=None):163 """Given response has status_code 301"""164 self._assert_response_code(301, response, msg)165 def response_302(self, response=None, msg=None):166 """Given response has status_code 302"""167 self._assert_response_code(302, response, msg)168 def response_400(self, response=None, msg=None):169 """Given response has status_code 400"""170 self._assert_response_code(400, response, msg)171 def response_401(self, response=None, msg=None):172 """Given response has status_code 401"""173 self._assert_response_code(401, response, msg)174 def response_403(self, response=None, msg=None):175 """Given response has status_code 403"""176 self._assert_response_code(403, response, msg)177 def response_404(self, response=None, msg=None):178 """Given response has status_code 404"""179 self._assert_response_code(404, response, msg)180 def response_405(self, response=None, msg=None):181 """Given response has status_code 405"""182 self._assert_response_code(405, response, msg)183 def response_409(self, response=None, msg=None):184 """Given response has status_code 409"""185 self._assert_response_code(409, response, msg)186 def response_410(self, response=None, msg=None):187 """Given response has status_code 410"""188 self._assert_response_code(410, response, msg)189 def get_check_200(self, url, *args, **kwargs):190 """Test that we can GET a page and it returns a 200"""191 response = self.get(url, *args, **kwargs)192 self.response_200(response)193 return response194 def assertLoginRequired(self, url, *args, **kwargs):195 """Ensure login is required to GET this URL"""196 response = self.get(url, *args, **kwargs)197 reversed_url = reverse(url, args=args, kwargs=kwargs)198 login_url = str(resolve_url(settings.LOGIN_URL))199 expected_url = "{0}?next={1}".format(login_url, reversed_url)200 self.assertRedirects(response, expected_url)201 def login(self, *args, **credentials):202 """Login a user"""...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...128 if response is None and self.last_response is not None:129 return self.last_response130 else:131 return response132 def _assert_response_code(self, status_code, response=None, msg=None):133 response = self._which_response(response)134 self.assertEqual(response.status_code, status_code, msg)135 def response_200(self, response=None, msg=None):136 """ Given response has status_code 200 """137 self._assert_response_code(200, response, msg)138 def response_201(self, response=None, msg=None):139 """ Given response has status_code 201 """140 self._assert_response_code(201, response, msg)141 def response_204(self, response=None, msg=None):142 """ Given response has status_code 204 """143 self._assert_response_code(204, response, msg)144 def response_301(self, response=None, msg=None):145 """ Given response has status_code 301 """146 self._assert_response_code(301, response, msg)147 def response_302(self, response=None, msg=None):148 """ Given response has status_code 302 """149 self._assert_response_code(302, response, msg)150 def response_400(self, response=None, msg=None):151 """ Given response has status_code 400 """152 self._assert_response_code(400, response, msg)153 def response_401(self, response=None, msg=None):154 """ Given response has status_code 401 """155 self._assert_response_code(401, response, msg)156 def response_403(self, response=None, msg=None):157 """ Given response has status_code 403 """158 self._assert_response_code(403, response, msg)159 def response_404(self, response=None, msg=None):160 """ Given response has status_code 404 """161 self._assert_response_code(404, response, msg)162 def response_405(self, response=None, msg=None):163 """ Given response has status_code 405 """164 self._assert_response_code(405, response, msg)165 def response_409(self, response=None, msg=None):166 """ Given response has status_code 409 """167 self._assert_response_code(409, response, msg)168 def response_410(self, response=None, msg=None):169 """ Given response has status_code 410 """170 self._assert_response_code(410, response, msg)171 def get_check_200(self, url, *args, **kwargs):172 """ Test that we can GET a page and it returns a 200 """173 response = self.get(url, *args, **kwargs)174 self.response_200(response)175 return response176 def assertLoginRequired(self, url, *args, **kwargs):177 """ Ensure login is required to GET this URL """178 response = self.get(url, *args, **kwargs)179 reversed_url = reverse(url, args=args, kwargs=kwargs)180 login_url = str(resolve_url(settings.LOGIN_URL))181 expected_url = "{0}?next={1}".format(login_url, reversed_url)182 self.assertRedirects(response, expected_url)183 def login(self, *args, **credentials):184 """ Login a user """...

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 Django Test Plus 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