示例#1
0
    def test_get_unvalidated_records_as_validator(self):
        view = GetNonValidatedRecords.as_view()
        BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 1',
            site=self.location_site,
            validated=False,
            ready_for_validation=True,
            taxonomy=self.taxonomy_1)
        BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 2',
            site=self.location_site,
            validated=False,
            ready_for_validation=True,
            taxonomy=self.taxonomy_2)
        user = UserF.create()
        content_type = ContentTypeF.create(app_label='bims', model='bims')
        permission = PermissionF.create(name='Can validate Aves',
                                        content_type=content_type,
                                        codename='can_validate_aves')
        group = GroupF.create()
        group.permissions.add(permission)
        user.groups.add(group)

        request = self.factory.get(reverse('get-unvalidated-records'))
        request.user = user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data['data']), 2)
    def test_get_unvalidated_records_as_validator(self):
        view = GetNonValidatedRecords.as_view()
        user = UserF.create()
        content_type = ContentTypeF.create(app_label='bims', model='bims')
        permission = PermissionF.create(name='Can validate data',
                                        content_type=content_type,
                                        codename='can_validate_data')
        group = GroupF.create()
        group.permissions.add(permission)
        user.groups.add(group)

        request = self.factory.get(reverse('get-unvalidated-records'))
        request.user = user
        response = view(request)
        self.assertEqual(response.status_code, 200)
示例#3
0
    def test_only_get_aves_collection(self):
        from django.contrib.auth.models import Permission
        view = GetNonValidatedRecords.as_view()
        BiologicalCollectionRecordF.create(site=self.location_site,
                                           taxonomy=self.taxonomy_class_1,
                                           validated=False)
        user = UserF.create()
        permission = Permission.objects.filter(codename='can_validate_aves')[0]
        group = GroupF.create()
        group.permissions.add(permission)
        user.groups.add(group)

        request = self.factory.get(reverse('get-unvalidated-records'))
        request.user = user
        response = view(request)
        self.assertEqual(response.status_code, 200)