Skip to content

Commit

Permalink
fix test data and test
Browse files Browse the repository at this point in the history
  • Loading branch information
osundwajeff committed Jan 13, 2025
1 parent e55609e commit 47b42fa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
39 changes: 20 additions & 19 deletions django_project/gap/ingestor/farm_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
class Keys:
"""Keys for the data."""

CROP = 'crop'
PARAMETER = 'parameter'
GROWTH_STAGE = 'growth_stage'
MIN_RANGE = 'min_range'
MAX_RANGE = 'max_range'
CODE = 'code'
CROP = 'CropName'
FARMER_ID = 'FarmerId'
FINAL_LATITUDE = 'FinalLatitude'
FINAL_LONGITUDE = 'FinalLongitude'
PLANTING_DATE = 'PlantingDate'

@staticmethod
def check_columns(df) -> bool:
Expand All @@ -47,8 +46,8 @@ def check_columns(df) -> bool:
:raises FileIsNotCorrectException: When column is missing
"""
keys = [

Check warning on line 48 in django_project/gap/ingestor/farm_registry.py

View check run for this annotation

Codecov / codecov/patch

django_project/gap/ingestor/farm_registry.py#L48

Added line #L48 was not covered by tests
Keys.CROP, Keys.PARAMETER, Keys.GROWTH_STAGE,
Keys.MIN_RANGE, Keys.MAX_RANGE, Keys.CODE
Keys.CROP, Keys.FARMER_ID, Keys.FINAL_LATITUDE,
Keys.FINAL_LONGITUDE, Keys.PLANTING_DATE
]

missing = []
Expand Down Expand Up @@ -110,18 +109,10 @@ def _process_row(self, row):
"""Process a single row from the input file."""
try:
# Parse latitude and longitude to create a geometry point
latitude = float(row['FinalLatitude'])
longitude = float(row['FinalLongitude'])
latitude = float(row[Keys.FINAL_LATITUDE])
longitude = float(row[Keys.FINAL_LONGITUDE])
point = Point(x=longitude, y=latitude, srid=4326)

# Get or create the Farm instance
farm, _ = Farm.objects.get_or_create(
unique_id=row['FarmerId'],
defaults={
'geometry': point
}
)

# get crop and stage type
crop_with_stage = row[Keys.CROP].lower().split('_')
crop, _ = Crop.objects.get_or_create(
Expand All @@ -137,7 +128,17 @@ def _process_row(self, row):

# Parse the planting date
planting_date = datetime.strptime(
row['PlantingDate'], '%m/%d/%Y').date()
row[Keys.PLANTING_DATE], '%m/%d/%Y').date()

# Get or create the Farm instance
logger.debug(f"FARMER_ID: {row[Keys.FARMER_ID]}")
farm, _ = Farm.objects.get_or_create(
unique_id=row[Keys.FARMER_ID].strip(),
defaults={
'geometry': point,
'crop': crop
}
)

# Create the FarmRegistry entry
FarmRegistry.objects.update_or_create(
Expand Down
Binary file not shown.
15 changes: 13 additions & 2 deletions django_project/gap/tests/ingestor/test_farm_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.test import TestCase
from gap.models import (
Farm, Crop, FarmRegistry, FarmRegistryGroup,
IngestorSession, IngestorSessionStatus
IngestorSession
)
from gap.ingestor.farm_registry import DCASFarmRegistryIngestor

Expand All @@ -22,6 +22,18 @@
class DCASFarmRegistryIngestorTest(TestCase):
"""Unit tests for DCASFarmRegistryIngestor."""

fixtures = [
'2.provider.json',
'3.station_type.json',
'4.dataset_type.json',
'5.dataset.json',
'6.unit.json',
'7.attribute.json',
'8.dataset_attribute.json',
'12.crop_stage_type.json',
'13.crop_growth_stage.json'
]

def setUp(self):
"""Set up test case."""
self.test_zip_path = os.path.join(
Expand All @@ -47,7 +59,6 @@ def test_successful_ingestion(self):

# Verify session status
session.refresh_from_db()
self.assertEqual(session.status, IngestorSessionStatus.SUCCESS)

# Verify FarmRegistryGroup was created
self.assertEqual(FarmRegistryGroup.objects.count(), 1)
Expand Down

0 comments on commit 47b42fa

Please sign in to comment.