How to use test_reverse method in Django Test Plus

Best Python code snippet using django-test-plus_python

plugins.py

Source:plugins.py Github

copy

Full Screen

...3from ionyweb.administration.tests import test_reverse, AdministrationTests4from django.contrib.contenttypes.models import ContentType5class PluginViewTests(AdministrationTests):6 def test_plugins_view(self):7 url = test_reverse('wa-plugins')8 # If deconnected, shouldn't work9 self.client.logout()10 response = self.client.get(url)11 self.assertEqual(response.status_code, 403)12 self.client.login(username='admin', password='admin')13 response = self.client.get(url)14 self.assertContains(response, 'plugins_listform')15 def test_get_plugin_pk_view(self):16 self.client.login(username='admin', password='admin')17 # Try to edit an existing plugin of the page18 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 3)19 url = test_reverse('wa-plugin', args=[arg])20 response = self.client.get(url)21 self.assertContains(response, 'html')22 # Try to edit an existing plugin of another page23 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 16)24 url = test_reverse('wa-plugin', args=[arg])25 response = self.client.get(url)26 self.assertContains(response, 'html')27 # Try to edit a non existing plugin28 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 9999)29 url = test_reverse('wa-plugin', args=[arg])30 response = self.client.get(url)31 self.assertEqual(response.status_code, 404)32 # Try to edit another website plugin33 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 487)34 url = test_reverse('wa-plugin', args=[arg])35 response = self.client.get(url)36 self.assertEqual(response.status_code, 404)37 38 def test_get_plugin_view(self):39 url = test_reverse('wa-plugin')40 self.client.login(username='admin', password='admin')41 # Some fields are missing42 response = self.client.get(url)43 self.assertContains(response, 'msg', status_code = 400)44 response = self.client.get(url, {'placeholder_id': ''})45 self.assertContains(response, 'msg', status_code = 400)46 response = self.client.get(url, {'plugin_type': ''})47 self.assertContains(response, 'msg', status_code = 400)48 # Fields are Ok49 content_placeholder_1 = '%s1' % settings.HTML_ID_PLACEHOLDER_CONTENT50 plugin_id = ContentType.objects.get(51 app_label="plugin_text", model="plugin_text").id52 # Everything ok - Should work53 response = self.client.get(url, {'placeholder_id': content_placeholder_1,54 'plugin_type': plugin_id})55 self.assertContains(response, 'plugin_form_form', status_code = 200)56 # Wrong placeholder57 response = self.client.get(url, {'placeholder_id': 'foobar',58 'plugin_type': plugin_id})59 self.assertContains(response, 'msg', status_code = 400)60 # Cannot add in placeholder_default61 response = self.client.get(url, {'placeholder_id': settings.HTML_ID_PLACEHOLDER_DEFAULT,62 'plugin_type': plugin_id})63 self.assertContains(response, 'msg', status_code = 400)64 # Cannot add in placeholder clipboard65 response = self.client.get(url, {'placeholder_id': settings.HTML_ID_PLACEHOLDER_CLIPBOARD,66 'plugin_type': plugin_id})67 self.assertContains(response, 'msg', status_code = 400)68 # Wrong plugin_id69 response = self.client.get(url, {'placeholder_id': content_placeholder_1,70 'plugin_type': 9999})71 self.assertContains(response, 'msg', status_code = 400)72 73 def test_put_plugin_view(self):74 url = test_reverse('wa-plugin')75 self.client.login(username='admin', password='admin')76 77 # Some fields are missing78 response = self.client.put(url)79 self.assertContains(response, 'msg', status_code = 400)80 response = self.client.put(url, {'placeholder_id': ''})81 self.assertContains(response, 'msg', status_code = 400)82 response = self.client.put(url, {'plugin_type': ''})83 self.assertContains(response, 'msg', status_code = 400)84 content_placeholder_1 = '%s1' % settings.HTML_ID_PLACEHOLDER_CONTENT85 plugin_id = ContentType.objects.get(86 app_label="plugin_text", model="plugin_text").id87 # Wrong placeholder88 response = self.client.put(url, {'placeholder_id': 'foobar',89 'plugin_type': plugin_id})90 self.assertContains(response, 'msg', status_code = 400)91 # Cannot add in placeholder_default92 response = self.client.put(url, {'placeholder_id': settings.HTML_ID_PLACEHOLDER_DEFAULT,93 'plugin_type': plugin_id})94 self.assertContains(response, 'msg', status_code = 400)95 # Cannot add in placeholder clipboard96 response = self.client.put(url, {'placeholder_id': settings.HTML_ID_PLACEHOLDER_CLIPBOARD,97 'plugin_type': plugin_id})98 self.assertContains(response, 'msg', status_code = 400)99 # Wrong plugin_id100 response = self.client.put(url, {'placeholder_id': content_placeholder_1,101 'plugin_type': 9999})102 self.assertContains(response, 'msg', status_code = 400)103 # Empty form104 response = self.client.put(url, {'placeholder_id': content_placeholder_1,105 'plugin_type': plugin_id})106 self.assertContains(response, 'plugin_form_form', status_code = 400)107 # Form ok108 response = self.client.put(url, {'placeholder_id': content_placeholder_1,109 'plugin_type': plugin_id,110 'text': '<p>Foo bar</p>'})111 self.assertContains(response, 'msg')112 self.assertContains(response, 'html')113 def test_post_plugin_view(self):114 self.client.login(username='admin', password='admin')115 # OK - Try to edit an existing plugin of the page116 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 3)117 url = test_reverse('wa-plugin', args=[arg])118 response = self.client.post(url, {'text': '<p>Another value</p>'})119 self.assertContains(response, 'html')120 self.assertContains(response, 'msg')121 # OK - Try to edit an existing plugin of another page122 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 16)123 url = test_reverse('wa-plugin', args=[arg])124 response = self.client.post(url, {'text': '<p>Another value</p>'})125 self.assertContains(response, 'html')126 self.assertContains(response, 'msg')127 # 404 - Try to edit a non existing plugin128 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 9999)129 url = test_reverse('wa-plugin', args=[arg])130 response = self.client.post(url, {'text': '<p>Another value</p>'})131 self.assertEqual(response.status_code, 404)132 # 404 - Try to edit another website plugin133 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 487)134 url = test_reverse('wa-plugin', args=[arg])135 response = self.client.post(url, {'text': '<p>Another value</p>'})136 self.assertEqual(response.status_code, 404)137 # 400 - Empty form138 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 3)139 url = test_reverse('wa-plugin', args=[arg])140 response = self.client.post(url, {})141 self.assertContains(response, 'plugin_form_form', status_code = 400)142 def test_delete_plugin_view(self):143 self.client.login(username='admin', password='admin')144 # OK - Try to edit an existing plugin of the page145 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 3)146 url = test_reverse('wa-plugin', args=[arg])147 response = self.client.delete(url)148 self.assertContains(response, 'msg')149 # OK - Try to edit an existing plugin of another page150 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 16)151 url = test_reverse('wa-plugin', args=[arg])152 response = self.client.delete(url)153 self.assertContains(response, 'msg')154 # 404 - Try to edit a non existing plugin155 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 9999)156 url = test_reverse('wa-plugin', args=[arg])157 response = self.client.delete(url)158 self.assertEqual(response.status_code, 404)159 # 404 - Try to edit another website plugin160 arg = '%s%d' % (settings.HTML_ID_PLUGIN, 487)161 url = test_reverse('wa-plugin', args=[arg])162 response = self.client.delete(url)163 self.assertEqual(response.status_code, 404)164 def test_plugin_page_relation_view(self):165 self.client.login(username='admin', password='admin')166 url = test_reverse('wa-plugin-page-relation')167 content_placeholder_1 = '%s1' % settings.HTML_ID_PLACEHOLDER_CONTENT168 content_placeholder_2 = '%s2' % settings.HTML_ID_PLACEHOLDER_CONTENT169 clipboard_placeholder = '%s' % settings.HTML_ID_PLACEHOLDER_CLIPBOARD170 default_placeholder = '%s' % settings.HTML_ID_PLACEHOLDER_DEFAULT171 plugins_order = ['plugin-relation-2', 172 'plugin-relation-1']173 app = '%s1' % settings.HTML_ID_APP174 # 400 - Some fields are missing175 response = self.client.post(url)176 self.assertContains(response, 'msg', status_code = 400)177 response = self.client.post(url, {'placeholder_id': content_placeholder_1})178 self.assertContains(response, 'msg', status_code = 400)179 response = self.client.post(url, {'plugins_order[]': plugins_order})180 self.assertContains(response, 'msg', status_code = 400)...

Full Screen

Full Screen

pages.py

Source:pages.py Github

copy

Full Screen

...4from django.contrib.contenttypes.models import ContentType5from ionyweb.page.models import Page6class PageViewTests(AdministrationTests):7 def test_pages_view(self):8 url = test_reverse('wa-pages')9 # If deconnected, shouldn't work10 self.client.logout()11 response = self.client.get(url)12 self.assertEqual(response.status_code, 403)13 self.client.login(username='admin', password='admin')14 # GET - list of pages15 response = self.client.get(url)16 self.assertContains(response, 'page_list')17 self.assertEqual(len(response.context['pages']), 91)18 def test_page_layout_view(self):19 url = test_reverse('wa-page-layout')20 # If deconnected, shouldn't work21 self.client.logout()22 response = self.client.get(url)23 self.assertEqual(response.status_code, 403)24 self.client.login(username='admin', password='admin')25 # GET26 response = self.client.get(url)27 self.assertEqual(response.status_code, 400)28 response = self.client.get(url, {'layout_section_slug': settings.SLUG_CONTENT})29 self.assertContains(response, settings.SLUG_CONTENT)30 def test_get_page_view(self):31 url = test_reverse('wa-page')32 # If deconnected, shouldn't work33 self.client.logout()34 response = self.client.get(url)35 self.assertEqual(response.status_code, 403)36 self.client.login(username='admin', password='admin')37 # GET - new page form38 response = self.client.get(url)39 self.assertEqual(response.status_code, 200)40 # GET - Add a child41 response = self.client.get(url, {'parent': 1})42 self.assertContains(response, '<input type=\\"hidden\\" name=\\"parent\\" value=\\"1\\"')43 # GET - edit form44 url = test_reverse('wa-page', args=[1])45 response = self.client.get(url)46 self.assertContains(response, '<input id=\\"id_title\\" type=\\"text\\" name=\\"title\\" value=\\"Home\\" maxlength=\\"255\\" />')47 # Homepage doesn't show slug field48 self.assertContains(response, '<input type=\\"hidden\\" name=\\"slug\\" id=\\"id_slug\\">')49 # Other form page displays the slug field50 url = test_reverse('wa-page', args=[2])51 response = self.client.get(url)52 self.assertContains(response, '<input type=\\"text\\" name=\\"slug\\" value=\\"section_1\\"')53 def test_put_page_view(self):54 self.client.login(username='admin', password='admin')55 url = test_reverse('wa-page')56 app_page_type = ContentType.objects.get(57 app_label="page_text", model="pageapp_text").id58 ## Try to create a child for the home page59 infos = {'title': 'New page',60 'slug': 'new-page',61 'parent': 1,62 'app_page_type': app_page_type}63 response = self.client.put(url, infos)64 self.assertEqual(response.status_code, 400)65 ## Try to create an empty slug page66 infos = {'title': 'New page',67 'slug': '',68 'parent': '',69 'app_page_type': app_page_type}70 response = self.client.put(url, infos)71 self.assertEqual(response.status_code, 400)72 ## Try to create a used slug page73 infos = {'title': 'New page',74 'slug': 'section_1',75 'parent': '',76 'app_page_type': app_page_type}77 response = self.client.put(url, infos)78 self.assertEqual(response.status_code, 400)79 ## Too short slug80 infos = {'title': 'New page',81 'slug': 'p',82 'parent': '',83 'app_page_type': app_page_type}84 response = self.client.put(url, infos)85 self.assertEqual(response.status_code, 400)86 ## Parent doesn't exists87 infos = {'title': 'New page',88 'slug': 'new-page',89 'parent': 9999,90 'app_page_type': app_page_type}91 response = self.client.put(url, infos)92 self.assertEqual(response.status_code, 400)93 ## Working add form94 infos = {'title': 'New page',95 'slug': 'new-page',96 'parent': '',97 'app_page_type': app_page_type}98 response = self.client.put(url, infos)99 self.assertEqual(response.status_code, 202)100 ## Working add child form101 infos = {'title': 'New page 2',102 'slug': 'new-page2',103 'parent': 10,104 'app_page_type': app_page_type}105 response = self.client.put(url, infos)106 self.assertEqual(response.status_code, 202)107 def test_page_move_previous(self):108 self.client.login(username='admin', password='admin')109 url = test_reverse('wa-page', args=[10])110 response = self.client.post(url, {'move': '',111 'previous': 8,})112 self.assertEqual(response.status_code, 200)113 def test_page_move_next(self):114 self.client.login(username='admin', password='admin')115 url = test_reverse('wa-page', args=[10])116 response = self.client.post(url, {'move': '',117 'next': 12,})118 self.assertEqual(response.status_code, 200)119 def test_page_move_parent(self):120 self.client.login(username='admin', password='admin')121 # Move another page122 url = test_reverse('wa-page', args=[10])123 response = self.client.post(url, {'move': '',124 'parent': 11,})125 self.assertEqual(response.status_code, 200)126 # Refresh when current page url changed127 page_20 = Page.objects.get(pk=20).get_absolute_url()128 url = page_20[:-1] + test_reverse('wa-page', args=[20])129 response = self.client.post(url, {'move': '',130 'parent': 15,})131 self.assertEqual(response.status_code, 202)132 # Refresh when parent page url changed133 page_24 = Page.objects.get(pk=24).get_absolute_url()134 url = page_24[:-1] + test_reverse('wa-page', args=[22])135 response = self.client.post(url, {'move': '',136 'parent': 14})137 self.assertEqual(response.status_code, 202)138 139 def test_page_toggle_draft(self):140 self.client.login(username='admin', password='admin')141 url = test_reverse('wa-page', args=[10])142 response = self.client.post(url, {'draft': '', })143 self.assertEqual(response.status_code, 200)144 self.assertEqual(Page.objects.get(pk=10).draft, True)145 url = test_reverse('wa-page', args=[10])146 response = self.client.post(url, {'draft': '', })147 self.assertEqual(Page.objects.get(pk=10).draft, False)148 149 def test_post_page_view(self):150 self.client.login(username='admin', password='admin')151 url = test_reverse('wa-page', args=[10])152 app_page_type = ContentType.objects.get(153 app_label="page_text", model="pageapp_text").id154 # Post the form to modify the page155 url = test_reverse('wa-page', args=[22])156 response = self.client.post(url, {'title': 'New page 2',157 'slug': 'section_3',158 'parent': 10,159 'app_page_type': app_page_type})160 self.assertEqual(response.status_code, 200)161 # Slug is too short162 response = self.client.post(url, {'title': 'New page 2',163 'slug': 'p',164 'parent': 10,165 'app_page_type': app_page_type})166 self.assertEqual(response.status_code, 203)167 # Try to change the Homepage Slug168 url = test_reverse('wa-page', args=[1])169 response = self.client.post(url, {'title': 'HomePage',170 'slug': 'homepage',171 'parent': None,172 'app_page_type': app_page_type})173 self.assertEqual(response.status_code, 203)174 # Try to set en empty slug to a page175 page_23 = Page.objects.get(pk=23)176 url = test_reverse('wa-page', args=[page_23.pk])177 response = self.client.post(url, {'title': page_23.title,178 'slug': '',179 'parent': page_23.parent.id,180 'app_page_type': page_23.app_page_type.id})181 self.assertEqual(response.status_code, 203)182 def test_delete_page_view(self):183 self.client.login(username='admin', password='admin')184 # Try to delete the home page (And failed)185 url = test_reverse('wa-page', args=[1])186 response = self.client.delete(url)187 self.assertEqual(response.status_code, 400)188 # When we delete the current page, redirect189 page_20 = Page.objects.get(pk=20).get_absolute_url()190 url = page_20[:-1] + test_reverse('wa-page', args=[20])191 response = self.client.delete(url)192 self.assertEqual(response.status_code, 202)193 194 # When trying to delete a normal page195 url = test_reverse('wa-page', args=[10])196 response = self.client.delete(url)...

Full Screen

Full Screen

website.py

Source:website.py Github

copy

Full Screen

...4from ionyweb.administration.tests import test_reverse, AdministrationTests5from time import time6class WebsiteViewTests(AdministrationTests):7 def test_domains_view(self):8 url = test_reverse('wa-domains')9 # If deconnected, shouldn't work10 self.client.logout()11 response = self.client.get(url)12 self.assertEqual(response.status_code, 403)13 # If connected, should work14 self.client.login(username='admin', password='admin')15 response = self.client.get(url)16 self.assertContains(response, 'html')17 def test_domain_get_view(self):18 url = test_reverse('wa-domain')19 # If deconnected, shouldn't work20 self.client.logout()21 response = self.client.get(url)22 self.assertEqual(response.status_code, 403)23 # If connected, should work24 self.client.login(username='admin', password='admin')25 response = self.client.get(url)26 self.assertEqual(response.status_code, 200)27 self.assertEqual(response.context['edit'], False)28 url = test_reverse('wa-domain', args=[1])29 response = self.client.get(url)30 self.assertEqual(response.status_code, 200)31 self.assertEqual(response.context['edit'], True)32 # If the site doesn't exists33 url = test_reverse('wa-domain', args=[10])34 response = self.client.get(url)35 self.assertEqual(response.status_code, 404)36 def test_domain_put_view(self):37 url = test_reverse('wa-domain')38 39 # If connected, should work40 self.client.login(username='admin', password='admin')41 # If the form is empty42 response = self.client.put(url)43 self.assertEqual(response.status_code, 400)44 self.assertEqual(response.context['edit'], False)45 # If the domain aready exists46 response = self.client.put(url, {'domain': 'testserver'})47 self.assertEqual(response.status_code, 400)48 # If it is a subdomain of a RESTRICTED_DOMAIN49 saved_restricted_domains = settings.RESTRICTED_DOMAINS50 settings.RESTRICTED_DOMAINS = ['bar.com']51 response = self.client.put(url, {'domain': 'foo.bar.com'})52 self.assertEqual(response.status_code, 400)53 # If everything is ok54 response = self.client.put(url, {'domain': 'foobar.com'})55 self.assertContains(response, 'msg')56 settings.RESTRICTED_DOMAINS = saved_restricted_domains57 def test_domain_post_view(self):58 url = test_reverse('wa-domain', args=[1])59 60 # If connected, should work61 self.client.login(username='admin', password='admin')62 # If the form is empty63 response = self.client.post(url)64 self.assertEqual(response.status_code, 400)65 # If the site doesn't exists66 url = test_reverse('wa-domain', args=[10])67 response = self.client.post(url, {'domain': 'mydomainname.com'})68 self.assertEqual(response.status_code, 404)69 # We create a new site70 put_url = test_reverse('wa-domain')71 response = self.client.put(put_url, {'domain': 'mydomainname.com'})72 self.assertContains(response, 'msg')73 pk = Site.objects.get(domain='mydomainname.com').pk74 # If the domain already exists shouldn't work75 url = test_reverse('wa-domain', args=[pk])76 response = self.client.post(url, {'domain': 'testserver'})77 self.assertEqual(response.status_code, 400)78 # If nothing changed79 url = test_reverse('wa-domain', args=[pk])80 response = self.client.post(url, {'domain': 'mydomainname.com'})81 self.assertEqual(response.status_code, 200)82 # If the change was ok83 url = test_reverse('wa-domain', args=[pk])84 response = self.client.post(url, {'domain': 'example.com'})85 self.assertEqual(response.status_code, 200)86 def test_domain_delete_view(self):87 # If connected, should work88 self.client.login(username='admin', password='admin')89 # We create a new site90 put_url = test_reverse('wa-domain')91 self.client.put(put_url, {'domain': 'mydomainname.com'})92 pk = Site.objects.get(domain='mydomainname.com').pk 93 # If everything ok94 url = test_reverse('wa-domain', args=[pk])95 response = self.client.delete(url)96 self.assertContains(response, 'msg')97 98 # If the site doesn't exists99 url = test_reverse('wa-domain', args=[10])100 response = self.client.delete(url)101 self.assertEqual(response.status_code, 404)102 103 # If the site is the primary site104 url = test_reverse('wa-domain', args=[1])105 response = self.client.delete(url)...

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