Best Python code snippet using Kiwi_python
test_permissions.py
Source:test_permissions.py  
...34    def verify_get_with_permission(self):35        response = self.client.get(self.url)36        self.assertContains(response, _('New bug'))37        self.assertContains(response, 'bugs/js/mutable.js')38    def verify_post_with_permission(self):39        initial_count = Bug.objects.count()40        response = self.client.post(self.url, self.post_data, follow=True)41        last_bug = Bug.objects.last()42        self.assertEqual(initial_count + 1, Bug.objects.count())43        self.assertEqual(self.tester, last_bug.reporter)44        self.assertContains(response, 'Bug created by test suite')45        self.assertContains(response, 'BUG-%d' % last_bug.pk)46class TestEdit(tests.PermissionsTestCase):47    permission_label = 'bugs.change_bug'48    http_method_names = ['get', 'post']49    @classmethod50    def setUpTestData(cls):51        cls.bug = BugFactory()52        cls.url = reverse('bugs-edit', args=(cls.bug.pk,))53        cls.post_data = {54            'summary': 'An edited summary',55            'reporter': cls.bug.reporter.pk,56            'assignee': cls.bug.assignee.pk,57            'product': cls.bug.product.pk,58            'version': cls.bug.version.pk,59            'build': cls.bug.build.pk,60        }61        super().setUpTestData()62        tests.user_should_have_perm(cls.tester, 'bugs.view_bug')63    def verify_get_with_permission(self):64        response = self.client.get(self.url)65        self.assertContains(response, _('Edit bug'))66        self.assertContains(response, self.url)67        self.assertContains(response, self.bug.summary)68        self.assertTemplateUsed(response, 'bugs/mutable.html')69    def verify_post_with_permission(self):70        response = self.client.post(self.url, self.post_data, follow=True)71        self.assertRedirects(72            response,73            reverse('bugs-get', args=(self.bug.pk,)),74            status_code=302,75            target_status_code=20076        )77        self.bug.refresh_from_db()78        self.assertContains(response, 'BUG-%d: %s' % (self.bug.pk, _(self.bug.summary)))79        self.assertTemplateUsed(response, 'bugs/get.html')80class TestAddComment(tests.PermissionsTestCase):81    permission_label = 'django_comments.add_comment'82    http_method_names = ['post']83    @classmethod84    def setUpTestData(cls):85        cls.bug = BugFactory()86        cls.url = reverse('bugs-comment')87        cls.post_data = {88            'bug': cls.bug.pk,89            'text': 'A comment text',90        }91        super().setUpTestData()92        tests.user_should_have_perm(cls.tester, 'bugs.view_bug')93    def verify_post_with_permission(self):94        old_comment_count = get_comments(self.bug).count()95        response = self.client.post(self.url, self.post_data, follow=True)96        comments = get_comments(self.bug)97        self.assertRedirects(98            response,99            reverse('bugs-get', args=(self.bug.pk,)),100            status_code=302,101            target_status_code=200102        )103        self.assertEqual(comments.count(), old_comment_count + 1)104        self.assertEqual(comments.last().comment, 'A comment text')105class TestSearch(tests.PermissionsTestCase):106    permission_label = 'bugs.view_bug'107    url = reverse('bugs-search')...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
