How to use assertURLEqual method in Django Test Plus

Best Python code snippet using django-test-plus_python

test_views.py

Source:test_views.py Github

copy

Full Screen

...55 def assertFormError(self, response, error):56 """Assert that error is found in response.context['form'] errors"""57 form_errors = list(itertools.chain(*response.context['form'].errors.values()))58 self.assertIn(force_text(error), form_errors)59 def assertURLEqual(self, url, expected, parse_qs=False):60 """61 Given two URLs, make sure all their components (the ones given by62 urlparse) are equal, only comparing components that are present in both63 URLs.64 If `parse_qs` is True, then the querystrings are parsed with QueryDict.65 This is useful if you don't want the order of parameters to matter.66 Otherwise, the query strings are compared as-is.67 """68 fields = ParseResult._fields69 for attr, x, y in zip(fields, urlparse(url), urlparse(expected)):70 if parse_qs and attr == 'query':71 x, y = QueryDict(x), QueryDict(y)72 if x and y and x != y:73 self.fail("%r != %r (%s doesn't match)" % (url, expected, attr))74@skipIfCustomUser75class AuthViewNamedURLTests(AuthViewsTestCase):76 urls = 'django.contrib.auth.urls'77 def test_named_urls(self):78 "Named URLs should be reversible"79 expected_named_urls = [80 ('login', [], {}),81 ('logout', [], {}),82 ('password_change', [], {}),83 ('password_change_done', [], {}),84 ('password_reset', [], {}),85 ('password_reset_done', [], {}),86 ('password_reset_confirm', [], {87 'uidb64': 'aaaaaaa',88 'token': '1111-aaaaa',89 }),90 ('password_reset_complete', [], {}),91 ]92 for name, args, kwargs in expected_named_urls:93 try:94 reverse(name, args=args, kwargs=kwargs)95 except NoReverseMatch:96 self.fail("Reversal of url named '%s' failed with NoReverseMatch" % name)97@skipIfCustomUser98class PasswordResetTest(AuthViewsTestCase):99 def test_email_not_found(self):100 """If the provided email is not registered, don't raise any error but101 also don't send any email."""102 response = self.client.get('/password_reset/')103 self.assertEqual(response.status_code, 200)104 response = self.client.post('/password_reset/', {'email': 'not_a_real_email@email.com'})105 self.assertEqual(response.status_code, 302)106 self.assertEqual(len(mail.outbox), 0)107 def test_email_found(self):108 "Email is sent if a valid email address is provided for password reset"109 response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})110 self.assertEqual(response.status_code, 302)111 self.assertEqual(len(mail.outbox), 1)112 self.assertTrue("http://" in mail.outbox[0].body)113 self.assertEqual(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)114 def test_email_found_custom_from(self):115 "Email is sent if a valid email address is provided for password reset when a custom from_email is provided."116 response = self.client.post('/password_reset_from_email/', {'email': 'staffmember@example.com'})117 self.assertEqual(response.status_code, 302)118 self.assertEqual(len(mail.outbox), 1)119 self.assertEqual("staffmember@example.com", mail.outbox[0].from_email)120 @override_settings(ALLOWED_HOSTS=['adminsite.com'])121 def test_admin_reset(self):122 "If the reset view is marked as being for admin, the HTTP_HOST header is used for a domain override."123 response = self.client.post('/admin_password_reset/',124 {'email': 'staffmember@example.com'},125 HTTP_HOST='adminsite.com'126 )127 self.assertEqual(response.status_code, 302)128 self.assertEqual(len(mail.outbox), 1)129 self.assertTrue("http://adminsite.com" in mail.outbox[0].body)130 self.assertEqual(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)131 # Skip any 500 handler action (like sending more mail...)132 @override_settings(DEBUG_PROPAGATE_EXCEPTIONS=True)133 def test_poisoned_http_host(self):134 "Poisoned HTTP_HOST headers can't be used for reset emails"135 # This attack is based on the way browsers handle URLs. The colon136 # should be used to separate the port, but if the URL contains an @,137 # the colon is interpreted as part of a username for login purposes,138 # making 'evil.com' the request domain. Since HTTP_HOST is used to139 # produce a meaningful reset URL, we need to be certain that the140 # HTTP_HOST header isn't poisoned. This is done as a check when get_host()141 # is invoked, but we check here as a practical consequence.142 with patch_logger('django.security.DisallowedHost', 'error') as logger_calls:143 response = self.client.post('/password_reset/',144 {'email': 'staffmember@example.com'},145 HTTP_HOST='www.example:dr.frankenstein@evil.tld'146 )147 self.assertEqual(response.status_code, 400)148 self.assertEqual(len(mail.outbox), 0)149 self.assertEqual(len(logger_calls), 1)150 # Skip any 500 handler action (like sending more mail...)151 @override_settings(DEBUG_PROPAGATE_EXCEPTIONS=True)152 def test_poisoned_http_host_admin_site(self):153 "Poisoned HTTP_HOST headers can't be used for reset emails on admin views"154 with patch_logger('django.security.DisallowedHost', 'error') as logger_calls:155 response = self.client.post('/admin_password_reset/',156 {'email': 'staffmember@example.com'},157 HTTP_HOST='www.example:dr.frankenstein@evil.tld'158 )159 self.assertEqual(response.status_code, 400)160 self.assertEqual(len(mail.outbox), 0)161 self.assertEqual(len(logger_calls), 1)162 def _test_confirm_start(self):163 # Start by creating the email164 response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})165 self.assertEqual(len(mail.outbox), 1)166 return self._read_signup_email(mail.outbox[0])167 def _read_signup_email(self, email):168 urlmatch = re.search(r"https?://[^/]*(/.*reset/\S*)", email.body)169 self.assertTrue(urlmatch is not None, "No URL found in sent email")170 return urlmatch.group(), urlmatch.groups()[0]171 def test_confirm_valid(self):172 url, path = self._test_confirm_start()173 response = self.client.get(path)174 # redirect to a 'complete' page:175 self.assertContains(response, "Please enter your new password")176 def test_confirm_valid_base36(self):177 # Remove in Django 1.7178 url, path = self._test_confirm_start()179 path_parts = path.strip("/").split("/")180 # construct an old style (base36) URL by converting the base64 ID181 path_parts[1] = int_to_base36(int(urlsafe_base64_decode(path_parts[1])))182 response = self.client.get("/%s/%s-%s/" % tuple(path_parts))183 # redirect to a 'complete' page:184 self.assertContains(response, "Please enter your new password")185 def test_confirm_invalid(self):186 url, path = self._test_confirm_start()187 # Let's munge the token in the path, but keep the same length,188 # in case the URLconf will reject a different length.189 path = path[:-5] + ("0" * 4) + path[-1]190 response = self.client.get(path)191 self.assertContains(response, "The password reset link was invalid")192 def test_confirm_invalid_user(self):193 # Ensure that we get a 200 response for a non-existant user, not a 404194 response = self.client.get('/reset/123456/1-1/')195 self.assertContains(response, "The password reset link was invalid")196 def test_confirm_invalid_user_base36(self):197 # Remove in Django 1.7198 response = self.client.get('/reset/123456-1-1/')199 self.assertContains(response, "The password reset link was invalid")200 def test_confirm_overflow_user(self):201 # Ensure that we get a 200 response for a base36 user id that overflows int202 response = self.client.get('/reset/zzzzzzzzzzzzz/1-1/')203 self.assertContains(response, "The password reset link was invalid")204 def test_confirm_overflow_user_base36(self):205 # Remove in Django 1.7206 response = self.client.get('/reset/zzzzzzzzzzzzz-1-1/')207 self.assertContains(response, "The password reset link was invalid")208 def test_confirm_invalid_post(self):209 # Same as test_confirm_invalid, but trying210 # to do a POST instead.211 url, path = self._test_confirm_start()212 path = path[:-5] + ("0" * 4) + path[-1]213 self.client.post(path, {214 'new_password1': 'anewpassword',215 'new_password2': ' anewpassword',216 })217 # Check the password has not been changed218 u = User.objects.get(email='staffmember@example.com')219 self.assertTrue(not u.check_password("anewpassword"))220 def test_confirm_complete(self):221 url, path = self._test_confirm_start()222 response = self.client.post(path, {'new_password1': 'anewpassword',223 'new_password2': 'anewpassword'})224 # Check the password has been changed225 u = User.objects.get(email='staffmember@example.com')226 self.assertTrue(u.check_password("anewpassword"))227 # Check we can't use the link again228 response = self.client.get(path)229 self.assertContains(response, "The password reset link was invalid")230 def test_confirm_different_passwords(self):231 url, path = self._test_confirm_start()232 response = self.client.post(path, {'new_password1': 'anewpassword',233 'new_password2': 'x'})234 self.assertFormError(response, SetPasswordForm.error_messages['password_mismatch'])235 def test_reset_redirect_default(self):236 response = self.client.post('/password_reset/',237 {'email': 'staffmember@example.com'})238 self.assertEqual(response.status_code, 302)239 self.assertURLEqual(response.url, '/password_reset/done/')240 def test_reset_custom_redirect(self):241 response = self.client.post('/password_reset/custom_redirect/',242 {'email': 'staffmember@example.com'})243 self.assertEqual(response.status_code, 302)244 self.assertURLEqual(response.url, '/custom/')245 def test_reset_custom_redirect_named(self):246 response = self.client.post('/password_reset/custom_redirect/named/',247 {'email': 'staffmember@example.com'})248 self.assertEqual(response.status_code, 302)249 self.assertURLEqual(response.url, '/password_reset/')250 def test_confirm_redirect_default(self):251 url, path = self._test_confirm_start()252 response = self.client.post(path, {'new_password1': 'anewpassword',253 'new_password2': 'anewpassword'})254 self.assertEqual(response.status_code, 302)255 self.assertURLEqual(response.url, '/reset/done/')256 def test_confirm_redirect_custom(self):257 url, path = self._test_confirm_start()258 path = path.replace('/reset/', '/reset/custom/')259 response = self.client.post(path, {'new_password1': 'anewpassword',260 'new_password2': 'anewpassword'})261 self.assertEqual(response.status_code, 302)262 self.assertURLEqual(response.url, '/custom/')263 def test_confirm_redirect_custom_named(self):264 url, path = self._test_confirm_start()265 path = path.replace('/reset/', '/reset/custom/named/')266 response = self.client.post(path, {'new_password1': 'anewpassword',267 'new_password2': 'anewpassword'})268 self.assertEqual(response.status_code, 302)269 self.assertURLEqual(response.url, '/password_reset/')270@override_settings(AUTH_USER_MODEL='auth.CustomUser')271class CustomUserPasswordResetTest(AuthViewsTestCase):272 fixtures = ['custom_user.json']273 def _test_confirm_start(self):274 # Start by creating the email275 response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})276 self.assertEqual(response.status_code, 302)277 self.assertEqual(len(mail.outbox), 1)278 return self._read_signup_email(mail.outbox[0])279 def _read_signup_email(self, email):280 urlmatch = re.search(r"https?://[^/]*(/.*reset/\S*)", email.body)281 self.assertTrue(urlmatch is not None, "No URL found in sent email")282 return urlmatch.group(), urlmatch.groups()[0]283 def test_confirm_valid_custom_user(self):284 url, path = self._test_confirm_start()285 response = self.client.get(path)286 # redirect to a 'complete' page:287 self.assertContains(response, "Please enter your new password")288@skipIfCustomUser289class ChangePasswordTest(AuthViewsTestCase):290 def fail_login(self, password='password'):291 response = self.client.post('/login/', {292 'username': 'testclient',293 'password': password,294 })295 self.assertFormError(response, AuthenticationForm.error_messages['invalid_login'] % {296 'username': User._meta.get_field('username').verbose_name297 })298 def logout(self):299 response = self.client.get('/logout/')300 def test_password_change_fails_with_invalid_old_password(self):301 self.login()302 response = self.client.post('/password_change/', {303 'old_password': 'donuts',304 'new_password1': 'password1',305 'new_password2': 'password1',306 })307 self.assertFormError(response, PasswordChangeForm.error_messages['password_incorrect'])308 def test_password_change_fails_with_mismatched_passwords(self):309 self.login()310 response = self.client.post('/password_change/', {311 'old_password': 'password',312 'new_password1': 'password1',313 'new_password2': 'donuts',314 })315 self.assertFormError(response, SetPasswordForm.error_messages['password_mismatch'])316 def test_password_change_succeeds(self):317 self.login()318 response = self.client.post('/password_change/', {319 'old_password': 'password',320 'new_password1': 'password1',321 'new_password2': 'password1',322 })323 self.fail_login()324 self.login(password='password1')325 def test_password_change_done_succeeds(self):326 self.login()327 response = self.client.post('/password_change/', {328 'old_password': 'password',329 'new_password1': 'password1',330 'new_password2': 'password1',331 })332 self.assertEqual(response.status_code, 302)333 self.assertURLEqual(response.url, '/password_change/done/')334 @override_settings(LOGIN_URL='/login/')335 def test_password_change_done_fails(self):336 response = self.client.get('/password_change/done/')337 self.assertEqual(response.status_code, 302)338 self.assertURLEqual(response.url, '/login/?next=/password_change/done/')339 def test_password_change_redirect_default(self):340 self.login()341 response = self.client.post('/password_change/', {342 'old_password': 'password',343 'new_password1': 'password1',344 'new_password2': 'password1',345 })346 self.assertEqual(response.status_code, 302)347 self.assertURLEqual(response.url, '/password_change/done/')348 def test_password_change_redirect_custom(self):349 self.login()350 response = self.client.post('/password_change/custom/', {351 'old_password': 'password',352 'new_password1': 'password1',353 'new_password2': 'password1',354 })355 self.assertEqual(response.status_code, 302)356 self.assertURLEqual(response.url, '/custom/')357 def test_password_change_redirect_custom_named(self):358 self.login()359 response = self.client.post('/password_change/custom/named/', {360 'old_password': 'password',361 'new_password1': 'password1',362 'new_password2': 'password1',363 })364 self.assertEqual(response.status_code, 302)365 self.assertURLEqual(response.url, '/password_reset/')366@skipIfCustomUser367class LoginTest(AuthViewsTestCase):368 def test_current_site_in_context_after_login(self):369 response = self.client.get(reverse('login'))370 self.assertEqual(response.status_code, 200)371 if Site._meta.installed:372 site = Site.objects.get_current()373 self.assertEqual(response.context['site'], site)374 self.assertEqual(response.context['site_name'], site.name)375 else:376 self.assertIsInstance(response.context['site'], RequestSite)377 self.assertTrue(isinstance(response.context['form'], AuthenticationForm),378 'Login form is not an AuthenticationForm')379 def test_security_check(self, password='password'):380 login_url = reverse('login')381 # Those URLs should not pass the security check382 for bad_url in ('http://example.com',383 'http:///example.com',384 'https://example.com',385 'ftp://exampel.com',386 '///example.com',387 '//example.com',388 'javascript:alert("XSS")'):389 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {390 'url': login_url,391 'next': REDIRECT_FIELD_NAME,392 'bad_url': urlquote(bad_url),393 }394 response = self.client.post(nasty_url, {395 'username': 'testclient',396 'password': password,397 })398 self.assertEqual(response.status_code, 302)399 self.assertFalse(bad_url in response.url,400 "%s should be blocked" % bad_url)401 # These URLs *should* still pass the security check402 for good_url in ('/view/?param=http://example.com',403 '/view/?param=https://example.com',404 '/view?param=ftp://exampel.com',405 'view/?param=//example.com',406 'https://testserver/',407 'HTTPS://testserver/',408 '//testserver/',409 '/url%20with%20spaces/'): # see ticket #12534410 safe_url = '%(url)s?%(next)s=%(good_url)s' % {411 'url': login_url,412 'next': REDIRECT_FIELD_NAME,413 'good_url': urlquote(good_url),414 }415 response = self.client.post(safe_url, {416 'username': 'testclient',417 'password': password,418 })419 self.assertEqual(response.status_code, 302)420 self.assertTrue(good_url in response.url,421 "%s should be allowed" % good_url)422 def test_login_form_contains_request(self):423 # 15198424 response = self.client.post('/custom_requestauth_login/', {425 'username': 'testclient',426 'password': 'password',427 }, follow=True)428 # the custom authentication form used by this login asserts429 # that a request is passed to the form successfully.430 def test_login_csrf_rotate(self, password='password'):431 """432 Makes sure that a login rotates the currently-used CSRF token.433 """434 # Do a GET to establish a CSRF token435 # TestClient isn't used here as we're testing middleware, essentially.436 req = HttpRequest()437 CsrfViewMiddleware().process_view(req, login_view, (), {})438 req.META["CSRF_COOKIE_USED"] = True439 resp = login_view(req)440 resp2 = CsrfViewMiddleware().process_response(req, resp)441 csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)442 token1 = csrf_cookie.coded_value443 # Prepare the POST request444 req = HttpRequest()445 req.COOKIES[settings.CSRF_COOKIE_NAME] = token1446 req.method = "POST"447 req.POST = {'username': 'testclient', 'password': password, 'csrfmiddlewaretoken': token1}448 req.REQUEST = req.POST449 # Use POST request to log in450 SessionMiddleware().process_request(req)451 CsrfViewMiddleware().process_view(req, login_view, (), {})452 req.META["SERVER_NAME"] = "testserver" # Required to have redirect work in login view453 req.META["SERVER_PORT"] = 80454 resp = login_view(req)455 resp2 = CsrfViewMiddleware().process_response(req, resp)456 csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)457 token2 = csrf_cookie.coded_value458 # Check the CSRF token switched459 self.assertNotEqual(token1, token2)460@skipIfCustomUser461class LoginURLSettings(AuthViewsTestCase):462 """Tests for settings.LOGIN_URL."""463 def assertLoginURLEquals(self, url, parse_qs=False):464 response = self.client.get('/login_required/')465 self.assertEqual(response.status_code, 302)466 self.assertURLEqual(response.url, url, parse_qs=parse_qs)467 @override_settings(LOGIN_URL='/login/')468 def test_standard_login_url(self):469 self.assertLoginURLEquals('/login/?next=/login_required/')470 @override_settings(LOGIN_URL='login')471 def test_named_login_url(self):472 self.assertLoginURLEquals('/login/?next=/login_required/')473 @override_settings(LOGIN_URL='http://remote.example.com/login')474 def test_remote_login_url(self):475 quoted_next = urlquote('http://testserver/login_required/')476 expected = 'http://remote.example.com/login?next=%s' % quoted_next477 self.assertLoginURLEquals(expected)478 @override_settings(LOGIN_URL='https:///login/')479 def test_https_login_url(self):480 quoted_next = urlquote('http://testserver/login_required/')481 expected = 'https:///login/?next=%s' % quoted_next482 self.assertLoginURLEquals(expected)483 @override_settings(LOGIN_URL='/login/?pretty=1')484 def test_login_url_with_querystring(self):485 self.assertLoginURLEquals('/login/?pretty=1&next=/login_required/', parse_qs=True)486 @override_settings(LOGIN_URL='http://remote.example.com/login/?next=/default/')487 def test_remote_login_url_with_next_querystring(self):488 quoted_next = urlquote('http://testserver/login_required/')489 expected = 'http://remote.example.com/login/?next=%s' % quoted_next490 self.assertLoginURLEquals(expected)491@skipIfCustomUser492class LoginRedirectUrlTest(AuthViewsTestCase):493 """Tests for settings.LOGIN_REDIRECT_URL."""494 def assertLoginRedirectURLEqual(self, url):495 response = self.login()496 self.assertEqual(response.status_code, 302)497 self.assertURLEqual(response.url, url)498 def test_default(self):499 self.assertLoginRedirectURLEqual('/accounts/profile/')500 @override_settings(LOGIN_REDIRECT_URL='/custom/')501 def test_custom(self):502 self.assertLoginRedirectURLEqual('/custom/')503 @override_settings(LOGIN_REDIRECT_URL='password_reset')504 def test_named(self):505 self.assertLoginRedirectURLEqual('/password_reset/')506 @override_settings(LOGIN_REDIRECT_URL='http://remote.example.com/welcome/')507 def test_remote(self):508 self.assertLoginRedirectURLEqual('http://remote.example.com/welcome/')509@skipIfCustomUser510class LogoutTest(AuthViewsTestCase):511 def confirm_logged_out(self):512 self.assertTrue(SESSION_KEY not in self.client.session)513 def test_logout_default(self):514 "Logout without next_page option renders the default template"515 self.login()516 response = self.client.get('/logout/')517 self.assertContains(response, 'Logged out')518 self.confirm_logged_out()519 def test_14377(self):520 # Bug 14377521 self.login()522 response = self.client.get('/logout/')523 self.assertTrue('site' in response.context)524 def test_logout_with_overridden_redirect_url(self):525 # Bug 11223526 self.login()527 response = self.client.get('/logout/next_page/')528 self.assertEqual(response.status_code, 302)529 self.assertURLEqual(response.url, '/somewhere/')530 response = self.client.get('/logout/next_page/?next=/login/')531 self.assertEqual(response.status_code, 302)532 self.assertURLEqual(response.url, '/login/')533 self.confirm_logged_out()534 def test_logout_with_next_page_specified(self):535 "Logout with next_page option given redirects to specified resource"536 self.login()537 response = self.client.get('/logout/next_page/')538 self.assertEqual(response.status_code, 302)539 self.assertURLEqual(response.url, '/somewhere/')540 self.confirm_logged_out()541 def test_logout_with_redirect_argument(self):542 "Logout with query string redirects to specified resource"543 self.login()544 response = self.client.get('/logout/?next=/login/')545 self.assertEqual(response.status_code, 302)546 self.assertURLEqual(response.url, '/login/')547 self.confirm_logged_out()548 def test_logout_with_custom_redirect_argument(self):549 "Logout with custom query string redirects to specified resource"550 self.login()551 response = self.client.get('/logout/custom_query/?follow=/somewhere/')552 self.assertEqual(response.status_code, 302)553 self.assertURLEqual(response.url, '/somewhere/')554 self.confirm_logged_out()555 def test_logout_with_named_redirect(self):556 "Logout resolves names or URLs passed as next_page."557 self.login()558 response = self.client.get('/logout/next_page/named/')559 self.assertEqual(response.status_code, 302)560 self.assertURLEqual(response.url, '/password_reset/')561 self.confirm_logged_out()562 def test_security_check(self, password='password'):563 logout_url = reverse('logout')564 # Those URLs should not pass the security check565 for bad_url in ('http://example.com',566 'http:///example.com',567 'https://example.com',568 'ftp://exampel.com',569 '///example.com',570 '//example.com',571 'javascript:alert("XSS")'):572 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {573 'url': logout_url,574 'next': REDIRECT_FIELD_NAME,...

Full Screen

Full Screen

test_urls.py

Source:test_urls.py Github

copy

Full Screen

...8#If you need to use something similar to the url template tag in your code9 def test_home_url_is_resolved(self):10 url = reverse('home')11 self.assertEqual(resolve(url).func,homePage) #check if [path] is match to this [.views] function12 self.assertURLEqual(url, '/') # check if url redirect to url as the function is [.views] declared13 def test_shop_reviews_url_is_resolved(self):14 url = reverse('shop-reviews', args=['1'])15 self.assertEqual(resolve(url).func,shopReviews) #check if [path] is match to this [.views] function16 self.assertURLEqual(url, '/shop/1/reviews') # check if url redirect to url as the function is [.views] declared17 def test_hotDeals_url_is_resolved(self):18 url = reverse('hotDeals')19 self.assertEqual(resolve(url).func,hotDeals) #check if [path] is match to this [.views] function20 self.assertURLEqual(url, '/hot-deals/') # check if url redirect to url as the function is [.views] declared21 def test_userPanel_url_is_resolved(self):22 url = reverse('userPanel')23 self.assertEqual(resolve(url).func, userPanel) # check if [path] is match to this [.views] function24 self.assertURLEqual(url, '/profile/') # check if url redirect to url as the function is [.views] declared25 def test_userUpdateInfo_url_is_resolved(self):26 url = reverse('user-update-info')27 self.assertEqual(resolve(url).func, userUpdateInfo) # check if [path] is match to this [.views] function28 self.assertURLEqual(url, '/update-info/') # check if url redirect to url as the function is [.views] declared29 def test_userUpdateShipping_url_is_resolved(self):30 url = reverse('update-shipping')31 self.assertEqual(resolve(url).func, userUpdateShipping) # check if [path] is match to this [.views] function32 self.assertURLEqual(url, '/update-shipping/') # check if url redirect to url as the function is [.views] declared33 def test_register_url_is_resolved(self):34 url = reverse('register')35 self.assertEqual(resolve(url).func,RegisterPage) #check if [path] is match to this [.views] function36 self.assertURLEqual(url, '/register/') # check if url redirect to url as the function is [.views] declared37 def test_login_url_is_resolved(self):38 url = reverse('login')39 self.assertEqual(resolve(url).func,loginPage) #check if [path] is match to this [.views] function40 self.assertURLEqual(url, '/login/') # check if url redirect to url as the function is [.views] declared41 def test_logout_url_is_resolved(self):42 url = reverse('logout')43 self.assertURLEqual(url, '/logout/') # check if url redirect to url as the function is [.views] declared44 def test_logout_with_log_url_is_resolved(self):45 url = reverse('logout_with_log')46 self.assertEqual(resolve(url).func, logoutPage) # check if [path] is match to this [.views] function47 self.assertURLEqual(url, '/logoutnow/') # check if url redirect to url as the function is [.views] declared48 def test_product_details_url_is_resolved(self):49 url = reverse('product-details', args=['50385'])50 self.assertEqual(resolve(url).func, productDetails) # check if [path] is match to this [.views] function51 self.assertURLEqual(url, '/product/50385/') # check if url redirect to url as the function is [.views] declared52 def test_review_product_url_is_resolved(self):53 url = reverse('review-product', args= ['50385'])54 self.assertEqual(resolve(url).func, reviewProduct) # check if [path] is match to this [.views] function55 self.assertURLEqual(url, '/admin-panel/product/50385/review/') # check if url redirect to url as the function is [.views] declared56 def test_productList_url_is_resolved(self):57 url = reverse('product-list')58 self.assertEqual(resolve(url).func,productList) #check if [path] is match to this [.views] function59 self.assertURLEqual(url, '/admin-panel/product-list/') # check if url redirect to url as the function is [.views] declared60 def test_adminMessages_reviews_url_is_resolved(self):61 url = reverse('admin-messages')62 self.assertEqual(resolve(url).func,adminMessages) #check if [path] is match to this [.views] function63 self.assertURLEqual(url, '/admin-panel/inbox/') # check if url redirect to url as the function is [.views] declared64 def test_adminMessageDelete_url_is_resolved(self):65 url = reverse('admin-message-delete', args = ['1'])66 self.assertEqual(resolve(url).func,adminMessageDelete) #check if [path] is match to this [.views] function67 self.assertURLEqual(url, '/admin-panel/inbox/1/delete') # check if url redirect to url as the function is [.views] declared68 def test_adminPanel_url_is_resolved(self):69 url = reverse('admin-panel')70 self.assertEqual(resolve(url).func, adminPanel) # check if [path] is match to this [.views] function71 self.assertURLEqual(url, '/admin-panel/') # check if url redirect to url as the function is [.views] declared72 def test_DeleteProduct_url_is_resolved(self):73 url = reverse('delete-product', args=['50417'])74 self.assertEqual(resolve(url).func, DeleteProduct) # check if [path] is match to this [.views] function75 self.assertURLEqual(url, '/admin-panel/product/50417/delete/') # check if url redirect to url as the function is [.views] declared76 def test_addProduct_url_is_resolved(self):77 url = reverse('add-product')78 self.assertEqual(resolve(url).func, addProduct) # check if [path] is match to this [.views] function79 self.assertURLEqual(url, '/admin-panel/product/add/') # check if url redirect to url as the function is [.views] declared80 def test_userList_url_is_resolved(self):81 url = reverse('user-list')82 self.assertEqual(resolve(url).func,userList) #check if [path] is match to this [.views] function83 self.assertURLEqual(url, '/admin-panel/users/') # check if url redirect to url as the function is [.views] declared84 def test_addUser_url_is_resolved(self):85 url = reverse('add-user')86 self.assertEqual(resolve(url).func,addUser) #check if [path] is match to this [.views] function87 self.assertURLEqual(url, '/admin-panel/users/add') # check if url redirect to url as the function is [.views] declared88 def test_reviewUser_url_is_resolved(self):89 url = reverse('review-user', args = ['11'])90 self.assertEqual(resolve(url).func, reviewUser) # check if [path] is match to this [.views] function91 self.assertURLEqual(url, '/admin-panel/users/11/review') # check if url redirect to url as the function is [.views] declared92 def test_checkout_url_is_resolved(self):93 url = reverse('checkout')94 self.assertEqual(resolve(url).func, checkout) # check if [path] is match to this [.views] function95 self.assertURLEqual(url, '/checkout/') # check if url redirect to url as the function is [.views] declared96 def test_updateItem_url_is_resolved(self):97 url = reverse('update-item')98 self.assertEqual(resolve(url).func, updateItem) # check if [path] is match to this [.views] function99 self.assertURLEqual(url, '/update_item/') # check if url redirect to url as the function is [.views] declared100 def test_updateWishlist_url_is_resolved(self):101 url = reverse('update-wishlist')102 self.assertEqual(resolve(url).func, updateWishlist) # check if [path] is match to this [.views] function103 self.assertURLEqual(url, '/update_wishlist/') # check if url redirect to url as the function is [.views] declared104 def test_cart_url_is_resolved(self):105 url = reverse('cart')106 self.assertEqual(resolve(url).func, cart) # check if [path] is match to this [.views] function107 self.assertURLEqual(url, '/cart/') # check if url redirect to url as the function is [.views] declared108 def test_faq_url_is_resolved(self):109 url = reverse('faq')110 self.assertEqual(resolve(url).func, faq) # check if [path] is match to this [.views] function111 self.assertURLEqual(url, '/faq/') # check if url redirect to url as the function is [.views] declared112 def test_SellerProducts_url_is_resolved(self):113 url = reverse('my-products')114 self.assertEqual(resolve(url).func, SellerProducts) # check if [path] is match to this [.views] function115 self.assertURLEqual(url, '/profile/my-products/') # check if url redirect to url as the function is [.views] declared116 def test_sellerReviewProduct_url_is_resolved(self):117 url = reverse('seller-review-products', args=['50393'])118 self.assertEqual(resolve(url).func, sellerReviewProduct) # check if [path] is match to this [.views] function119 self.assertURLEqual(url,'/profile/my-products/50393/review') # check if url redirect to url as the function is [.views] declared120 def test_wishlist_url_is_resolved(self):121 url = reverse('wishlist')122 self.assertEqual(resolve(url).func, wish_list) # check if [path] is match to this [.views] function123 self.assertURLEqual(url, '/wishlist/') # check if url redirect to url as the function is [.views] declared124 def test_SellerDeleteProduct_url_is_resolved(self):125 url = reverse('seller-delete-product', args=['50385'])126 self.assertEqual(resolve(url).func, SellerDeleteProduct) # check if [path] is match to this [.views] function127 self.assertURLEqual(url,'/profile/my-products/50385/delete/') # check if url redirect to url as the function is [.views] declared128 def test_sellerAddProduct_url_is_resolved(self):129 url = reverse('seller-add-product')130 self.assertEqual(resolve(url).func, sellerAddProduct) # check if [path] is match to this [.views] function131 self.assertURLEqual(url, '/profile/my-products/add/') # check if url redirect to url as the function is [.views] declared132 def test_sellerContact_url_is_resolved(self):133 url = reverse('seller-contact', args=['11'])134 self.assertEqual(resolve(url).func, sellerContact) # check if [path] is match to this [.views] function135 self.assertURLEqual(url,'/seller/11/contact/') # check if url redirect to url as the function is [.views] declared136 def test_userMessages_url_is_resolved(self):137 url = reverse('user-messages')138 self.assertEqual(resolve(url).func, userMessages) # check if [path] is match to this [.views] function139 self.assertURLEqual(url, '/profile/inbox/') # check if url redirect to url as the function is [.views] declared140 def test_userMessageReview_url_is_resolved(self):141 url = reverse('user-message-review', args=['11'])142 self.assertEqual(resolve(url).func, userMessageReview) # check if [path] is match to this [.views] function143 self.assertURLEqual(url,'/profile/inbox/11') # check if url redirect to url as the function is [.views] declared144 def test_sellerMessageDelete_url_is_resolved(self):145 url = reverse('seller-delete-message', args=['10'])146 self.assertEqual(resolve(url).func, sellerMessageDelete) # check if [path] is match to this [.views] function147 self.assertURLEqual(url,'/profile/inbox/10/delete/seller') # check if url redirect to url as the function is [.views] declared148 def test_BuyerMessageDelete_url_is_resolved(self):149 url = reverse('buyer-delete-message', args=['10'])150 self.assertEqual(resolve(url).func, BuyerMessageDelete) # check if [path] is match to this [.views] function151 self.assertURLEqual(url, '/profile/inbox/10/delete/buyer') # check if url redirect to url as the function is [.views] declared152 def test_coupons_url_is_resolved(self):153 url = reverse('coupons')154 self.assertEqual(resolve(url).func, coupons) # check if [path] is match to this [.views] function155 self.assertURLEqual(url, '/admin-panel/coupons') # check if url redirect to url as the function is [.views] declared156 def test_sellerCoupons_url_is_resolved(self):157 url = reverse('seller-coupons')158 self.assertEqual(resolve(url).func, sellerCoupons) # check if [path] is match to this [.views] function159 self.assertURLEqual(url, '/profile/coupons/') # check if url redirect to url as the function is [.views] declared160 def test_sellerCouponDelete_url_is_resolved(self):161 url = reverse('seller-coupons-delete', args=['11'])162 self.assertEqual(resolve(url).func, sellerCouponDelete) # check if [path] is match to this [.views] function163 self.assertURLEqual(url, '/profile/coupons/11/delete') # check if url redirect to url as the function is [.views] declared164 def test_sellerAddCoupon_url_is_resolved(self):165 url = reverse('seller-coupons-add')166 self.assertEqual(resolve(url).func, sellerAddCoupon) # check if [path] is match to this [.views] function167 self.assertURLEqual(url, '/profile/coupons/add') # check if url redirect to url as the function is [.views] declared168 def test_contactUs_url_is_resolved(self):169 url = reverse('contact-site')170 self.assertEqual(resolve(url).func, contactUs) # check if [path] is match to this [.views] function171 self.assertURLEqual(url, '/contactus/') # check if url redirect to url as the function is [.views] declared172 def test_searchPage_url_is_resolved(self):173 url = reverse('search-page')174 self.assertEqual(resolve(url).func, searchPage) # check if [path] is match to this [.views] function175 self.assertURLEqual(url, '/search/') # check if url redirect to url as the function is [.views] declared176 def test_sellerShop_url_is_resolved(self):177 url = reverse('seller-shop', args=['11'])178 self.assertEqual(resolve(url).func, sellerShop) # check if [path] is match to this [.views] function179 self.assertURLEqual(url, '/shop/11') # check if url redirect to url as the function is [.views] declared180 def test_sellerStoreRate_url_is_resolved(self):181 url = reverse('seller-shop-rate', args=['11'])182 self.assertEqual(resolve(url).func, sellerStoreRate) # check if [path] is match to this [.views] function183 self.assertURLEqual(url, '/shop/11/rate') # check if url redirect to url as the function is [.views] declared184 def test_buyerShopList_url_is_resolved(self):185 url = reverse('buyer-shop-list')186 self.assertEqual(resolve(url).func, buyerShopList) # check if [path] is match to this [.views] function187 self.assertURLEqual(url, '/profile/my-shops/') # check if url redirect to url as the function is [.views] declared188 def test_buyerDeleteShop_url_is_resolved(self):189 url = reverse('buyer-delete-from-shop-list', args=['10'])190 self.assertEqual(resolve(url).func, buyerDeleteShop) # check if [path] is match to this [.views] function191 self.assertURLEqual(url, '/profile/my-shops/10/delete/') # check if url redirect to url as the function is [.views] declared192 def test_orderCompleted_url_is_resolved(self):193 url = reverse('order-completed', args=['41D39170A37554E50054F331'])194 self.assertEqual(resolve(url).func, orderCompleted) # check if [path] is match to this [.views] function195 self.assertURLEqual(url, '/order/41D39170A37554E50054F331/success') # check if url redirect to url as the function is [.views] declared196 def test_buyerOrderList_url_is_resolved(self):197 url = reverse('buyer-order-list')198 self.assertEqual(resolve(url).func, buyerOrderList) # check if [path] is match to this [.views] function199 self.assertURLEqual(url, '/profile/my-orders/') # check if url redirect to url as the function is [.views] declared200 def test_sellerSales_url_is_resolved(self):201 url = reverse('seller-sales')202 self.assertEqual(resolve(url).func, sellerSales) # check if [path] is match to this [.views] function203 self.assertURLEqual(url, '/profile/my-sales/') # check if url redirect to url as the function is [.views] declared204 def test_adminTransactions_url_is_resolved(self):205 url = reverse('admin-transactions')206 self.assertEqual(resolve(url).func, adminTransactions) # check if [path] is match to this [.views] function207 self.assertURLEqual(url, '/admin-panel/transactions/') # check if url redirect to url as the function is [.views] declared208 def test_adminSettings_url_is_resolved(self):209 url = reverse('admin-settings')210 self.assertEqual(resolve(url).func, adminSettings) # check if [path] is match to this [.views] function211 self.assertURLEqual(url, '/admin-panel/settings/') # check if url redirect to url as the function is [.views] declared212 def test_unauthorizeed_url_is_resolved(self):213 url = reverse('unauthorized')214 self.assertEqual(resolve(url).func, unauthorized) # check if [path] is match to this [.views] function215 self.assertURLEqual(url, '/unauthorized') # check if url redirect to url as the function is [.views] declared216 def test_bestSellersPage_url_is_resolved(self):217 url = reverse('best-sellers-page')218 self.assertEqual(resolve(url).func, bestSellersPage) # check if [path] is match to this [.views] function...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...16 'email' : 'lennon@thebeatles.com',17 'password1' : '111',18 'password2' : '111'})19 self.assertEqual(response.status_code, 302)20 self.assertURLEqual(21 response.headers['Location'],'/addressbook/birthdays/')22 23 #вываливалась ошибка . дырка в if во вьюшке register24 response = self.client.post(reverse('register'), 25 {'username' : 'boss', 26 'email' : 'lennon@thebeatles.com',27 'password1' : '111',28 'password2' : '111'})29 self.assertEqual(response.status_code, 302)30 self.assertURLEqual(31 response.headers['Location'],'/register/')32 33 response = self.client.post(reverse('register'), 34 {'username' : 'boss', 35 'email' : 'lennon@thebeatles.com',36 'password1' : '111',37 'password2' : '222'})38 self.assertEqual(response.status_code, 302)39 self.assertURLEqual(40 response.headers['Location'],'/register/')41 42 def test_login_user(self):43 user = User.objects.create_user('boss', 'lennon@thebeatles.com', '111')44 boss = User.objects.get(id= 1)45 response = self.client.post(reverse('login'), {'username' : 'boss', 'password' : '111'})46 self.assertEqual(response.status_code, 302)47 self.assertURLEqual(48 response.headers['Location'], '/addressbook/birthdays/')49 50 response = self.client.post(reverse('login'), {'username' : 'boss', 'password' : '222'})51 self.assertEqual(response.status_code, 200)52 def test_logout_user(self):53 user = User.objects.create_user('boss', 'lennon@thebeatles.com', '111')54 user_is_auth = authenticate(username='boss', password = '111')55 response = self.client.post(reverse('logout'))56 self.assertEqual(response.status_code, 302)57 self.assertURLEqual(58 response.headers['Location'], '/dashboard/')...

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