How to use remove_perm_from_user method in Kiwi

Best Python code snippet using Kiwi_python

test_views.py

Source:test_views.py Github

copy

Full Screen

...31 cls.unauthorized = UserFactory()32 cls.unauthorized.set_password("password")33 cls.unauthorized.save()34 cls.unauthorized.user_permissions.add(*Permission.objects.all())35 remove_perm_from_user(cls.unauthorized, "testruns.add_testruntag")36 remove_perm_from_user(cls.unauthorized, "testruns.delete_testruntag")37 def test_404_if_non_existing_pk(self):38 url = reverse("testruns-get", args=[99999999])39 response = self.client.get(url)40 self.assertEqual(HTTPStatus.NOT_FOUND, response.status_code)41 def test_get_a_run(self):42 url = reverse("testruns-get", args=[self.test_run.pk])43 response = self.client.get(url)44 self.assertEqual(HTTPStatus.OK, response.status_code)45 _tags = _("Tags")46 self.assertContains(47 response,48 f'<h2 class="card-pf-title"><span class="fa fa-tags"></span>{_tags}</h2>',49 html=True,50 )51 def test_get_run_without_permissions_to_add_or_remove_tags(self):52 self.client.logout()53 self.client.login( # nosec:B106:hardcoded_password_funcarg54 username=self.unauthorized.username, password="password"55 )56 url = reverse("testruns-get", args=[self.test_run.pk])57 response = self.client.get(url)58 self.assertEqual(HTTPStatus.OK, response.status_code)59 self.assertNotContains(response, "Add Tag")60 self.assertNotContains(response, "js-remove-tag")61class TestCreateNewRun(BasePlanCase):62 """Test creating new run"""63 @classmethod64 def setUpTestData(cls):65 super().setUpTestData()66 cls.build = BuildFactory(version=cls.plan.product_version)67 user_should_have_perm(cls.tester, "testruns.add_testrun")68 user_should_have_perm(cls.tester, "testruns.view_testrun")69 cls.url = reverse("testruns-new")70 def test_get_shows_selected_cases(self):71 self.client.login( # nosec:B106:hardcoded_password_funcarg72 username=self.tester.username, password="password"73 )74 response = self.client.get(75 self.url,76 {"p": self.plan.pk, "c": [self.case_1.pk, self.case_2.pk, self.case_3.pk]},77 )78 # Assert listed cases79 for _i, case in enumerate((self.case_1, self.case_2, self.case_3), 1):80 case_url = reverse("testcases-get", args=[case.pk])81 self.assertContains(82 response,83 f'<a href="{case_url}">TC-{case.pk}: {case.summary}</a>',84 html=True,85 )86 def test_post_creates_new_run(self):87 new_run_summary = "TestRun summary"88 post_data = {89 "summary": new_run_summary,90 "plan": self.plan.pk,91 "product_id": self.plan.product_id,92 "product": self.plan.product_id,93 "build": self.build.pk,94 "manager": self.tester.email,95 "default_tester": self.tester.email,96 "notes": "",97 "case": [self.case_1.pk, self.case_2.pk],98 }99 url = reverse("testruns-new")100 response = self.client.post(url, post_data)101 new_run = TestRun.objects.last()102 self.assertRedirects(response, reverse("testruns-get", args=[new_run.pk]))103 for case, execution in zip(104 (self.case_1, self.case_2), new_run.executions.order_by("case")105 ):106 self.assertEqual(case, execution.case)107 self.assertIsNone(execution.tested_by)108 self.assertEqual(self.tester, execution.assignee)109 self.assertEqual(110 case.history.latest().history_id, execution.case_text_version111 )112 self.assertEqual(new_run.build, execution.build)113 self.assertIsNone(execution.stop_date)114class TestCloneRunView(PermissionsTestCase):115 permission_label = "testruns.add_testrun"116 http_method_names = ["get"]117 @classmethod118 def setUpTestData(cls):119 cls.test_run = TestRunFactory()120 cls.execution_1 = TestExecutionFactory(run=cls.test_run)121 cls.execution_2 = TestExecutionFactory(run=cls.test_run)122 cls.url = reverse("testruns-clone", args=[cls.test_run.pk])123 super().setUpTestData()124 def verify_get_with_permission(self):125 response = self.client.get(self.url)126 self.assertContains(response, _("Clone TestRun"))127 _clone_of = _("Clone of ")128 self.assertContains(129 response,130 '<input id="id_summary" class="form-control" name="summary" '131 f'type="text" value="{_clone_of}{self.test_run.summary}" required>',132 html=True,133 )134 for execution in (self.execution_1, self.execution_2):135 case_url = reverse("testcases-get", args=[execution.case.pk])136 self.assertContains(137 response,138 f'<a href="{case_url}">TC-{execution.case.pk}: {execution.case.summary}</a>',139 html=True,140 )141class TestSearchRuns(BaseCaseRun):142 @classmethod143 def setUpTestData(cls):144 super(TestSearchRuns, cls).setUpTestData()145 cls.search_runs_url = reverse("testruns-search")146 user_should_have_perm(cls.tester, "testruns.view_testrun")147 def test_search_page_is_shown(self):148 response = self.client.get(self.search_runs_url)149 self.assertContains(response, '<input id="id_summary" type="text"')150 def test_search_page_is_shown_with_get_parameter_used(self):151 response = self.client.get(self.search_runs_url, {"product": self.product.pk})152 self.assertContains(153 response,154 f'<option value="{self.product.pk}" selected>{self.product.name}</option>',155 html=True,156 )157class TestRunCasesMenu(BaseCaseRun):158 @classmethod159 def setUpTestData(cls):160 super().setUpTestData()161 user_should_have_perm(cls.tester, "testruns.view_testrun")162 cls.url = reverse("testruns-get", args=[cls.test_run.pk])163 _update_text_version = _("Update text version")164 cls.update_text_version_html = f"""165 <a href="#" class="update-case-text-bulk">166 <span class="fa fa-refresh"></span>{_update_text_version}167 </a>168 """169 _assignee = _("Assignee")170 cls.change_assignee_html = f"""171 <a class="change-assignee-bulk" href="#">172 <span class="fa pficon-user"></span>173 {_assignee}174 </a>175 """176 _delete = _("Delete")177 cls.remove_executions_html = f"""178 <a class="bg-danger remove-execution-bulk" href="#">179 <span class="fa fa-trash-o"></span>180 {_delete}181 </a>182 """183 def test_add_cases_to_run_with_permission(self):184 user_should_have_perm(self.tester, "testruns.add_testexecution")185 response = self.client.get(self.url)186 self.assertContains(response, _("Search and add test cases"))187 self.assertContains(response, _("Advanced search"))188 def test_add_cases_to_run_without_permission(self):189 remove_perm_from_user(self.tester, "testruns.add_testexecution")190 response = self.client.get(self.url)191 self.assertNotContains(response, _("Search and add test cases"))192 self.assertNotContains(response, _("Advanced search"))193 def test_change_assignee_with_permission(self):194 user_should_have_perm(self.tester, "testruns.change_testexecution")195 response = self.client.get(self.url)196 self.assertContains(response, self.change_assignee_html, html=True)197 def test_change_assignee_without_permission(self):198 remove_perm_from_user(self.tester, "testruns.change_testexecution")199 response = self.client.get(self.url)200 self.assertNotContains(response, self.change_assignee_html, html=True)201 def test_update_text_version_with_permission(self):202 user_should_have_perm(self.tester, "testruns.change_testexecution")203 response = self.client.get(self.url)204 self.assertContains(response, self.update_text_version_html, html=True)205 def test_update_text_version_without_permission(self):206 remove_perm_from_user(self.tester, "testruns.change_testexecution")207 response = self.client.get(self.url)208 self.assertNotContains(response, self.update_text_version_html, html=True)209 def test_remove_executions_with_permission(self):210 user_should_have_perm(self.tester, "testruns.delete_testexecution")211 response = self.client.get(self.url)212 self.assertContains(response, self.remove_executions_html, html=True)213 def test_remove_executions_without_permission(self):214 remove_perm_from_user(self.tester, "testruns.delete_testexecution")215 response = self.client.get(self.url)216 self.assertNotContains(response, self.remove_executions_html, html=True)217class TestRunStatusMenu(BaseCaseRun):218 @classmethod219 def setUpTestData(cls):220 super().setUpTestData()221 cls.url = reverse("testruns-get", args=[cls.test_run.pk])222 user_should_have_perm(cls.tester, "testruns.view_testrun")223 cls.status_menu_html = []224 def test_get_status_options_with_permission(self):225 user_should_have_perm(self.tester, "testruns.change_testexecution")226 response = self.client.get(self.url)227 self.assertEqual(HTTPStatus.OK, response.status_code)228 for execution_status in TestExecutionStatus.objects.all():229 self.assertContains(230 response,231 f'<span class="{execution_status.icon}"></span>{execution_status.name}',232 html=True,233 )234 def test_get_status_options_without_permission(self):235 remove_perm_from_user(self.tester, "testruns.change_testexecution")236 response = self.client.get(self.url)237 self.assertEqual(HTTPStatus.OK, response.status_code)238 for execution_status in TestExecutionStatus.objects.all():239 self.assertNotContains(240 response,241 f'<span class="{execution_status.icon}"></span>{execution_status.name}',242 html=True,...

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 Kiwi 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