def test_AttestableBasicNote_signing(self): """Verify that signing is possible for those with relevant permission. """ sign_url = "attestable-basic-note-sign" note = models.AttestableBasicNote.objects.create(**self.note_data) # Fresh notes should be unsigned assert not note.signed() # Providers with can_attend == False should not be able to sign can_sign_group = user_factories.PermGroupFactory( permissions=['workup.sign_AttestableBasicNote']) cannot_sign_group = user_factories.NoPermGroupFactory() can_sign = user_factories.UserFactory(groups=[can_sign_group]) cannot_sign = user_factories.UserFactory(groups=[cannot_sign_group]) for user in [can_sign, cannot_sign]: log_in_user(self.client, user) response = self.client.get(reverse(sign_url, args=(note.id, ))) detail_url = reverse('attestable-basic-note-detail', args=(note.id, )) self.assertRedirects(response, detail_url) assert models.AttestableBasicNote.objects.get( pk=note.id).signed() == (user == can_sign) note.signer = None note.save()
def build_user(group_factories=None, username=None, password=None): if group_factories is None: group_factories = [user_factories.VolunteerGroupFactory] return user_factories.UserFactory(groups=[f() for f in group_factories], username=username, password=password)
def test_workup_pdf(self): """Verify that pdf download with the correct name """ wu_url = "workup-pdf" no_perm_group = user_factories.NoPermGroupFactory() pdf_perm_group = user_factories.PermGroupFactory( permissions=['workup.export_pdf_Workup']) for group in [no_perm_group, pdf_perm_group]: log_in_user(self.client, user_factories.UserFactory(groups=[group])) response = self.client.get(reverse(wu_url, args=(self.wu.id, ))) assert response.status_code == 200 if group == pdf_perm_group else 403
def test_export_dispensing_histories(self): export_dispensing_histories_url = reverse('inventory:export-dispensing-history') no_perm_group = user_factories.NoPermGroupFactory() csv_perm_group = user_factories.PermGroupFactory(permissions=['inventory.export_csv']) for group in [no_perm_group, csv_perm_group]: log_in_user(self.client, user_factories.UserFactory(groups=[group])) response = self.client.post(export_dispensing_histories_url, {'start_date': '2020-09-22','end_date': '2020-09-28'}) if group == csv_perm_group: assert response.status_code == 200 self.assertEqual(response["Content-Disposition"], f"attachment; filename=drug-dispensing-history-through-09/28/20.csv") else: assert response.status_code == 403
def test_export_csv(self): export_csv_url = reverse('inventory:export-csv') no_perm_group = user_factories.NoPermGroupFactory() csv_perm_group = user_factories.PermGroupFactory(permissions=['inventory.export_csv']) for group in [no_perm_group, csv_perm_group]: log_in_user(self.client, user_factories.UserFactory(groups=[group])) response = self.client.post(export_csv_url) if group == csv_perm_group: assert response.status_code == 200 date_list = str(timezone.now().date()).split("-") formatted_date = f"{date_list[1]}/{date_list[2]}/{date_list[0][:2]}" self.assertEqual(response["Content-Disposition"], f"attachment; filename=drug-inventory-{formatted_date}.csv") else: assert response.status_code == 403
def test_audit_unicode(self): """Check that unicode works for TestAudit """ user = user_factories.UserFactory() p = PageviewRecord.objects.create( user=user, user_ip='128.0.0.1', role=user.groups.first(), method=PageviewRecord.HTTP_METHODS[0], url=reverse('home'), referrer='', status_code=200, ) self.assertEqual( str(p), "GET by %s to %s at %s" % (p.user, reverse('home'), p.timestamp))
def setUp(self): self.user = user_factories.UserFactory() self.ai_data = factory.build( dict, FACTORY_CLASS=factories.ActionItemFactory)