Skip to content

Commit

Permalink
Merge pull request #148 from Mosquito-Alert/add_gbif_id
Browse files Browse the repository at this point in the history
Added Taxon.gbif_id
  • Loading branch information
epou authored Oct 6, 2023
2 parents 1a96aff + 4ec92c7 commit 55db94d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mosquito_alert/taxa/migrations/0003_taxon_gbif_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.3 on 2023-10-06 12:54

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("taxa", "0002_alter_speciedistribution_boundary"),
]

operations = [
migrations.AddField(
model_name="taxon",
name="gbif_id",
field=models.PositiveBigIntegerField(blank=True, null=True),
),
]
8 changes: 8 additions & 0 deletions mosquito_alert/taxa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ class TaxonomicRank(models.IntegerChoices):

# Attributes - Optional
common_name = models.CharField(max_length=64, null=True, blank=True)
gbif_id = models.PositiveBigIntegerField(null=True, blank=True)

# Object Manager
# Custom Properties
node_order_by = ["name"] # Needed for django-treebeard

@property
def gbif_url(self) -> str:
if self.gbif_id:
return f"https://www.gbif.org/species/{self.gbif_id}"

return ""

@property
def is_specie(self):
return self.rank >= self.TaxonomicRank.SPECIES_COMPLEX
Expand Down
11 changes: 11 additions & 0 deletions mosquito_alert/taxa/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ def test_tree_is_ordered_by_name_on_parent_change(self, taxon_root):

assert frozenset(Taxon.objects.all()) == frozenset([taxon_root, z_child, a_child, b_child])

def test_gbif_id_can_be_null(self):
assert Taxon._meta.get_field("gbif_id").null

def test_gbif_id_can_be_blank(self):
assert Taxon._meta.get_field("gbif_id").blank

# properties
@pytest.mark.parametrize("gbif_id, expected_result", [(None, ""), (12345, "https://www.gbif.org/species/12345")])
def test_gbif_url(self, gbif_id, expected_result):
assert TaxonFactory(gbif_id=gbif_id).gbif_url == expected_result


@pytest.mark.django_db
class TestSpecieDistributionModel:
Expand Down

0 comments on commit 55db94d

Please sign in to comment.