def test_custom_report_detail_view_should_not_update_report_if_author_is_not_a_member_of_selected_project( self): other_project = ProjectFactory() other_project.save() old_description = self.data["description"] self.data["description"] = "Some other description" old_project = self.data["project"] self.data["project"] = other_project.pk response = self.client.post(path=self.url, data=self.data) self.report.refresh_from_db() self.assertEqual(response.status_code, 200) self.assertIsNotNone(response.context_data["form"].errors) self.assertEqual(old_description, self.report.description) self.assertEqual(old_project, self.report.project.pk)
class NotificationsTests(TestCase): def setUp(self): self.admin = AdminUserFactory() self.employee = UserFactory() self.manager = ManagerUserFactory() self.project = ProjectFactory() self.project.managers.add(self.admin) self.project.managers.add(self.manager) self.project.members.add(self.employee) self.url = reverse("custom-users-notifications") def _check_response(self, response, status_code, contains): self.assertTemplateUsed(response, NotificationUserListView.template_name) self.assertEqual(response.status_code, status_code) for element in contains: self.assertContains(response, element) @parameterized.expand(["2019-07-06", "2019-07-07", "2019-07-08"]) def test_manager_should_not_get_any_notification_about_missing_reports(self, test_date): with freeze_time("2019-07-05"): ReportFactory(author=self.employee, project=self.project, date="2019-07-05") self.client.force_login(self.manager) with freeze_time(test_date): response = self.client.get(self.url) self._check_response(response, 200, [UserNotificationsText.NO_MORE_NOTIFICATIONS.value]) @parameterized.expand( [ ("2019-07-10", '<td><div class="td-cell-value">1</div></td>'), ("2019-07-11", '<td><div class="td-cell-value">2</div></td>'), ("2019-07-15", '<td><div class="td-cell-value">4</div></td>'), ] ) def test_manager_should_get_notification_about_missing_reports(self, test_date, missing_reports): with freeze_time("2019-07-08"): ReportFactory(author=self.employee, project=self.project, date="2019-07-08") self.client.force_login(self.manager) with freeze_time(test_date): response = self.client.get(self.url) self._check_response(response, 200, [self.employee.email, missing_reports]) def test_manager_should_only_get_notifications_about_employees_from_his_projects(self): with freeze_time("2019-07-08"): ReportFactory(date="2019-07-08") self.client.force_login(self.manager) with freeze_time("2019-07-15"): response = self.client.get(self.url) self._check_response(response, 200, [UserNotificationsText.NO_MORE_NOTIFICATIONS.value]) def test_manager_should_not_get_any_notifications_if_they_are_disabled_for_project(self): self.project.is_notification_enabled = False self.project.save() with freeze_time("2019-07-08"): ReportFactory(author=self.employee, project=self.project, date="2019-07-08") self.client.force_login(self.manager) with freeze_time("2019-07-15"): response = self.client.get(self.url) self._check_response(response, 200, [UserNotificationsText.NO_MORE_NOTIFICATIONS.value]) def test_manager_should_not_get_get_notifications_about_inactive_employees(self): inactive_user = UserFactory(is_active=False) with freeze_time("2019-07-08"): ReportFactory(author=inactive_user, project=self.project, date="2019-07-08") self.client.force_login(self.manager) with freeze_time("2019-07-15"): response = self.client.get(self.url) self._check_response(response, 200, [UserNotificationsText.NO_MORE_NOTIFICATIONS.value])