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())
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)
def setUp(self): """ Sets up before each test """ self.taxon = TaxonomyF.create(scientific_name='Aves', rank=TaxonomicRank.CLASS.name) self.permission = PermissionF.create(name='Can validate data', codename='can_validate_data')
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)
def test_Taxon_delete(self): """ Tests taxon model delete """ model = TaxonomyF.create() model.delete() # check if deleted self.assertTrue(model.pk is None)
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())
def test_Taxon_create(self): """ Tests taxon creation """ model = TaxonomyF.create() # check if pk exists self.assertTrue(model.pk is not None) # check if iucn_status exists self.assertTrue(model.iucn_status is not None) # check if scientific name exists self.assertTrue(model.scientific_name is not None)
def test_Taxon_read(self): """ Tests taxon model read """ iucn_status = IUCNStatusF.create( category=u'custom iucn status', sensitive=True, ) model = TaxonomyF.create(iucn_status=iucn_status, scientific_name=u'custom scientific name', canonical_name=u'custom common name', author=u'custom author') self.assertTrue(model.iucn_status.category == 'custom iucn status') self.assertTrue(model.scientific_name == 'custom scientific name') self.assertTrue(model.canonical_name == 'custom common name') self.assertTrue(model.author == 'custom author')
def test_get_taxon_by_id(self): pk = 1 taxon = TaxonomyF.create( pk=1, scientific_name=u'Golden fish', ) view = TaxonDetail.as_view() request = self.factory.get('/api/taxon/' + str(pk)) response = view(request, str(pk)) self.assertEqual(taxon.scientific_name, response.data['scientific_name']) # def test_get_allowed_geometry_location_type_by_id(self): view = LocationTypeAllowedGeometryDetail.as_view() pk = '%s' % self.fish_collection_1.site.location_type.pk request = self.factory.get('/api/location-type/%s/allowed-geometry/' % pk) response = view(request, pk) self.assertEqual(response.data, 'POINT')
def test_Taxon_update(self): """ Tests taxon model update """ model = TaxonomyF.create() iucn_status = IUCNStatusF.create( category=u'custom iucn status', sensitive=True, ) new_data = { 'iucn_status': iucn_status, 'scientific_name': u'new scientific name', 'common_name': u'new common name', 'author': u'custom author', } model.__dict__.update(new_data) model.save() # check if updated for key, val in new_data.items(): self.assertEqual(model.__dict__.get(key), val)