Exemple #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)
Exemple #2
0
 def test_get_referece_category(self):
     view = ReferenceCategoryList.as_view()
     BiologicalCollectionRecordF.create(original_species_name=u'Test name',
                                        site=self.location_site,
                                        reference_category=u'Database')
     request = self.factory.get(reverse('list-reference-category'))
     response = view(request)
     self.assertEqual(response.status_code, 200)
     self.assertTrue(len(response.data) > 0)
Exemple #3
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.location_site = LocationSiteF.create(
         pk=1, location_context_document='""')
     self.fish_collection_1 = BiologicalCollectionRecordF.create(
         pk=1,
         original_species_name=u'Test fish species name 1',
         site=self.location_site)
     self.fish_collection_2 = BiologicalCollectionRecordF.create(
         pk=2,
         original_species_name=u'Test fish species name 2',
         site=self.location_site)
 def test_add_taxa_to_taxon_group(self):
     taxonomy_1 = TaxonomyF.create()
     taxonomy_2 = TaxonomyF.create()
     BiologicalCollectionRecordF.create(taxonomy=taxonomy_1)
     taxon_group_1 = TaxonGroupF.create()
     add_taxa_to_taxon_group([taxonomy_1.id, taxonomy_2.id],
                             taxon_group_1.id)
     self.assertEqual(
         TaxonGroup.objects.get(
             id=taxon_group_1.id).taxonomies.all().count(), 2)
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(
             module_group=taxon_group_1).exists())
Exemple #5
0
 def test_get_module_summary(self):
     view = ModuleSummary.as_view()
     taxon_class_1 = TaxonomyF.create(scientific_name='Aves',
                                      rank=TaxonomicRank.CLASS.name)
     taxon_species_1 = TaxonomyF.create(scientific_name='Bird1',
                                        rank=TaxonomicRank.SPECIES.name,
                                        parent=taxon_class_1)
     BiologicalCollectionRecordF.create(taxonomy=taxon_species_1,
                                        validated=True,
                                        site=self.location_site)
     TaxonGroupF.create(name='fish',
                        category=TaxonomicGroupCategory.SPECIES_MODULE.name,
                        taxonomies=(taxon_class_1, ))
     request = self.factory.get(reverse('module-summary'))
     response = view(request)
     self.assertTrue(len(response.data['fish']) > 0)
Exemple #6
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)
Exemple #7
0
 def test_merge_users(self):
     """Test a function to merge multiple users"""
     user_1 = UserF.create()
     user_2 = UserF.create()
     BiologicalCollectionRecordF.create(owner=user_1, collector_user=user_2)
     BiologicalCollectionRecordF.create(owner=user_2, collector_user=user_1)
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(owner=user_2).exists())
     merge_users(primary_user=user_1, user_list=[user_1.id, user_2.id])
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(owner=user_1).count(), 2)
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(
             collector_user=user_1).count(), 2)
     self.assertFalse(
         BiologicalCollectionRecord.objects.filter(owner=user_2).exists())
    def test_owner_collector_user_delete_collection_record(self):
        """Test owner or collector user deleting collection record"""
        user = UserF.create()
        self.client.login(username=user.username, password='******')
        col = BiologicalCollectionRecordF.create(owner=user)
        self.client.post(
            reverse('collection-delete', kwargs={'col_id': col.id}))
        self.assertFalse(
            BiologicalCollectionRecord.objects.filter(id=col.id).exists())

        # Collector
        col = BiologicalCollectionRecordF.create(collector_user=user)
        self.assertTrue(
            BiologicalCollectionRecord.objects.filter(id=col.id).exists())
        self.client.post(
            reverse('collection-delete', kwargs={'col_id': col.id}))
        self.assertFalse(
            BiologicalCollectionRecord.objects.filter(id=col.id).exists())
 def test_super_user_delete_collection_record(self):
     user = UserF.create(is_superuser=True)
     self.client.login(username=user.username, password='******')
     col = BiologicalCollectionRecordF.create()
     response = self.client.post('{url}?next={next}'.format(
         url=reverse('collection-delete', kwargs={'col_id': col.id}),
         next=reverse('nonvalidated-user-list')))
     self.assertEqual(response.url, reverse('nonvalidated-user-list'))
     self.assertFalse(
         BiologicalCollectionRecord.objects.filter(id=col.id).exists())
 def test_common_user_delete_collection_record(self):
     """Test common user deleting collection record"""
     user = UserF.create()
     self.client.login(username=user.username, password='******')
     col = BiologicalCollectionRecordF.create()
     response = self.client.post(
         reverse('collection-delete', kwargs={'col_id': col.id}))
     self.assertEqual(response.status_code, 403)
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(id=col.id).exists())
Exemple #11
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.location_site = LocationSiteF.create(
            pk=1, location_context_document='""')

        self.taxonomy_class_1 = TaxonomyF.create(scientific_name='Aves',
                                                 rank=TaxonomicRank.CLASS.name)
        self.taxonomy_1 = TaxonomyF.create(scientific_name='Some aves name 1',
                                           canonical_name='aves name 1',
                                           rank=TaxonomicRank.SPECIES.name,
                                           parent=self.taxonomy_class_1)
        self.taxonomy_2 = TaxonomyF.create(scientific_name='Some aves name 2',
                                           canonical_name='aves name 2',
                                           rank=TaxonomicRank.SPECIES.name,
                                           parent=self.taxonomy_class_1)
        self.aves_collection_1 = BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 1',
            site=self.location_site,
            validated=True,
            ready_for_validation=True,
            taxonomy=self.taxonomy_1)
        self.aves_collection_2 = BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 2',
            site=self.location_site,
            validated=True,
            ready_for_validation=True,
            taxonomy=self.taxonomy_2)

        self.fish_collection_1 = BiologicalCollectionRecordF.create(
            original_species_name=u'Test fish species name 1',
            site=self.location_site,
            validated=True)
        self.fish_collection_2 = BiologicalCollectionRecordF.create(
            original_species_name=u'Test fish species name 2',
            site=self.location_site,
            validated=True)
        self.admin_user = UserF.create(is_superuser=True, is_staff=True)
        self.rebuild_index()
 def test_remove_taxa_from_taxon_group(self):
     taxonomy_1 = TaxonomyF.create()
     taxonomy_2 = TaxonomyF.create()
     taxonomy_3 = TaxonomyF.create()
     taxon_group_1 = TaxonGroupF.create(taxonomies=(taxonomy_1, taxonomy_2))
     biological_1 = BiologicalCollectionRecordF.create(
         taxonomy=taxonomy_1, module_group=taxon_group_1)
     BiologicalCollectionRecordF.create(taxonomy=taxonomy_3,
                                        module_group=taxon_group_1)
     self.assertEqual(taxon_group_1.taxonomies.all().count(), 2)
     self.assertEqual(biological_1.module_group, taxon_group_1)
     remove_taxa_from_taxon_group([taxonomy_1.id], taxon_group_1.id)
     # Removing taxon that doesn't exist in the group
     remove_taxa_from_taxon_group([taxonomy_3.id], taxon_group_1.id)
     self.assertEqual(
         TaxonGroup.objects.get(
             id=taxon_group_1.id).taxonomies.all().count(), 1)
     self.assertEqual(
         TaxonGroup.objects.get(
             id=taxon_group_1.id).taxonomies.all().count(), 1)
     self.assertFalse(
         BiologicalCollectionRecord.objects.filter(
             module_group=taxon_group_1).exists())
Exemple #13
0
    def test_merge_duplicated_taxa(self):
        """Test a function responsible for merging duplicated taxa"""

        vernacular_name_1 = VernacularNameF.create(name='common_name_1')
        vernacular_name_2 = VernacularNameF.create(name='common_name_2')
        vernacular_name_3 = VernacularNameF.create(name='common_name_3')
        taxa_1 = TaxonomyF.create(canonical_name='taxa_to_merged',
                                  vernacular_names=(vernacular_name_1, ))
        taxa_2 = TaxonomyF.create(canonical_name='verified_taxa',
                                  vernacular_names=(vernacular_name_2, ))
        taxa_3 = TaxonomyF.create(canonical_name='taxa_to_merged',
                                  vernacular_names=(vernacular_name_3,
                                                    vernacular_name_1))
        collection = BiologicalCollectionRecordF.create(taxonomy=taxa_1)
        taxon_group = TaxonGroupF.create(name='test',
                                         taxonomies=(taxa_1, taxa_3))
        taxon_group_2 = TaxonGroupF.create(name='test_3',
                                           taxonomies=(taxa_3, ))
        self.assertTrue(taxon_group.taxonomies.filter(id=taxa_1.id).exists())
        self.assertEqual(collection.taxonomy, taxa_1)

        # Merge all taxa
        merge_taxa_data(
            excluded_taxon=Taxonomy.objects.get(
                canonical_name='verified_taxa'),
            taxa_list=Taxonomy.objects.filter(canonical_name='taxa_to_merged'))
        # Collection should point to taxa_2
        self.assertEqual(
            BiologicalCollectionRecord.objects.get(id=collection.id).taxonomy,
            taxa_2)

        # Taxon group should have updated taxa member
        self.assertFalse(
            TaxonGroup.objects.filter(id=taxon_group.id,
                                      taxonomies__id=taxa_1.id).exists())
        self.assertTrue(
            TaxonGroup.objects.filter(id=taxon_group.id,
                                      taxonomies__id=taxa_2.id).exists())
        self.assertTrue(
            TaxonGroup.objects.filter(id=taxon_group_2.id,
                                      taxonomies__id=taxa_2.id).exists())

        # Vernacular names should be updated
        self.assertEqual(
            Taxonomy.objects.get(id=taxa_2.id).vernacular_names.all().count(),
            3)