How to use assertRedirects method in pytest-django

Best Python code snippet using pytest-django_python

test_urls.py

Source:test_urls.py Github

copy

Full Screen

...4 super().__init__(*args, **kwargs)5 self.language = "en"6 def test_activities(self):7 response = self.client.get("/activities")8 self.assertRedirects(9 response,10 "https://classic.csunplugged.org/activities",11 status_code=301,12 fetch_redirect_response=False13 )14 def test_artificial_intelligence(self):15 response = self.client.get("/artificial-intelligence")16 self.assertRedirects(17 response,18 "https://classic.csunplugged.org/artificial-intelligence",19 status_code=301,20 fetch_redirect_response=False21 )22 def test_binary_numbers(self):23 response = self.client.get("/binary-numbers")24 self.assertRedirects(25 response,26 "https://classic.csunplugged.org/binary-numbers",27 status_code=301,28 fetch_redirect_response=False29 )30 def test_books(self):31 response = self.client.get("/books")32 self.assertRedirects(33 response,34 "https://classic.csunplugged.org/books",35 status_code=301,36 fetch_redirect_response=False37 )38 def test_changelog(self):39 response = self.client.get("/changelog")40 self.assertRedirects(41 response,42 "https://cs-unplugged.readthedocs.io/changelog.html",43 status_code=301,44 fetch_redirect_response=False45 )46 def test_class_simulation_computer_unfinished(self):47 response = self.client.get("/class-simulation-computer-unfinished")48 self.assertRedirects(49 response,50 "https://classic.csunplugged.org/class-simulation-computer-unfinished",51 status_code=301,52 fetch_redirect_response=False53 )54 def test_community(self):55 response = self.client.get("/community")56 self.assertRedirects(57 response,58 "https://classic.csunplugged.org/community",59 status_code=301,60 fetch_redirect_response=False61 )62 def test_community_activties(self):63 response = self.client.get("/community-activties")64 self.assertRedirects(65 response,66 "https://classic.csunplugged.org/community-activties",67 status_code=301,68 fetch_redirect_response=False69 )70 def test_contact_us(self):71 response = self.client.get("/contact-us", follow=True)72 self.assertRedirects(response, "/en/contact/", status_code=301)73 def test_contribute(self):74 response = self.client.get("/contribute")75 self.assertRedirects(76 response,77 "https://classic.csunplugged.org/contribute",78 status_code=301,79 fetch_redirect_response=False80 )81 def test_cryptographic_protocols(self):82 response = self.client.get("/cryptographic-protocols")83 self.assertRedirects(84 response,85 "https://classic.csunplugged.org/cryptographic-protocols",86 status_code=301,87 fetch_redirect_response=False88 )89 def test_curriculum_links(self):90 response = self.client.get("/curriculum-links")91 self.assertRedirects(92 response,93 "https://classic.csunplugged.org/curriculum-links",94 status_code=301,95 fetch_redirect_response=False96 )97 def test_databases(self):98 response = self.client.get("/databases")99 self.assertRedirects(100 response,101 "https://classic.csunplugged.org/databases",102 status_code=301,103 fetch_redirect_response=False104 )105 def test_divideandconquer(self):106 response = self.client.get("/divideandconquer")107 self.assertRedirects(108 response,109 "https://classic.csunplugged.org/divideandconquer",110 status_code=301,111 fetch_redirect_response=False112 )113 def test_dominating_sets(self):114 response = self.client.get("/dominating-sets")115 self.assertRedirects(116 response,117 "https://classic.csunplugged.org/dominating-sets",118 status_code=301,119 fetch_redirect_response=False120 )121 def test_error_detection(self):122 response = self.client.get("/error-detection")123 self.assertRedirects(124 response,125 "https://classic.csunplugged.org/error-detection",126 status_code=301,127 fetch_redirect_response=False128 )129 def test_events(self):130 response = self.client.get("/events")131 self.assertRedirects(132 response,133 "https://classic.csunplugged.org/events",134 status_code=301,135 fetch_redirect_response=False136 )137 def test_finite_state_automata(self):138 response = self.client.get("/finite-state-automata")139 self.assertRedirects(140 response,141 "https://classic.csunplugged.org/finite-state-automata",142 status_code=301,143 fetch_redirect_response=False144 )145 def test_graph_colouring(self):146 response = self.client.get("/graph-colouring")147 self.assertRedirects(148 response,149 "https://classic.csunplugged.org/graph-colouring",150 status_code=301,151 fetch_redirect_response=False152 )153 def test_harold_the_robot_2(self):154 response = self.client.get("/harold-the-robot-2")155 self.assertRedirects(156 response,157 "https://classic.csunplugged.org/harold-the-robot-2",158 status_code=301,159 fetch_redirect_response=False160 )161 def test_human_interface_design(self):162 response = self.client.get("/human-interface-design")163 self.assertRedirects(164 response,165 "https://classic.csunplugged.org/human-interface-design",166 status_code=301,167 fetch_redirect_response=False168 )169 def test_image_representation(self):170 response = self.client.get("/image-representation")171 self.assertRedirects(172 response,173 "https://classic.csunplugged.org/image-representation",174 status_code=301,175 fetch_redirect_response=False176 )177 def test_information_hiding(self):178 response = self.client.get("/information-hiding")179 self.assertRedirects(180 response,181 "https://classic.csunplugged.org/information-hiding",182 status_code=301,183 fetch_redirect_response=False184 )185 def test_information_theory(self):186 response = self.client.get("/information-theory")187 self.assertRedirects(188 response,189 "https://classic.csunplugged.org/information-theory",190 status_code=301,191 fetch_redirect_response=False192 )193 def test_line_drawing(self):194 response = self.client.get("/line-drawing")195 self.assertRedirects(196 response,197 "https://classic.csunplugged.org/line-drawing",198 status_code=301,199 fetch_redirect_response=False200 )201 def test_minimal_spanning_trees(self):202 response = self.client.get("/minimal-spanning-trees")203 self.assertRedirects(204 response,205 "https://classic.csunplugged.org/minimal-spanning-trees",206 status_code=301,207 fetch_redirect_response=False208 )209 def test_modems(self):210 response = self.client.get("/modem/")211 self.assertRedirects(212 response,213 "https://classic.csunplugged.org/activities/community-activities/modems-unplugged/",214 status_code=301,215 fetch_redirect_response=False216 )217 def test_modems_unplugged_2(self):218 response = self.client.get("/modems-unplugged-2")219 self.assertRedirects(220 response,221 "https://classic.csunplugged.org/activities/community-activities/modems-unplugged/",222 status_code=301,223 fetch_redirect_response=False224 )225 def test_network_protocols(self):226 response = self.client.get("/network-protocols")227 self.assertRedirects(228 response,229 "https://classic.csunplugged.org/network-protocols",230 status_code=301,231 fetch_redirect_response=False232 )233 def test_phylogenetics(self):234 response = self.client.get("/phylogenetics")235 self.assertRedirects(236 response,237 "https://classic.csunplugged.org/phylogenetics",238 status_code=301,239 fetch_redirect_response=False240 )241 def test_programming_languages(self):242 response = self.client.get("/programming-languages")243 self.assertRedirects(244 response,245 "https://classic.csunplugged.org/programming-languages",246 status_code=301,247 fetch_redirect_response=False248 )249 def test_projects(self):250 response = self.client.get("/projects")251 self.assertRedirects(252 response,253 "https://classic.csunplugged.org/projects",254 status_code=301,255 fetch_redirect_response=False256 )257 def test_promotional(self):258 response = self.client.get("/promotional")259 self.assertRedirects(260 response,261 "https://classic.csunplugged.org/promotional",262 status_code=301,263 fetch_redirect_response=False264 )265 def test_public_key_encryption(self):266 response = self.client.get("/public-key-encryption")267 self.assertRedirects(268 response,269 "https://classic.csunplugged.org/public-key-encryption",270 status_code=301,271 fetch_redirect_response=False272 )273 def test_research(self):274 response = self.client.get("/research")275 self.assertRedirects(276 response,277 "https://classic.csunplugged.org/research",278 status_code=301,279 fetch_redirect_response=False280 )281 def test_routing_and_deadlock(self):282 response = self.client.get("/routing-and-deadlock")283 self.assertRedirects(284 response,285 "https://classic.csunplugged.org/routing-and-deadlock",286 status_code=301,287 fetch_redirect_response=False288 )289 def test_scout_patrol_encryption(self):290 response = self.client.get("/scout-patrol-encryption")291 self.assertRedirects(292 response,293 "https://classic.csunplugged.org/scout-patrol-encryption",294 status_code=301,295 fetch_redirect_response=False296 )297 def test_searching_algorithms(self):298 response = self.client.get("/searching-algorithms")299 self.assertRedirects(300 response,301 "https://classic.csunplugged.org/searching-algorithms",302 status_code=301,303 fetch_redirect_response=False304 )305 def test_sneak_peek(self):306 response = self.client.get("/sneak-peek", follow=True)307 self.assertRedirects(response, "/en/", status_code=301)308 def test_sorting_algorithms(self):309 response = self.client.get("/sorting-algorithms")310 self.assertRedirects(311 response,312 "https://classic.csunplugged.org/sorting-algorithms",313 status_code=301,314 fetch_redirect_response=False315 )316 def test_sorting_networks(self):317 response = self.client.get("/sorting-networks")318 self.assertRedirects(319 response,320 "https://classic.csunplugged.org/sorting-networks",321 status_code=301,322 fetch_redirect_response=False323 )324 def test_steiner_trees(self):325 response = self.client.get("/steiner-trees")326 self.assertRedirects(327 response,328 "https://classic.csunplugged.org/steiner-trees",329 status_code=301,330 fetch_redirect_response=False331 )332 def test_teachers(self):333 response = self.client.get("/teachers")334 self.assertRedirects(335 response,336 "https://classic.csunplugged.org/teachers",337 status_code=301,338 fetch_redirect_response=False339 )340 def test_text_compression(self):341 response = self.client.get("/text-compression")342 self.assertRedirects(343 response,344 "https://classic.csunplugged.org/text-compression",345 status_code=301,346 fetch_redirect_response=False347 )348 def test_the_turing_test(self):349 response = self.client.get("/the-turing-test")350 self.assertRedirects(351 response,352 "https://classic.csunplugged.org/the-turing-test",353 status_code=301,354 fetch_redirect_response=False355 )356 def test_translations(self):357 response = self.client.get("/translations")358 self.assertRedirects(359 response,360 "https://classic.csunplugged.org/translations",361 status_code=301,362 fetch_redirect_response=False363 )364 def test_videos(self):365 response = self.client.get("/videos")366 self.assertRedirects(367 response,368 "https://classic.csunplugged.org/videos",369 status_code=301,370 fetch_redirect_response=False371 )372 def test_wp_content(self):373 response = self.client.get("/wp-content/")374 self.assertRedirects(375 response,376 "https://classic.csunplugged.org/wp-content/",377 status_code=301,378 fetch_redirect_response=False379 )380 def test_wp_content_file(self):381 response = self.client.get("/wp-content/uploads/2015/03/CSUnplugged_OS_2015_v3.1.pdf")382 self.assertRedirects(383 response,384 "https://classic.csunplugged.org/wp-content/uploads/2015/03/CSUnplugged_OS_2015_v3.1.pdf",385 status_code=301,386 fetch_redirect_response=False...

Full Screen

Full Screen

test_views.py

Source:test_views.py Github

copy

Full Screen

...12 creating the root article and a simple markup.13 """14 c = self.c15 response = c.get(reverse('wiki:root')) # url '/'16 self.assertRedirects(17 response,18 reverse('wiki:root_create') # url '/create-root/'19 )20 response = c.post(21 reverse('wiki:root_create'),22 {'content': 'test heading h1\n====\n', 'title': 'Wiki Test'}23 )24 self.assertRedirects(response, reverse('wiki:root'))25 response = c.get(reverse('wiki:root'))26 self.assertContains(response, 'test heading h1</h1>')27class ArticleViewViewTests(ArticleTestBase):28 """29 Tests for article views, assuming a root article already created.30 """31 def dump_db_status(self, message=''):32 """Debug printing of the complete important database content."""33 print('*** db status *** {}'.format(message))34 from wiki.models import Article, ArticleRevision, URLPath35 for klass in (Article, ArticleRevision, URLPath):36 print('* {} *'.format(klass.__name__))37 pprint.pprint(list(klass.objects.values()), width=240)38 def test_preview_save(self):39 """Test edit preview, edit save and messages."""40 c = self.c41 # test preview42 response = c.post(43 reverse('wiki:preview', kwargs={'path': ''}), # url: '/_preview/'44 self.example_data45 )46 self.assertContains(response, 'The modified text')47 # test save and messages48 example2 = self.example_data.copy()49 example2['content'] = 'Something 2'50 response = c.post(reverse('wiki:edit', kwargs={'path': ''}), example2)51 message = getattr(c.cookies['messages'], 'value')52 self.assertRedirects(response, reverse('wiki:root'))53 response = c.get(reverse('wiki:root'))54 # self.dump_db_status('test_preview_save')55 # Why it doesn't display the latest revison text if other test56 # preceded? It is correctly in the db.57 self.assertContains(response, 'Something 2')58 self.assertIn('succesfully added', message)59 def test_redirects_to_create_if_the_slug_is_unknown(self):60 response = self.get_by_path('Unknown/')61 self.assertRedirects(62 response,63 reverse('wiki:create', kwargs={'path': ''}) + '?slug=Unknown'64 )65 def test_article_list_update(self):66 """67 Test automatic adding and removing the new article to/from article_list.68 """69 c = self.c70 root_data = {71 'content': '[article_list depth:2]',72 'current_revision': '1',73 'preview': '1',74 'title': 'Root Article'75 }76 response = c.post(reverse('wiki:edit', kwargs={'path': ''}), root_data)77 self.assertRedirects(response, reverse('wiki:root'))78 # verify the new article is added to article_list79 response = c.post(80 reverse('wiki:create', kwargs={'path': ''}),81 {'title': 'Sub Article 1', 'slug': 'SubArticle1'}82 )83 self.assertRedirects(84 response,85 reverse('wiki:get', kwargs={'path': 'subarticle1/'})86 )87 self.assertContains(self.get_by_path(''), 'Sub Article 1')88 self.assertContains(self.get_by_path(''), 'subarticle1/')89 # verify the deleted article is removed from article_list90 response = c.post(91 reverse('wiki:delete', kwargs={'path': 'SubArticle1/'}),92 {'confirm': 'on', 'purge': 'on', 'revision': '3'}93 )94 message = getattr(c.cookies['messages'], 'value')95 self.assertRedirects(96 response,97 reverse('wiki:get', kwargs={'path': ''})98 )99 self.assertIn(100 'This article together with all '101 'its contents are now completely gone',102 message)103 self.assertNotContains(self.get_by_path(''), 'Sub Article 1')104class CreateViewTest(ArticleTestBase):105 def test_revision_conflict(self):106 """107 Test the warning if the same article is being edited concurrently.108 """109 c = self.c110 response = c.post(111 reverse('wiki:edit', kwargs={'path': ''}),112 self.example_data113 )114 self.assertRedirects(response, reverse('wiki:root'))115 response = c.post(116 reverse('wiki:edit', kwargs={'path': ''}),117 self.example_data118 )119 self.assertContains(120 response,121 'While you were editing, someone else changed the revision.'122 )123 # self.dump_db_status('after test_revision_conflict')124 def test_create_nested_article_in_article(self):125 c = self.c126 response = c.post(127 reverse('wiki:create', kwargs={'path': ''}),128 {'title': 'Level 1', 'slug': 'Level1', 'content': 'Content level 1'}129 )130 self.assertRedirects(131 response,132 reverse('wiki:get', kwargs={'path': 'level1/'})133 )134 response = c.post(135 reverse('wiki:create', kwargs={'path': 'Level1/'}),136 {'title': 'test', 'slug': 'Test', 'content': 'Content on level 2'}137 )138 self.assertRedirects(139 response,140 reverse('wiki:get', kwargs={'path': 'level1/test/'})141 )142 response = c.post(143 reverse('wiki:create', kwargs={'path': ''}),144 {'title': 'test',145 'slug': 'Test',146 'content': 'Other content on level 1'147 }148 )149 self.assertRedirects(150 response,151 reverse('wiki:get', kwargs={'path': 'test/'})152 )153 self.assertContains(154 self.get_by_path('Test/'),155 'Other content on level 1'156 )157 self.assertContains(158 self.get_by_path('Level1/Test/'),159 'Content'160 ) # on level 2')161class DeletViewTest(ArticleTestBase):162 def test_articles_cache_is_cleared_after_deleting(self):163 # That bug is tested by one individual test, otherwise it could be164 # revealed only by sequence of tests in some particular order165 c = self.c166 response = c.post(167 reverse('wiki:create', kwargs={'path': ''}),168 {'title': 'Test cache', 'slug': 'testcache', 'content': 'Content 1'}169 )170 self.assertRedirects(171 response,172 reverse('wiki:get', kwargs={'path': 'testcache/'})173 )174 response = c.post(175 reverse('wiki:delete', kwargs={'path': 'testcache/'}),176 {'confirm': 'on', 'purge': 'on', 'revision': '2'}177 )178 self.assertRedirects(179 response,180 reverse('wiki:get', kwargs={'path': ''})181 )182 response = c.post(183 reverse('wiki:create', kwargs={'path': ''}),184 {'title': 'Test cache', 'slug': 'TestCache', 'content': 'Content 2'}185 )186 self.assertRedirects(187 response,188 reverse('wiki:get', kwargs={'path': 'testcache/'})189 )190 # test the cache191 self.assertContains(self.get_by_path('TestCache/'), 'Content 2')192class SearchViewTest(ArticleTestBase):193 def test_query_string(self):194 c = self.c195 response = c.get(reverse('wiki:search'), {'q': 'Article'})196 self.assertContains(response, 'Root Article')197 def test_empty_query_string(self):198 c = self.c199 response = c.get(reverse('wiki:search'), {'q': ''})200 self.assertFalse(response.context['articles'])

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 pytest-django 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