def test_edit_request_view_inaccessible_if_pending(self): """Edit request not accessible if one already exists and is pending""" load_initial_data() mommy.make('EditRequest', certificate=self.cert, status=EditRequest.PENDING) response = self.c.get(self.url) self.assertRedirects(response, self.cert.get_absolute_url())
def test_default_auditor_search_filters_returns_query_params(self): load_initial_data() auditor = mommy.make(settings.AUTH_USER_MODEL, is_superuser=False) auditor.groups.add(Group.objects.get(name='Auditor')) """Query parameters for default auditor cert search are generated""" expected = 'status=1&status=2&status=3' self.assertEqual(Certificate.default_search_filters(auditor), expected)
def setUp(self): load_initial_data() self.licensee = mommy.make('Licensee') self.user = mommy.make(settings.AUTH_USER_MODEL, is_superuser=False) self.user.profile.licensees.add(self.licensee) self.url = reverse('new-addressee', args=[self.licensee.id]) self.c = Client() self.c.force_login(self.user)
def test_auditor_denied(self): """Auditors cannot access""" load_initial_data() self.user.is_superuser = False self.user.save() self.user.groups.add(Group.objects.get(name='Auditor')) response = self.c.post(self.url, self.form_kwargs) self.assertTemplateUsed(response, '403.html')
def _make_edit_form_kwargs(self): load_initial_data() form_kwargs = CERT_FORM_KWARGS.copy() form_kwargs.pop('attested') form_kwargs['harmonized_code'] = self.hs_code.id form_kwargs['port_of_export'] = self.poe.id form_kwargs['date_of_issue'] = '01/01/2018' form_kwargs['date_of_expiry'] = '03/02/2018' return form_kwargs
def setUp(self): load_initial_data() self.destination = mommy.make('KpcAddress', country='IN') self.licensee = self.destination.licensee self.user = mommy.make(settings.AUTH_USER_MODEL, is_superuser=False) self.user.profile.licensees.add(self.licensee) self.url = self.destination.get_absolute_url() self.c = Client() self.c.force_login(self.user)
def test_auditor_denied(self): """Auditors cannot access""" load_initial_data() cert = mommy.make(Certificate, void=False) self.user.is_superuser = False self.user.save() self.user.groups.add(Group.objects.get(name='Auditor')) response = self.c.get(reverse('void', args=[cert.number]), follow=True) self.assertTemplateUsed(response, '403.html')
def test_auditors_can_get(self): """Auditors can GET""" load_initial_data() self.user.is_superuser = False self.user.save() self.user.groups.add(Group.objects.get(name='Auditor')) cert = mommy.make(Certificate, status=Certificate.AVAILABLE) """User gets an editable form if certificate is editable""" response = self.c.get(cert.get_absolute_url()) self.assertTemplateUsed(response, 'certificate/prepare.html')
def test_auditor_denied_on_post(self): """Auditors cannot POST""" load_initial_data() self.user.is_superuser = False self.user.save() self.user.groups.add(Group.objects.get(name='Auditor')) cert = mommy.make(Certificate, status=Certificate.AVAILABLE) response = self.c.post(cert.get_absolute_url(), self.form_kwargs, follow=True) self.assertTemplateUsed(response, '403.html')
def test_can_post_with_perm(self): """ accounts.can_adjudicate_edit_requests allows POSTing to this view User can view edit request but not approve/reject """ load_initial_data() perm, _ = Permission.objects.get_or_create(codename='can_adjudicate_edit_requests') user = mommy.make(settings.AUTH_USER_MODEL, is_superuser=False) user.user_permissions.add(perm) licensee = mommy.make("Licensee") self.cert.licensee = licensee self.cert.save() user.profile.licensees.add(licensee) self.c.force_login(user) response = self.c.post(self.url) self.assertNotEqual(response.status_code, 403)
def test_auditor_can_access(self): """Can access details if auditor""" load_initial_data() auditor = mommy.make(settings.AUTH_USER_MODEL, is_superuser=False) auditor.groups.add(Group.objects.get(name='Auditor')) self.assertTrue(self.licensee.user_can_access(auditor))
def make_auditor(): load_initial_data() user = mommy.make(settings.AUTH_USER_MODEL, is_superuser=False) user.groups.add(Group.objects.get(name='Auditor')) return user