From 9b91066c55be3d85e8cc8eb7608e37f73d24c71c Mon Sep 17 00:00:00 2001 From: "Szabo, Zoltan" Date: Thu, 18 Aug 2022 15:33:42 +0200 Subject: [PATCH] Add annual figures --- deployments/admin.py | 5 + deployments/drf_views.py | 2 +- deployments/migrations/0067_annualsplit.py | 33 ++++ deployments/models.py | 21 ++ deployments/serializers.py | 9 + deployments/snapshots/snap_tests.py | 216 ++++++++++++--------- deployments/test_views.py | 34 +++- main/settings.py | 2 +- 8 files changed, 220 insertions(+), 102 deletions(-) create mode 100644 deployments/migrations/0067_annualsplit.py diff --git a/deployments/admin.py b/deployments/admin.py index c96f6b954..83e4c629b 100644 --- a/deployments/admin.py +++ b/deployments/admin.py @@ -104,6 +104,10 @@ class ProjectCountryFilter(AutocompleteFilter): field_name = 'project_country' +class ProjectAnnualSplitAdminInline(admin.TabularInline): + model = models.AnnualSplit + + class ProjectAdmin(CompareVersionAdmin, TranslationAdmin): form = ProjectForm reporting_ns_in = 'country_from__in' @@ -113,6 +117,7 @@ class ProjectAdmin(CompareVersionAdmin, TranslationAdmin): 'user', 'reporting_ns', 'project_country', 'project_districts', 'regional_project', 'event', 'dtype', ) + inlines = [ProjectAnnualSplitAdminInline] class Media: # Required by AutocompleteFilter pass diff --git a/deployments/drf_views.py b/deployments/drf_views.py index f43b101a8..f2bd39d12 100644 --- a/deployments/drf_views.py +++ b/deployments/drf_views.py @@ -368,7 +368,7 @@ class ProjectViewset( viewsets.ModelViewSet, ): queryset = Project.objects.prefetch_related( - 'user', 'reporting_ns', 'project_districts', 'event', 'dtype', 'regional_project', + 'user', 'reporting_ns', 'project_districts', 'event', 'dtype', 'regional_project', 'annual_splits', ).all() filterset_class = ProjectFilter serializer_class = ProjectSerializer diff --git a/deployments/migrations/0067_annualsplit.py b/deployments/migrations/0067_annualsplit.py new file mode 100644 index 000000000..4a0ca6e9d --- /dev/null +++ b/deployments/migrations/0067_annualsplit.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.27 on 2022-08-18 09:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('deployments', '0066_auto_20220727_0708'), + ] + + operations = [ + migrations.CreateModel( + name='AnnualSplit', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('year', models.IntegerField(blank=True, null=True, verbose_name='year')), + ('budget_amount', models.IntegerField(blank=True, null=True, verbose_name='amount')), + ('target_male', models.IntegerField(blank=True, null=True, verbose_name='target male')), + ('target_female', models.IntegerField(blank=True, null=True, verbose_name='target female')), + ('target_other', models.IntegerField(blank=True, null=True, verbose_name='target other')), + ('reached_male', models.IntegerField(blank=True, null=True, verbose_name='reached male')), + ('reached_female', models.IntegerField(blank=True, null=True, verbose_name='reached female')), + ('reached_other', models.IntegerField(blank=True, null=True, verbose_name='reached other')), + ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='annual_splits', to='deployments.Project', verbose_name='project')), + ], + options={ + 'verbose_name': 'Annual Split', + 'verbose_name_plural': 'Annual Splits', + }, + ), + ] diff --git a/deployments/models.py b/deployments/models.py index 48c27cd13..17ad42337 100644 --- a/deployments/models.py +++ b/deployments/models.py @@ -518,6 +518,27 @@ def get_for(user, queryset=None): ) +class AnnualSplit(models.Model): + """ Annual split for Project """ + + project = models.ForeignKey(Project, verbose_name=_('project'), related_name='annual_splits', on_delete=models.CASCADE) + year = models.IntegerField(verbose_name=_('year'), null=True, blank=True) + budget_amount = models.IntegerField(verbose_name=_('amount'), null=True, blank=True) + target_male = models.IntegerField(verbose_name=_('target male'), null=True, blank=True) + target_female = models.IntegerField(verbose_name=_('target female'), null=True, blank=True) + target_other = models.IntegerField(verbose_name=_('target other'), null=True, blank=True) + reached_male = models.IntegerField(verbose_name=_('reached male'), null=True, blank=True) + reached_female = models.IntegerField(verbose_name=_('reached female'), null=True, blank=True) + reached_other = models.IntegerField(verbose_name=_('reached other'), null=True, blank=True) + + class Meta: + verbose_name = _('Annual Split') + verbose_name_plural = _('Annual Splits') + + def __str__(self): + return '%s: %s %s | %s %s' % (str(self.project_id), str(self.year), str(self.budget_amount), str(self.target_male), str(self.reached_male),) + + @reversion.register() class ProjectImport(models.Model): """ diff --git a/deployments/serializers.py b/deployments/serializers.py index 41822ce39..547e87b52 100644 --- a/deployments/serializers.py +++ b/deployments/serializers.py @@ -24,6 +24,7 @@ ) from .models import ( + AnnualSplit, ERUOwner, ERU, PersonnelDeployment, @@ -337,6 +338,13 @@ class Meta: fields = '__all__' +class AnnualSplitSerializer(ModelSerializer): + class Meta: + model = AnnualSplit + fields = ('year', 'budget_amount', 'target_male', 'target_female', 'target_other', + 'reached_male', 'reached_female', 'reached_other',) + + class ProjectSerializer(EnumSupportSerializerMixin, ModelSerializer): project_country_detail = MiniCountrySerializer(source='project_country', read_only=True) project_districts_detail = MiniDistrictSerializer(source='project_districts', read_only=True, many=True) @@ -350,6 +358,7 @@ class ProjectSerializer(EnumSupportSerializerMixin, ModelSerializer): status_display = serializers.CharField(source='get_status_display', read_only=True) visibility_display = serializers.CharField(source='get_visibility_display', read_only=True) secondary_sectors_display = serializers.ListField(source='get_secondary_sectors_display', read_only=True) + annual_split_detail = AnnualSplitSerializer(source='annual_splits', many=True, read_only=True) modified_by_detail = MiniUserSerializer(source='modified_by', read_only=True) class Meta: diff --git a/deployments/snapshots/snap_tests.py b/deployments/snapshots/snap_tests.py index 29fb2423b..40be04d37 100644 --- a/deployments/snapshots/snap_tests.py +++ b/deployments/snapshots/snap_tests.py @@ -238,10 +238,8 @@ 'count': 1, 'primary_sector': 0, 'primary_sector_display': 'WASH' - } ], - 'society_name': 'society-name-ZfIICfPhtHBcdPxXcaTMlqrMTOlHCJFwODdOoPbXjLmbhgUjvO', 'target_total': 0 }, @@ -251,9 +249,19 @@ 'iso3': 'vSz', 'name': 'country-lhXnmyTHMXydaGmrDBRVeiQGOKHLNUoaRFrygVhVpUKMWOEKMi', 'ongoing_projects': 1, - 'operation_types': [1], - 'operation_types_display': ['Emergency Operation'], - 'projects_per_sector':[{'count': 1, 'primary_sector': 2, 'primary_sector_display': 'CEA'}], + 'operation_types': [ + 1 + ], + 'operation_types_display': [ + 'Emergency Operation' + ], + 'projects_per_sector': [ + { + 'count': 1, + 'primary_sector': 2, + 'primary_sector_display': 'CEA' + } + ], 'society_name': 'society-name-dYonHRFVIHRwjGxUPJNGzGPgIXXqXpKDzSpdTKaPaEpFLsNLNY', 'target_total': 0 }, @@ -263,9 +271,19 @@ 'iso3': 'ovT', 'name': 'country-IONANNPhnjWOLpxCunHtYGOegfuTFcmtDxzdPfAsRkyltvusAk', 'ongoing_projects': 1, - 'operation_types': [1], - 'operation_types_display': ['Emergency Operation'], - 'projects_per_sector': [{'count': 1, 'primary_sector': 0, 'primary_sector_display': 'WASH'}], + 'operation_types': [ + 1 + ], + 'operation_types_display': [ + 'Emergency Operation' + ], + 'projects_per_sector': [ + { + 'count': 1, + 'primary_sector': 0, + 'primary_sector_display': 'WASH' + } + ], 'society_name': 'society-name-qYyNTSkjQpKsaFfWCpQsoryydZNvqERdUQdAdYYpKHedCKXwgz', 'target_total': 0 }, @@ -461,94 +479,6 @@ ,,,,,,,,,,,,1,,,,,,,,,,,True,True,,,,,,,,\r ''' -snapshots['TestProjectAPI::test_project_create 1'] = { - 'actual_expenditure': 0, - 'budget_amount': 410000, - 'description': '', - 'document': None, - 'dtype': None, - 'dtype_detail': None, - 'end_date': '2008-01-01', - 'event': None, - 'event_detail': None, - 'id': 1, - 'modified_at': '2008-01-01T00:00:00.123456Z', - 'modified_by': None, - 'modified_by_detail': None, - 'name': 'Mock Project for Create API Test', - 'operation_type': 1, - 'operation_type_display': 'Emergency Operation', - 'primary_sector': 7, - 'primary_sector_display': 'NS Strengthening', - 'programme_type': 2, - 'programme_type_display': 'Domestic', - 'project_country': 1, - 'project_country_detail': { - 'average_household_size': None, - 'fdrs': None, - 'id': 1, - 'independent': None, - 'is_deprecated': False, - 'iso': 'oA', - 'iso3': 'MjY', - 'name': 'country-hQoAZvUhEREEnLkPAbpciKLkiOGcKjdkqlHzMKObUUQsfnCMEE', - 'record_type': 2, - 'record_type_display': 'Cluster', - 'region': 1, - 'society_name': 'society-name-LXlNQGqkURvDMLeoyyigbmHGRAjMglENMcYIGWhfEQiMIaXRPB' - }, - 'project_districts': [ - 1 - ], - 'project_districts_detail': [ - { - 'code': 'DPCfUGhlXL', - 'id': 1, - 'is_deprecated': False, - 'is_enclave': True, - 'name': 'district-cMVyUuzNVKMIHPTYcHgCDcpHIzVcJyHWOdmsCztXsDkBsNdSHj' - } - ], - 'reached_female': 0, - 'reached_male': 0, - 'reached_other': 0, - 'reached_total': 0, - 'regional_project': None, - 'regional_project_detail': None, - 'reporting_ns': 1, - 'reporting_ns_contact_email': None, - 'reporting_ns_contact_name': None, - 'reporting_ns_contact_role': None, - 'reporting_ns_detail': { - 'average_household_size': None, - 'fdrs': None, - 'id': 1, - 'independent': None, - 'is_deprecated': False, - 'iso': 'oA', - 'iso3': 'MjY', - 'name': 'country-hQoAZvUhEREEnLkPAbpciKLkiOGcKjdkqlHzMKObUUQsfnCMEE', - 'record_type': 2, - 'record_type_display': 'Cluster', - 'region': 1, - 'society_name': 'society-name-LXlNQGqkURvDMLeoyyigbmHGRAjMglENMcYIGWhfEQiMIaXRPB' - }, - 'secondary_sectors': [ - ], - 'secondary_sectors_display': [ - ], - 'start_date': '2008-01-01', - 'status': 1, - 'status_display': 'Ongoing', - 'target_female': 0, - 'target_male': 0, - 'target_other': 0, - 'target_total': 0, - 'user': 2, - 'visibility': 'public', - 'visibility_display': 'Public' -} - snapshots['TestProjectAPI::test_project_csv_api 1'] = '''actual_expenditure,budget_amount,description,document,dtype,dtype_detail.id,dtype_detail.name,dtype_detail.summary,end_date,event,event_detail.dtype,event_detail.emergency_response_contact_email,event_detail.id,event_detail.name,event_detail.parent_event,event_detail.slug,id,modified_at,modified_by,modified_by_detail,name,operation_type,operation_type_display,primary_sector,primary_sector_display,programme_type,programme_type_display,project_country,project_country_detail.average_household_size,project_country_detail.fdrs,project_country_detail.id,project_country_detail.independent,project_country_detail.is_deprecated,project_country_detail.iso,project_country_detail.iso3,project_country_detail.name,project_country_detail.record_type,project_country_detail.record_type_display,project_country_detail.region,project_country_detail.society_name,project_districts_detail.code,project_districts_detail.id,project_districts_detail.is_deprecated,project_districts_detail.is_enclave,project_districts_detail.name,reached_female,reached_male,reached_other,reached_total,regional_project,regional_project_detail.created_at,regional_project_detail.id,regional_project_detail.modified_at,regional_project_detail.name,reporting_ns,reporting_ns_contact_email,reporting_ns_contact_name,reporting_ns_contact_role,reporting_ns_detail.average_household_size,reporting_ns_detail.fdrs,reporting_ns_detail.id,reporting_ns_detail.independent,reporting_ns_detail.is_deprecated,reporting_ns_detail.iso,reporting_ns_detail.iso3,reporting_ns_detail.name,reporting_ns_detail.record_type,reporting_ns_detail.record_type_display,reporting_ns_detail.region,reporting_ns_detail.society_name,secondary_sectors,secondary_sectors_display,start_date,status,status_display,target_female,target_male,target_other,target_total,user,visibility,visibility_display\r 0,1200000,,,3,3,disaster-type-KOlJVJAVgXOKwRDSQBgkYlJzGvQkIMCwuJuxAWOBUuMpKInyXJ,VqxCCzaUcsMbHitatonubXSrJGJKKjgcDwjiqxLpoqZtfKzKnUeUuYElFSSKgMPtcUZKyfXdXvwBAhXoVPMaOXOydtHcuIKjuGSojdRUzCWMKGfoBsYzjivfEKVdJzqfzGBXSiWiEJmFzPKmJNVHpperXBuRKfhQABxwmuwMPbXtkwNZCNjCcomRxjWUfhVdpNjsavSZhtCEbvnVInnIHWqJENUjSSQbyLQHcqkdsmYSNrdDPaeyQrQQxgbsPyoyGTguFMIflmGDJTbcpHtvFzVkbwRwwOtpGrZdOqybJrojvzQifUyHRNORoApKjBtMvCIinPiLIRZmitSTHiBXjPKkueJIUhlujUbWuAAtCVOVrjXmgilbWNNrMKNoMooRbwfSXEiGMETPxlyFEikmocAWarAoVQmWnelCNFSuDpBzXcMVyUuzNVKMIHPTYcHgCDcpHIzVcJyHWOdmsCztXsDkBsNdSHjDPCfUGhlXLSIizAuCblDL,2008-01-01,2,1,,2,event-JEdfryiAmPZHpOZIYbyYTwEIYFwKGuyrlbuMobZXrdZEHwXLok,1,gpqpriyvdwokzywllpluzvswlbtswkkjkmzfitlfcfdomobhea,1,2008-01-01T00:00:00.123456Z,,,project-TmDfquSPTYkTUhfhTCOxfHTyUYGNkyJycXkvKQjkjlXTdAttUX,0,Programme,4,Health,1,Multilateral,3,,,3,,False,ZQ,ANX,country-AlXiXPUPAxyCyyfRQIiPwhlIzHiUoaWbtDRUIBIyopDwjrmUWh,1,Country,3,society-name-bpnegMcCMRTdpVczCoInWXdiGsoUKuKMXRuptjQHoAtrdJLVlO,"gRoEbNJuNo, nPOMbdYvpi","1, 2","False, True","True, True","district-uVAlmiYIxHGrkqEZsVvZhDejWoRURzZJxfYzaqIhDxRVRqLyOx, district-cctFhgpIiyDxQVSIALVUjAPgFNArcSxnCCpxgRxIPwdzrmhDfQ",0,0,0,0,1,2008-01-01T00:00:00.123456Z,1,2008-01-01T00:00:00.123456Z,regional-project-pnLQEDACfMMapJrNOJndljdPwcjcQKMtvfdgAlkRsNQSSMKYJl,2,,,,,,2,,False,dE,zBR,country-YMarjiIqZlhQbiawYYpLublqdiVAHhVeECXxGLgCGoNcUYQHtD,1,Country,2,society-name-gFTCefuMjeirNOLJTuyMHsDGMBgYShPPXJUnBCoAvDzAUguBuQ,"0, 1","WASH, PGI",2008-01-01,1,Ongoing,0,0,0,0,2,public,Public\r 0,8470000,,,6,6,disaster-type-hmscizAVvckQmEQrhAFJFZRTiuWWXzGUVyihgYbijwGaXRpdRv,BMVaBEssFfWBpNjUGlprXhqSpQBmETYZgSUGNlmLOOjohizcrmjBbNmfdyAHtSOoovBEdGBPdthrxrwTApudlcadQVunsErMgBlqFxvthgQaRJXivxVZxVXLHMxpPrnLyfgiOVMhcLPmmTCgeINvtUEWmIUjcimAJTqWJwxCOThBeEAHGYbkMrSiscKdYSmVzFRIGekCWGyJXyzMrnlakKnLSaYGDGTUHqtosTrJhkocIpscOjrirYdPpnIhaPwOMxufTJqUiANsudOawoUrlqbIQXXLgUVSyPqOOMJnCournLOZWzjCoUUBxjEfFlDllmKFUlPsbtklzRMmejeBpDPzgUHiUWZaMgyybhaWPcipXfrjOMaYaYgIVvTfmiEWKCktvEjpdISrOIhbcgIsgGAjaoboByjwPsoRyRThFkhogsweNvhxfcMjlBHvMlRBjQRtNswgrFQxqZTZeYajXPjujyCUYYEehKBUrjfuilXywuFBESAM,2008-01-01,4,4,,4,event-vMTQDisUTyARPVxYEZkNnsSVfQEilmkMFgYAFtpnJdbwqwRklG,3,czevbhnohjofqvywxcxjrjsgmqgtdczdwhgynnygjcggkohnxk,2,2008-01-01T00:00:00.123456Z,,,project-YOviZPpyAJFIIFIIoyfLTAHKXSZVoSfpxanbxJEihdwxXisDjJ,0,Programme,3,Migration,1,Multilateral,5,,,5,,False,MM,GdQ,country-sWKQjZKUCvShUEciRJhtbzNoCwfudMPmLHoYXrmbfICRQfGzmF,3,Region,5,society-name-xzjTBxyxaswwtCJfnUCVAZCskZUBUAiLMfjntEHveLWyfaAOrA,"gRoEbNJuNo, nPOMbdYvpi","1, 2","False, True","True, True","district-uVAlmiYIxHGrkqEZsVvZhDejWoRURzZJxfYzaqIhDxRVRqLyOx, district-cctFhgpIiyDxQVSIALVUjAPgFNArcSxnCCpxgRxIPwdzrmhDfQ",0,0,0,0,2,2008-01-01T00:00:00.123456Z,2,2008-01-01T00:00:00.123456Z,regional-project-SgQLeEMkbjxjfpeaKAjWlEViVHStEAUvCYPSashjdPcMWlGkaz,4,,,,,,4,,False,UO,FFZ,country-XtuxyeWBJesEihSrvHAHnSnNdgKUOHfEUSMYTsBMuqHKNwiNKF,5,Representative Office,4,society-name-lNoTsmahbDOYhVnZNAAcvwJZOnaOmSsqYettGJuXahRvvzUKNb,"0, 1","WASH, PGI",2008-01-01,1,Ongoing,0,0,0,0,3,public,Public\r @@ -571,6 +501,7 @@ 'results': [ { 'actual_expenditure': 0, + 'annual_split_detail': [], 'budget_amount': 9080000, 'description': '', 'document': None, @@ -676,6 +607,7 @@ 'results': [ { 'actual_expenditure': 0, + 'annual_split_detail': [], 'budget_amount': 9080000, 'description': '', 'document': None, @@ -773,6 +705,7 @@ }, { 'actual_expenditure': 0, + 'annual_split_detail': [], 'budget_amount': 4360000, 'description': '', 'document': None, @@ -881,6 +814,7 @@ snapshots['TestProjectAPI::test_project_read 1'] = { 'actual_expenditure': 0, + 'annual_split_detail': [], 'budget_amount': 9080000, 'description': '', 'document': None, @@ -977,8 +911,98 @@ 'visibility_display': 'Public' } +snapshots['TestProjectAPI::test_project_create 1'] = { + 'actual_expenditure': 0, + 'annual_split_detail': [], + 'budget_amount': 410000, + 'description': '', + 'document': None, + 'dtype': None, + 'dtype_detail': None, + 'end_date': '2008-01-01', + 'event': None, + 'event_detail': None, + 'id': 1, + 'modified_at': '2008-01-01T00:00:00.123456Z', + 'modified_by': None, + 'modified_by_detail': None, + 'name': 'Mock Project for Create API Test', + 'operation_type': 1, + 'operation_type_display': 'Emergency Operation', + 'primary_sector': 7, + 'primary_sector_display': 'NS Strengthening', + 'programme_type': 2, + 'programme_type_display': 'Domestic', + 'project_country': 1, + 'project_country_detail': { + 'average_household_size': None, + 'fdrs': None, + 'id': 1, + 'independent': None, + 'is_deprecated': False, + 'iso': 'oA', + 'iso3': 'MjY', + 'name': 'country-hQoAZvUhEREEnLkPAbpciKLkiOGcKjdkqlHzMKObUUQsfnCMEE', + 'record_type': 2, + 'record_type_display': 'Cluster', + 'region': 1, + 'society_name': 'society-name-LXlNQGqkURvDMLeoyyigbmHGRAjMglENMcYIGWhfEQiMIaXRPB' + }, + 'project_districts': [ + 1 + ], + 'project_districts_detail': [ + { + 'code': 'DPCfUGhlXL', + 'id': 1, + 'is_deprecated': False, + 'is_enclave': True, + 'name': 'district-cMVyUuzNVKMIHPTYcHgCDcpHIzVcJyHWOdmsCztXsDkBsNdSHj' + } + ], + 'reached_female': 0, + 'reached_male': 0, + 'reached_other': 0, + 'reached_total': 0, + 'regional_project': None, + 'regional_project_detail': None, + 'reporting_ns': 1, + 'reporting_ns_contact_email': None, + 'reporting_ns_contact_name': None, + 'reporting_ns_contact_role': None, + 'reporting_ns_detail': { + 'average_household_size': None, + 'fdrs': None, + 'id': 1, + 'independent': None, + 'is_deprecated': False, + 'iso': 'oA', + 'iso3': 'MjY', + 'name': 'country-hQoAZvUhEREEnLkPAbpciKLkiOGcKjdkqlHzMKObUUQsfnCMEE', + 'record_type': 2, + 'record_type_display': 'Cluster', + 'region': 1, + 'society_name': 'society-name-LXlNQGqkURvDMLeoyyigbmHGRAjMglENMcYIGWhfEQiMIaXRPB' + }, + 'secondary_sectors': [ + ], + 'secondary_sectors_display': [ + ], + 'start_date': '2008-01-01', + 'status': 1, + 'status_display': 'Ongoing', + 'target_female': 0, + 'target_male': 0, + 'target_other': 0, + 'target_total': 0, + 'user': 2, + 'visibility': 'public', + 'visibility_display': 'Public' +} + snapshots['TestProjectAPI::test_project_update 1'] = { 'actual_expenditure': 0, + 'annual_split_detail': [], 'budget_amount': 9080000, 'description': '', 'document': None, diff --git a/deployments/test_views.py b/deployments/test_views.py index d5c27e2b2..9b87bfb7e 100644 --- a/deployments/test_views.py +++ b/deployments/test_views.py @@ -1,5 +1,5 @@ import json -import datetime +import datetime, pytz from unittest import mock from django.core import management @@ -13,6 +13,7 @@ from .models import ( + AnnualSplit, Project, ProgrammeTypes, Sectors, @@ -36,9 +37,14 @@ def setUp(self): self.maxDiff = None self.country1 = Country.objects.create(name='country1', iso='XX') self.country2 = Country.objects.create(name='country2', iso='YY') + self.country3 = Country.objects.create(name='country3', iso='ZZ') self.district1 = District.objects.create(name='district1', country=self.country1) self.district2 = District.objects.create(name='district2', country=self.country2) + self.district3 = District.objects.create(name='district3', country=self.country3) + + self.split1 = AnnualSplit.objects.create(project_id=0, year=2009, budget_amount=333, target_male=40) + first = Project.objects.create( user=self.user, @@ -69,6 +75,22 @@ def setUp(self): ) second.project_districts.set([self.district2]) + third = Project.objects.create( + id=0, + user=self.user, + reporting_ns=self.country3, + name='ccc', + programme_type=ProgrammeTypes.MULTILATERAL.value, + primary_sector=Sectors.SHELTER.value, + secondary_sectors=[SectorTags.WASH.value, SectorTags.MIGRATION.value], + operation_type=OperationTypes.PROGRAMME.value, + start_date=datetime.date(2012, 12, 12), + end_date=datetime.date(2013, 1, 1), + budget_amount=3000, + status=Statuses.ONGOING.value, + ) + third.project_districts.set([self.district3]) + def create_project(self, **kwargs): project = Project.objects.create( user=self.user, @@ -124,14 +146,14 @@ def test_2(self): resp = self.client.post('/api/v2/project/', body) self.assertEqual(resp.status_code, 400, resp.content) - self.assertEqual(len(Project.objects.all()), 3) # we created 3 projects until now here + self.assertEqual(len(Project.objects.all()), 4) # we created 4 projects until now here def test_get_projects(self): self.authenticate(self.user) resp = self.client.get('/api/v2/project/', format='json') self.assertEqual(resp.status_code, 200) data = json.loads(resp.content) - self.assertEqual(data['count'], 2) + self.assertEqual(data['count'], 3) self.assertEqual(data['results'][0]['name'], 'aaa') resp_country_filter = self.client.get('/api/v2/project/?country=YY', format='json') self.assertEqual(resp_country_filter.status_code, 200) @@ -143,6 +165,10 @@ def test_get_projects(self): data = json.loads(resp_budget_filter.content) self.assertEqual(data['count'], 1) self.assertEqual(data['results'][0]['name'], 'aaa') + resp_third = self.client.get('/api/v2/project/?country=ZZ', format='json') + data = json.loads(resp_third.content) + self.assertEqual(data['count'], 1) + self.assertEqual(data['results'][0]['annual_split_detail'][0]['year'], 2009) def test_visibility_project_get(self): # Create country for scoping new projects @@ -190,7 +216,7 @@ def test_regional_project_get(self, mock_now): district2 = District.objects.create(name='district2', country=country2) district2a = District.objects.create(name='district2a', country=country2) - mock_now.return_value = datetime.datetime(2011, 11, 11) + mock_now.return_value = datetime.datetime(2011, 11, 11, tzinfo=pytz.utc) # Create new Projects for i, pdata in enumerate([ ( diff --git a/main/settings.py b/main/settings.py index eee016c10..98fbca79d 100644 --- a/main/settings.py +++ b/main/settings.py @@ -435,7 +435,7 @@ RETRY_STRATEGY = Retry( total=3, status_forcelist=[429, 500, 502, 503, 504], - method_whitelist=["HEAD", "GET", "OPTIONS"] + allowed_methods=["HEAD", "GET", "OPTIONS"] ) MOLNIX_API_BASE = env('MOLNIX_API_BASE')