Skip to content

Commit 07b63dc

Browse files
authored
Merge pull request #7 from CIAT-DAPA/develop
GAP-11 #major
2 parents 347d9d8 + e7072ae commit 07b63dc

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Attributes:
9393
- species_name: `str` Name of the species of the accession. Optional.
9494
- crop: `Crop` Crop object, Crop to which the accession belongs. Mandatory.
9595
- landrace_group: `Group` Group object, Landrace group to which the accession belongs. Mandatory.
96+
- country: `Country` Country object, country to which the accession belongs. Mandatory.
9697
- institution_name: `str` Name of the institution that holds the accession. Optional.
9798
- source_database: `str` Name of the database where the accession was originally stored. Optional.
9899
- latitude: `float` Latitude of the geographical location where the accession was collected. Mandatory.

src/ormgap/models/accession.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mongoengine import Document, StringField, ReferenceField, FloatField, DictField
22
from .crop import Crop
33
from .group import Group
4+
from .country import Country
45

56
class Accession(Document):
67

@@ -19,6 +20,8 @@ class Accession(Document):
1920
Name of the institution that holds the accession. Optional.
2021
source_database: str
2122
Name of the database where the accession was originally stored. Optional.
23+
country: Country
24+
Country object, country to which the accession belongs. Mandatory.
2225
latitude: float
2326
Latitude of the geographical location where the accession was collected. Mandatory.
2427
longitude: float
@@ -46,6 +49,7 @@ class Accession(Document):
4649
landrace_group = ReferenceField(Group, required=True)
4750
institution_name = StringField(max_length=255)
4851
source_database = StringField(max_length=255)
52+
country = ReferenceField(Country, required=True)
4953
latitude = FloatField(required=True)
5054
longitude = FloatField(required=True)
5155
accession_id = StringField(max_length=255)

src/tests/test_accession.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ormgap.models.accession import Accession
1111
from ormgap.models.crop import Crop
1212
from ormgap.models.group import Group
13+
from ormgap.models.country import Country
1314

1415
class AccessionTestCase(unittest.TestCase):
1516
@classmethod
@@ -21,12 +22,15 @@ def setUp(self):
2122
self.assertIsNotNone(self.crop.id)
2223
self.group = Group(group_name='Test Group', crop=self.crop, ext_id='12345').save()
2324
self.assertIsNotNone(self.group.id)
25+
self.country = Country(iso_2='AR', name='Argentina').save()
26+
self.assertIsNotNone(self.country.id)
2427
self.accession = Accession(
2528
species_name='Test Species',
2629
crop=self.crop,
2730
landrace_group=self.group,
2831
institution_name='ICARDA',
2932
source_database='GENESYS',
33+
country=self.country,
3034
latitude=40.7128,
3135
longitude=-74.0060,
3236
accession_id='12345',
@@ -59,6 +63,13 @@ def test_get_accession_by_group(self):
5963
accession = accessions.first()
6064
self.assertEqual(self.group.id, accession.landrace_group.id)
6165

66+
def test_get_accession_by_country(self):
67+
self.accession.save()
68+
accessions =Accession.objects(country=self.country)
69+
self.assertGreaterEqual(len(accessions), 1)
70+
accession = accessions.first()
71+
self.assertEqual(self.country.id, accession.country.id)
72+
6273
def test_unique_ext_id(self):
6374
self.accession.save()
6475
accession = Accession(
@@ -69,12 +80,12 @@ def test_unique_ext_id(self):
6980
source_database='GENESYS',
7081
latitude=91, # Latitud inválida
7182
longitude=-181, # Longitud inválida
83+
country= self.country,
7284
accession_id='12345',
7385
ext_id='123'
7486
)
7587
with self.assertRaises(Exception) as context:
7688
accession.save()
77-
print(str(context.exception))
7889
self.assertTrue('Tried to save duplicate unique keys (E11000 Duplicate Key Error)' in str(context.exception))
7990

8091
def test_get_accession_by_invalid_id(self):
@@ -102,6 +113,7 @@ def test_delete_accession(self):
102113
def tearDown(self):
103114
self.crop.delete()
104115
self.group.delete()
116+
self.country.delete()
105117
Accession.objects.delete()
106118

107119
if __name__ == '__main__':

0 commit comments

Comments
 (0)