diff --git a/CHANGES b/CHANGES index f82eb8628..214f6a279 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +2.14 +---- +* Add geonameid to locations endpoint +* Add pd_url to pd indicator endpoint +* Set budget values in process_country and not through mapping +* Fix InterventionBudget loader queryset + 2.13 ---- * Add new office endpoint diff --git a/docker/Dockerfile.alpine.base b/docker/Dockerfile.alpine.base index 3840eb439..f370e406c 100644 --- a/docker/Dockerfile.alpine.base +++ b/docker/Dockerfile.alpine.base @@ -11,9 +11,9 @@ ENV TEST ${TEST} RUN apk add --no-cache --virtual .build-deps \ - --repository http://dl-cdn.alpinelinux.org/alpine/edge/main \ - --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \ - --repository http://dl-3.alpinelinux.org/alpine/edge/community/ \ + --repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/main \ + --repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/testing \ + --repository http://dl-3.alpinelinux.org/alpine/latest-stable/community/ \ gcc \ g++ \ gdal-dev \ diff --git a/docker/Makefile b/docker/Makefile index 677c33142..f0a36325d 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -4,7 +4,7 @@ DATABASE_URL_ETOOLS?= DEVELOP?=1 DOCKER_PASS?= DOCKER_USER?= -TARGET?=2.13.1a +TARGET?=2.14.1a PUSH_BASE?=1 BASE?=$(shell echo "${TARGET}" | sed "s/\([0-9]*\)\.\([0-9]*\)\.\(.*\)/\1.\2/g" ) #BASE?=$(shell echo "${TARGET}" | sed "s/\([0-9]*\)\.\([0-9]*\)\.\(.*\)/\1.\2/g" | echo "`xargs`xx" ) @@ -55,7 +55,7 @@ build-test: TARGET=dev $(MAKE) .build test build: - $(MAKE) .build test + $(MAKE) .build .run: diff --git a/src/etools_datamart/__init__.py b/src/etools_datamart/__init__.py index c3bba0f54..7987fc66f 100644 --- a/src/etools_datamart/__init__.py +++ b/src/etools_datamart/__init__.py @@ -1,7 +1,7 @@ import warnings NAME = 'etools-datamart' -VERSION = __version__ = '2.13' +VERSION = __version__ = '2.14' __author__ = '' # UserWarning: The psycopg2 wheel package will be renamed from release 2.11; diff --git a/src/etools_datamart/api/endpoints/datamart/location.py b/src/etools_datamart/api/endpoints/datamart/location.py index 75ca35c79..1731572a3 100644 --- a/src/etools_datamart/api/endpoints/datamart/location.py +++ b/src/etools_datamart/api/endpoints/datamart/location.py @@ -26,11 +26,18 @@ class Meta: class LocationSerializer(serializers.ModelSerializer): + geonameid = serializers.SerializerMethodField() + class Meta: model = models.Location exclude = ('schema_name', 'tree_id', 'lft', 'rght', 'level', 'source_id', 'geom', 'point', 'latitude', 'longitude') + def get_geonameid(self, obj): + if obj.geoname: + return obj.geoname.geoname_id + return None + class LocationViewSet(common.DataMartViewSet): serializer_class = LocationSerializer diff --git a/src/etools_datamart/apps/mart/data/migrations/0114_auto_20200420_1755.py b/src/etools_datamart/apps/mart/data/migrations/0114_auto_20200420_1755.py new file mode 100644 index 000000000..5b0368b23 --- /dev/null +++ b/src/etools_datamart/apps/mart/data/migrations/0114_auto_20200420_1755.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.9 on 2020-04-20 17:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('data', '0113_auto_20200408_1747'), + ] + + operations = [ + migrations.AlterField( + model_name='section', + name='name', + field=models.CharField(blank=True, max_length=128, null=True), + ), + ] diff --git a/src/etools_datamart/apps/mart/data/migrations/0115_pdindicator_pd_url.py b/src/etools_datamart/apps/mart/data/migrations/0115_pdindicator_pd_url.py new file mode 100644 index 000000000..e88e5869e --- /dev/null +++ b/src/etools_datamart/apps/mart/data/migrations/0115_pdindicator_pd_url.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.9 on 2020-04-21 13:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('data', '0114_auto_20200420_1755'), + ] + + operations = [ + migrations.AddField( + model_name='pdindicator', + name='pd_url', + field=models.CharField(blank=True, max_length=254, null=True), + ), + ] diff --git a/src/etools_datamart/apps/mart/data/migrations/0116_auto_20200417_1734.py b/src/etools_datamart/apps/mart/data/migrations/0116_auto_20200417_1734.py new file mode 100644 index 000000000..9cd726a6d --- /dev/null +++ b/src/etools_datamart/apps/mart/data/migrations/0116_auto_20200417_1734.py @@ -0,0 +1,37 @@ +# Generated by Django 2.2.11 on 2020-04-17 17:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('data', '0115_pdindicator_pd_url'), + ] + + operations = [ + migrations.CreateModel( + name='GeoName', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('toponym_name', models.CharField(max_length=254, null=True)), + ('name', models.CharField(max_length=254, null=True)), + ('lat', models.FloatField()), + ('lng', models.FloatField()), + ('geoname_id', models.CharField(max_length=50, null=True)), + ('country_code', models.CharField(max_length=20, null=True)), + ('country_name', models.CharField(max_length=150, null=True)), + ('fcl', models.CharField(max_length=50, null=True)), + ('fcode', models.CharField(max_length=50, null=True)), + ('distance', models.FloatField(null=True)), + ], + options={ + 'unique_together': {('lat', 'lng')}, + }, + ), + migrations.AddField( + model_name='location', + name='geoname', + field=models.ForeignKey(blank=True, null=True, on_delete=models.deletion.DO_NOTHING, to='data.GeoName'), + ), + ] diff --git a/src/etools_datamart/apps/mart/data/migrations/0117_auto_20200421_1544.py b/src/etools_datamart/apps/mart/data/migrations/0117_auto_20200421_1544.py new file mode 100644 index 000000000..8e39bab17 --- /dev/null +++ b/src/etools_datamart/apps/mart/data/migrations/0117_auto_20200421_1544.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.9 on 2020-04-21 15:44 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('data', '0116_auto_20200417_1734'), + ] + + operations = [ + migrations.AlterField( + model_name='location', + name='geoname', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='data.GeoName'), + ), + ] diff --git a/src/etools_datamart/apps/mart/data/models/location.py b/src/etools_datamart/apps/mart/data/models/location.py index b64dd77fe..2ce8c8460 100644 --- a/src/etools_datamart/apps/mart/data/models/location.py +++ b/src/etools_datamart/apps/mart/data/models/location.py @@ -1,7 +1,12 @@ +from xml.etree import ElementTree + +from django.conf import settings from django.contrib.gis.db import models as geomodels from django.contrib.gis.db.models.functions import Centroid from django.db import connection, models +import requests + from etools_datamart.apps.core.models import DataMartManager, DataMartQuerySet from etools_datamart.apps.mart.data.models.base import EtoolsDataMartModel from etools_datamart.apps.sources.etools.models import LocationsGatewaytype, LocationsLocation @@ -39,12 +44,29 @@ def batch_update_centroid(self): with connection.cursor() as cursor: cursor.execute(sql) + # need to update geoname + for record in super().filter( + latitude__isnull=False, + longitude__isnull=False, + ).all(): + geoname = GeoName.objects.get_or_add( + lat=record.latitude, + lng=record.longitude, + ) + if record.geoname != geoname: + record.geoname = geoname + record.save() + def update_centroid(self): clone = self._chain() for each in clone.annotate(cent=Centroid('geom')): each.point = each.cent each.latitude = each.point.y each.longitude = each.point.x + each.geoname = GeoName.objects.get_or_add( + lat=each.point.y, + lng=each.point.x, + ) each.save() @@ -69,6 +91,7 @@ class Location(EtoolsDataMartModel): point = geomodels.PointField(blank=True, null=True) gateway = models.ForeignKey(GatewayType, models.DO_NOTHING, blank=True, null=True) geom = geomodels.MultiPolygonField(blank=True, null=True) + geoname = models.ForeignKey("GeoName", models.DO_NOTHING, blank=True, null=True) level = models.IntegerField(db_index=True) lft = models.IntegerField() parent = models.ForeignKey('self', models.DO_NOTHING, blank=True, null=True) @@ -90,13 +113,87 @@ class Options: source = LocationsLocation queryset = lambda: LocationsLocation.objects.order_by('-parent') last_modify_field = 'modified' - exclude_from_compare = ['latitude', 'longitude', 'point'] + exclude_from_compare = ['latitude', 'longitude', 'point', 'geoname'] # sync_deleted_records = False mapping = {'source_id': 'id', # 'area_code': lambda loader, record: loader.context['country'].business_area_code, 'parent': '__self__', - 'gateway': GatewayType + 'gateway': GatewayType, } def __str__(self): return self.name + + +# store geo names pulled from http://api.geonames.org +# Using lat and lng get geoname data with +# http://api.geonames.org/findNearby?lat=47.3&lng=9&username=ntrncic +class GeoNameManager(models.Manager): + def get_or_add(self, lat, lng): + # check if we have a matching lat, lng record + # if so, return that record + # otherwise create a new record based on results + # of request to geonames.org + if not lat or not lng: + return None + try: + geoname = self.get_queryset().get(lat=lat, lng=lng) + except GeoName.DoesNotExist: + payload = { + "lat": lat, + "lng": lng, + "username": settings.GEONAMES_USERNAME, + } + res = requests.get( + settings.GEONAMES_URL, + params=payload, + timeout=settings.REQUEST_TIMEOUT, + ) + geoname = ElementTree.fromstring(res.content)[0] + mapping = [ + ("toponym_name", "toponymName"), + ("name", "name"), + ("lat", "lat"), + ("lng", "lng"), + ("geoname_id", "geonameId"), + ("country_code", "countryCode"), + ("country_name", "countryName"), + ("fcl", "fcl"), + ("fcode", "fcode"), + ("distance", "distance"), + ] + data = {} + for k, f in mapping: + try: + data[k] = geoname.find(f).text + except AttributeError: + return None + lat = data.pop("lat") + lng = data.pop("lng") + geoname, __ = GeoName.objects.get_or_create( + lat=lat, + lng=lng, + defaults=data, + ) + return geoname + + +class GeoName(models.Model): + toponym_name = models.CharField(max_length=254, null=True) + name = models.CharField(max_length=254, null=True) + lat = models.FloatField() + lng = models.FloatField() + geoname_id = models.CharField(max_length=50, null=True) + country_code = models.CharField(max_length=20, null=True) + country_name = models.CharField(max_length=150, null=True) + fcl = models.CharField(max_length=50, null=True) + fcode = models.CharField(max_length=50, null=True) + distance = models.FloatField(null=True) + + objects = GeoNameManager() + + class Meta: + unique_together = ('lat', 'lng') + + def __str__(self): + return f"{self.name} ({self.lat}, {self.lng})" diff --git a/src/etools_datamart/apps/mart/data/models/partners_interventionbudget.py b/src/etools_datamart/apps/mart/data/models/partners_interventionbudget.py index c9daa9767..f03b4e4fc 100644 --- a/src/etools_datamart/apps/mart/data/models/partners_interventionbudget.py +++ b/src/etools_datamart/apps/mart/data/models/partners_interventionbudget.py @@ -3,19 +3,24 @@ from etools_datamart.apps.mart.data.models import Location from etools_datamart.apps.mart.data.models.base import EtoolsDataMartModel from etools_datamart.apps.mart.data.models.intervention import InterventionAbstract, InterventionLoader -from etools_datamart.apps.mart.data.models.mixins import extend from etools_datamart.apps.sources.etools.models import (FundsFundsreservationheader, models, PartnersIntervention, PartnersInterventionbudget,) class InterventionBudgetLoader(InterventionLoader): + def get_queryset(self): + return PartnersInterventionbudget.objects + def process_country(self): - qs = PartnersInterventionbudget.objects.all() - for record in qs.all(): - record.intervention.budget = record + for record in self.get_queryset().all(): filters = self.config.key(self, record) values = self.get_values(record.intervention) values['source_id'] = record.id + values['budget_cso_contribution'] = record.partner_contribution_local + values['budget_unicef_cash'] = record.unicef_cash_local + values['budget_total'] = record.total_local + values['budget_currency'] = record.currency + values['budget_unicef_supply'] = record.in_kind_amount_local op = self.process_record(filters, values) self.increment_counter(op) @@ -57,13 +62,4 @@ class Options(InterventionAbstract.Options): model = PartnersInterventionbudget depends = (Location,) key = lambda loader, record: dict(schema_name=loader.context['country'].schema_name, - source_id=record.intervention.budget.pk) - - mapping = extend(InterventionAbstract.Options.mapping, - dict( - budget_cso_contribution='budget.partner_contribution_local', - budget_unicef_cash='budget.unicef_cash_local', - budget_total='budget.total_local', - budget_currency='budget.currency', - budget_unicef_supply='budget.in_kind_amount_local', - )) + source_id=record.pk) diff --git a/src/etools_datamart/apps/mart/data/models/pd_indicator.py b/src/etools_datamart/apps/mart/data/models/pd_indicator.py index 6a22d63a3..b0ac622f6 100644 --- a/src/etools_datamart/apps/mart/data/models/pd_indicator.py +++ b/src/etools_datamart/apps/mart/data/models/pd_indicator.py @@ -1,3 +1,5 @@ +from django.shortcuts import reverse + from etools_datamart.apps.mart.data.fields import SafeDecimal from etools_datamart.apps.mart.data.loader import EtoolsLoader from etools_datamart.apps.mart.data.models import Location @@ -30,6 +32,12 @@ def process_country(self): op = self.process_record(filters, values) self.increment_counter(op) + def get_pd_url(self, record: ReportsAppliedindicator, values: dict, **kwargs): + return reverse( + "api:intervention-detail", + args=["latest", record.lower_result.result_link.intervention.pk], + ) + class PDIndicator(LocationMixin, EtoolsDataMartModel): context_code = models.CharField(max_length=50, blank=True, null=True) @@ -73,6 +81,7 @@ class PDIndicator(LocationMixin, EtoolsDataMartModel): # from lower_result lower_result_name = models.CharField(max_length=500, blank=True, null=True) result_link_intervention = models.IntegerField(blank=True, null=True) + pd_url = models.CharField(max_length=254, blank=True, null=True) # from section section_name = models.CharField(max_length=45, blank=True, null=True) @@ -126,6 +135,7 @@ class Options: section_name='section.name', lower_result_name='lower_result.name', result_link_intervention='lower_result.result_link.intervention.pk', + pd_url='-', disaggregation_name='disaggregation.name', disaggregation_active='disaggregation.active', diff --git a/src/etools_datamart/apps/mart/data/models/report_sector.py b/src/etools_datamart/apps/mart/data/models/report_sector.py index af82cde4e..dd2ad1993 100644 --- a/src/etools_datamart/apps/mart/data/models/report_sector.py +++ b/src/etools_datamart/apps/mart/data/models/report_sector.py @@ -5,7 +5,7 @@ class Section(EtoolsDataMartModel): - name = models.CharField(max_length=45, blank=True, null=True) + name = models.CharField(max_length=128, blank=True, null=True) description = models.CharField(max_length=256, blank=True, null=True) alternate_id = models.IntegerField(blank=True, null=True) alternate_name = models.CharField(max_length=255, blank=True, null=True) diff --git a/src/etools_datamart/config/settings.py b/src/etools_datamart/config/settings.py index daa5e358c..caba29b52 100644 --- a/src/etools_datamart/config/settings.py +++ b/src/etools_datamart/config/settings.py @@ -79,6 +79,9 @@ URL_PREFIX=(str, ''), USE_X_FORWARDED_HOST=(bool, False), X_FRAME_OPTIONS=(str, 'DENY'), + GEONAMES_URL=(str, 'http://api.geonames.org/findNearby'), + GEONAMES_USERNAME=(str, 'ntrncic'), + REQUEST_TIMEOUT=(int, 300), ) DEBUG = env.bool('DEBUG') @@ -737,3 +740,7 @@ def before_send(event, hint): AZURE_AUTO_SIGN = env('AZURE_STORAGE_AUTO_SIGN') AZURE_ACCESS_MODE = env('AZURE_STORAGE_ACCESS_MODE') AZURE_ACCESS_TTL = env('AZURE_STORAGE_ACCESS_TTL') + +REQUEST_TIMEOUT = env('REQUEST_TIMEOUT') +GEONAMES_URL = env('GEONAMES_URL') +GEONAMES_USERNAME = env('GEONAMES_USERNAME') diff --git a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'geo'}.response.json b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'geo'}.response.json index 976f346e3..eb6fe86be 100644 --- a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'geo'}.response.json +++ b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'geo'}.response.json @@ -15,7 +15,7 @@ ], "etag": [ "ETag", - "\"a68108482a49fa9d63bcfc2be35ff6e8\"" + "\"7b1c8f06afa1b55cf60e751b25230b12\"" ], "x-frame-options": [ "X-Frame-Options", @@ -39,19 +39,27 @@ ], "cache-key": [ "cache-key", - "a68108482a49fa9d63bcfc2be35ff6e8" + "7b1c8f06afa1b55cf60e751b25230b12" ], "cache-hit": [ "cache-hit", "False" ], + "qs_filter": [ + "qs_filter", + "{}" + ], + "qs_exclude": [ + "qs_exclude", + "{}" + ], "cache-ttl": [ "cache-ttl", "1y" ], "content-length": [ "Content-Length", - "1147" + "1192" ] }, "data": { @@ -81,6 +89,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1514, + "geoname": null, "parent": null } }, @@ -102,6 +111,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1515, + "geoname": null, "parent": null } }, @@ -123,6 +133,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1516, + "geoname": null, "parent": null } } diff --git a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'gis'}.response.json b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'gis'}.response.json index 0f171ed38..5cb74403b 100644 --- a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'gis'}.response.json +++ b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'gis'}.response.json @@ -15,7 +15,7 @@ ], "etag": [ "ETag", - "\"1d8b75a006985f57eb41f0abe2b93b0d\"" + "\"7ca2df9eb73a74de5a1ae12f402b4375\"" ], "x-frame-options": [ "X-Frame-Options", @@ -39,19 +39,27 @@ ], "cache-key": [ "cache-key", - "1d8b75a006985f57eb41f0abe2b93b0d" + "7ca2df9eb73a74de5a1ae12f402b4375" ], "cache-hit": [ "cache-hit", "False" ], + "qs_filter": [ + "qs_filter", + "{}" + ], + "qs_exclude": [ + "qs_exclude", + "{}" + ], "cache-ttl": [ "cache-ttl", "1y" ], "content-length": [ "Content-Length", - "999" + "1044" ] }, "data": { @@ -77,6 +85,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1514, + "geoname": null, "parent": null }, { @@ -95,6 +104,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1515, + "geoname": null, "parent": null }, { @@ -113,6 +123,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1516, + "geoname": null, "parent": null } ] diff --git a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'latlng'}.response.json b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'latlng'}.response.json index 3f0c00e48..6fd9aaa37 100644 --- a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'latlng'}.response.json +++ b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'latlng'}.response.json @@ -15,7 +15,7 @@ ], "etag": [ "ETag", - "\"af31155424c5e98a227bc738e4e90aed\"" + "\"777205cfe9fa00154eca3971b7ccb10e\"" ], "x-frame-options": [ "X-Frame-Options", @@ -39,12 +39,20 @@ ], "cache-key": [ "cache-key", - "af31155424c5e98a227bc738e4e90aed" + "777205cfe9fa00154eca3971b7ccb10e" ], "cache-hit": [ "cache-hit", "False" ], + "qs_filter": [ + "qs_filter", + "{}" + ], + "qs_exclude": [ + "qs_exclude", + "{}" + ], "cache-ttl": [ "cache-ttl", "1y" diff --git a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'light'}.response.json b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'light'}.response.json index cdb776ef4..dd7aede4c 100644 --- a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'light'}.response.json +++ b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'light'}.response.json @@ -15,7 +15,7 @@ ], "etag": [ "ETag", - "\"e3fea213e28ce892638e1e22af822fd4\"" + "\"26cd3e770361ce343fd412b1cb5b8e9e\"" ], "x-frame-options": [ "X-Frame-Options", @@ -39,12 +39,20 @@ ], "cache-key": [ "cache-key", - "e3fea213e28ce892638e1e22af822fd4" + "26cd3e770361ce343fd412b1cb5b8e9e" ], "cache-hit": [ "cache-hit", "False" ], + "qs_filter": [ + "qs_filter", + "{}" + ], + "qs_exclude": [ + "qs_exclude", + "{}" + ], "cache-ttl": [ "cache-ttl", "1y" diff --git a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'std'}.response.json b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'std'}.response.json index a7b070a75..603c715e4 100644 --- a/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'std'}.response.json +++ b/tests/api/interfaces/_api_checker/test_data/test_list/_api_latest_datamart_locations_/get/{'-serializer': 'std'}.response.json @@ -15,7 +15,7 @@ ], "etag": [ "ETag", - "\"5ee8c76e2e1e6a3ff02fdc065c7fa81e\"" + "\"de8daea5fda4f852ad3f4fff999eae2c\"" ], "x-frame-options": [ "X-Frame-Options", @@ -39,19 +39,27 @@ ], "cache-key": [ "cache-key", - "5ee8c76e2e1e6a3ff02fdc065c7fa81e" + "de8daea5fda4f852ad3f4fff999eae2c" ], "cache-hit": [ "cache-hit", "False" ], + "qs_filter": [ + "qs_filter", + "{}" + ], + "qs_exclude": [ + "qs_exclude", + "{}" + ], "cache-ttl": [ "cache-ttl", "1y" ], "content-length": [ "Content-Length", - "825" + "921" ] }, "data": { @@ -63,6 +71,7 @@ "results": [ { "id": 1502, + "geonameid": null, "last_modify_date": "16 Sep 2019 18:29:12", "seen": null, "country_name": "bolivia", @@ -73,10 +82,12 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1514, + "geoname": null, "parent": null }, { "id": 1503, + "geonameid": null, "last_modify_date": "16 Sep 2019 18:29:12", "seen": null, "country_name": "chad", @@ -87,10 +98,12 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1515, + "geoname": null, "parent": null }, { "id": 1504, + "geonameid": null, "last_modify_date": "16 Sep 2019 18:29:12", "seen": null, "country_name": "lebanon", @@ -101,6 +114,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1516, + "geoname": null, "parent": null } ] diff --git a/tests/api/interfaces/_api_checker/test_data/test_record/_api_latest_datamart_locations_1505_/get/None.response.json b/tests/api/interfaces/_api_checker/test_data/test_record/_api_latest_datamart_locations_1505_/get/None.response.json index 7c878a822..84cb8a972 100644 --- a/tests/api/interfaces/_api_checker/test_data/test_record/_api_latest_datamart_locations_1505_/get/None.response.json +++ b/tests/api/interfaces/_api_checker/test_data/test_record/_api_latest_datamart_locations_1505_/get/None.response.json @@ -15,7 +15,7 @@ ], "etag": [ "ETag", - "\"79ff1e8816ef69c2d9436bbffae91cd2\"" + "\"9fc96177d97286f9f0ad7e47f1947f41\"" ], "x-frame-options": [ "X-Frame-Options", @@ -29,6 +29,14 @@ "service", "etools_datamart.api.endpoints.datamart.location.LocationViewSet" ], + "qs_filter": [ + "qs_filter", + "{}" + ], + "qs_exclude": [ + "qs_exclude", + "{}" + ], "cache-hit": [ "cache-hit", "False" @@ -39,11 +47,12 @@ ], "content-length": [ "Content-Length", - "247" + "279" ] }, "data": { "id": 1505, + "geonameid": null, "last_modify_date": "16 Sep 2019 18:29:18", "seen": null, "country_name": "bolivia", @@ -54,6 +63,7 @@ "modified": "16 Sep 2019 18:29:02", "is_active": true, "gateway": 1517, + "geoname": null, "parent": null }, "content_type": null diff --git a/tests/datamart/test_data_models.py b/tests/datamart/test_data_models.py index 4a4318919..a16a1c0c6 100644 --- a/tests/datamart/test_data_models.py +++ b/tests/datamart/test_data_models.py @@ -4,6 +4,10 @@ from django.apps import apps from django.db import connections +EXCLUDED_MODELS = [ + 'GeoName', +] + def pytest_generate_tests(metafunc): if 'context' in metafunc.fixturenames: @@ -11,13 +15,20 @@ def pytest_generate_tests(metafunc): models = [] ids = [] for m in config.get_models(): - ctx = {'country': 1, 'year': 2019} - models.append([m, ctx]) - ids.append(m.__name__) + if m.__name__ not in EXCLUDED_MODELS: + ctx = {'country': 1, 'year': 2019} + models.append([m, ctx]) + ids.append(m.__name__) metafunc.parametrize("model,context", models, ids=ids) elif 'model' in metafunc.fixturenames: config = apps.get_app_config('data') - metafunc.parametrize("model", config.get_models()) + metafunc.parametrize( + "model", + [ + m for m in config.get_models() + if m.__name__ not in EXCLUDED_MODELS + ], + ) def test_model_str(model):