Skip to content

Commit

Permalink
Merge branch 'develop' into feature/cluster_api
Browse files Browse the repository at this point in the history
  • Loading branch information
robertavram authored Oct 25, 2018
2 parents 492df54 + ffaa6a2 commit d7225c5
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 147 deletions.
1 change: 1 addition & 0 deletions src/etools/applications/attachments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def assert_keys(self, response):
"object_link",
"filename",
"file_type",
"file_type_id",
"file_link",
"uploaded_by",
"created",
Expand Down
12 changes: 0 additions & 12 deletions src/etools/applications/audit/purchase_order/synchronizers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

from collections import OrderedDict

from etools.applications.audit.purchase_order.models import AuditorFirm, PurchaseOrder, PurchaseOrderItem
from etools.applications.funds.models import Donor, Grant
from etools.applications.vision.synchronizers import ManualVisionSynchronizer


Expand Down Expand Up @@ -34,18 +32,8 @@ class POSynchronizer(ManualVisionSynchronizer):
"name": "VENDOR_NAME",
"country": "VENDOR_CTRY_NAME",
},
'grant': {
"name": "GRANT_REF",
"expiry": "EXPIRY_DATE",
"donor": "DONOR_NAME"
},
'donor': {
"name": "DONOR_NAME",
}
}
MODEL_MAPPING = OrderedDict((
('donor', Donor),
('grant', Grant),
('auditor_firm', AuditorFirm),
('purchase_order', PurchaseOrder),
('order_item', PurchaseOrderItem),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from etools.applications.audit.purchase_order.models import AuditorFirm, PurchaseOrder, PurchaseOrderItem
from etools.applications.audit.purchase_order.tasks import update_purchase_orders
from etools.applications.EquiTrack.tests.cases import BaseTenantTestCase
from etools.applications.funds.models import Donor, Grant
from etools.applications.users.models import Country


Expand Down Expand Up @@ -65,21 +64,15 @@ def test_save_records(self):
number=self.data["PO_ITEM"]
)
auditor_qs = AuditorFirm.objects.filter(name=self.data["VENDOR_NAME"])
donor_qs = Donor.objects.filter(name=self.data["DONOR_NAME"])
grant_qs = Grant.objects.filter(name=self.data["GRANT_REF"])
self.assertFalse(purchase_order_qs.exists())
self.assertFalse(purchase_order_item_qs.exists())
self.assertFalse(auditor_qs.exists())
self.assertFalse(donor_qs.exists())
self.assertFalse(grant_qs.exists())

self.adapter._save_records([self.data])

self.assertTrue(purchase_order_qs.exists())
self.assertTrue(purchase_order_item_qs.exists())
self.assertTrue(auditor_qs.exists())
self.assertTrue(donor_qs.exists())
self.assertTrue(grant_qs.exists())


class TestUpdatePurchaseOrders(BaseTenantTestCase):
Expand Down
24 changes: 16 additions & 8 deletions src/etools/applications/partners/serializers/prp_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,13 @@ class PRPInterventionListSerializer(serializers.ModelSerializer):
unicef_budget_cash = serializers.DecimalField(source='total_unicef_cash', read_only=True,
max_digits=20, decimal_places=2)
unicef_budget_currency = serializers.SerializerMethodField(read_only=True)
# TODO: update this after FR Validation changes, pending new Insight API changes.

expected_results = PRPResultSerializer(many=True, read_only=True, source='all_lower_results')
expected_results = serializers.SerializerMethodField()
update_date = serializers.DateTimeField(source='modified')
reporting_requirements = ReportingRequirementsSerializer(many=True, read_only=True)
reporting_requirements = serializers.SerializerMethodField()
special_reports = SpecialReportingRequirementsSerializer(source="special_reporting_requirements",
many=True, read_only=True)
sections = SectionSerializer(source="combined_sections", many=True, read_only=True)
sections = SectionSerializer(many=True, read_only=True)
locations = PRPLocationSerializer(source="flat_locations", many=True, read_only=True)

def get_unicef_budget_currency(self, obj):
Expand All @@ -255,14 +254,23 @@ def get_unicef_budget_currency(self, obj):
def get_business_area_code(self, obj):
return connection.tenant.business_area_code

def get_funds_received(self, obj):
return obj.total_frs['total_actual_amt']
def get_reporting_requirements(self, obj):
if obj.status not in [Intervention.ACTIVE, ]:
return []
return ReportingRequirementsSerializer(obj.reporting_requirements, many=True).data

def get_expected_results(self, obj):
if obj.status not in [Intervention.ACTIVE, ]:
return []
return PRPResultSerializer(obj.all_lower_results, many=True).data

class Meta:
model = Intervention
fields = (
'id', 'title', 'business_area_code',
'offices', # todo: convert to names, not ids
'id',
'title',
'business_area_code',
'offices',
'number',
'status',
'partner_org',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,103 +89,5 @@
"id": 642,
"cso_budget": "0.00",
"update_date": "2017-10-12T08:10:43.708677Z"
},
{
"expected_results": [],
"unicef_focal_points": [],
"end_date": null,
"reporting_requirements": [],
"sections": [],
"agreement": "PCA20172036",
"agreement_auth_officers": [],
"amendments": [],
"business_area_code": "ZZZ",
"title": "Intervention 2",
"unicef_budget": "0.00",
"unicef_budget_cash": "0.00",
"unicef_budget_supplies": "0.00",
"unicef_budget_currency": "",
"number": "/PCA2017393/PD2017641",
"start_date": null,
"focal_points": [],
"locations": [],
"offices": [],
"partner_org": {
"id": 0,
"address": null,
"partner_type": "",
"cso_type": null,
"total_ct_cp": null,
"total_ct_cy": null,
"short_name": "",
"alternate_name": null,
"basis_for_risk_rating": "",
"city": null,
"core_values_assessment_date": null,
"country": null,
"email": null,
"last_assessment_date": null,
"name": "Partner 1",
"phone_number": null,
"postal_code": null,
"rating": null,
"street_address": null,
"type_of_assessment": null
},
"special_reports": [],
"status": "draft",
"cso_budget_currency": "",
"id": 641,
"cso_budget": "0.00",
"update_date": "2017-10-12T08:10:43.708677Z"
},
{
"expected_results": [],
"unicef_focal_points": [],
"end_date": null,
"reporting_requirements": [],
"sections": [],
"agreement": "PCA20172036",
"agreement_auth_officers": [],
"amendments": [],
"business_area_code": "ZZZ",
"title": "Intervention 1",
"unicef_budget": "110.00",
"unicef_budget_cash": "100.00",
"unicef_budget_supplies": "10.00",
"unicef_budget_currency": "",
"number": "/PCA2017393/2017640",
"start_date": null,
"focal_points": [],
"locations": [],
"offices": [],
"partner_org": {
"id": 0,
"address": null,
"partner_type": "",
"cso_type": null,
"total_ct_cp": null,
"total_ct_cy": null,
"short_name": "",
"alternate_name": null,
"basis_for_risk_rating": "",
"city": null,
"core_values_assessment_date": null,
"country": null,
"email": null,
"last_assessment_date": null,
"name": "Partner 1",
"phone_number": null,
"postal_code": null,
"rating": null,
"street_address": null,
"type_of_assessment": null
},
"special_reports": [],
"status": "draft",
"cso_budget_currency": "",
"id": 640,
"cso_budget": "200.00",
"update_date": "2017-10-12T08:10:43.708677Z"
}
]
6 changes: 3 additions & 3 deletions src/etools/applications/partners/tests/test_api_prp.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def test_prp_api_modified_queries(self):
tomorrow = (timezone.now() + datetime.timedelta(days=1)).isoformat()
checks = [
({'updated_before': yesterday}, 0),
({'updated_before': tomorrow}, 3),
({'updated_after': yesterday}, 3),
({'updated_before': tomorrow}, 1),
({'updated_after': yesterday}, 1),
({'updated_after': tomorrow}, 0),
({'updated_before': tomorrow, 'updated_after': yesterday}, 3),
({'updated_before': tomorrow, 'updated_after': yesterday}, 1),
]
for params, expected_results in checks:
status_code, response = self.run_prp_v1(
Expand Down
8 changes: 5 additions & 3 deletions src/etools/applications/partners/views/prp_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ def get_queryset(self, format=None):
'result_links__ll_results',
'result_links__ll_results__applied_indicators__indicator',
'result_links__ll_results__applied_indicators__disaggregation__disaggregation_values',
'result_links__ll_results__applied_indicators__locations__gateway',
'result_links__ll_results__applied_indicators__locations',
'special_reporting_requirements',
'reporting_requirements',
'frs',
'partner_focal_points',
'unicef_focal_points',
'agreement__authorized_officers',
'agreement__partner',
'amendments',
'flat_locations'
)
'flat_locations',
'sections'
).exclude(status=Intervention.DRAFT)

query_params = self.request.query_params
workspace = query_params.get('workspace', None)
Expand Down
19 changes: 17 additions & 2 deletions src/etools/applications/tpm/serializers/attachments.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.utils.translation import ugettext as _

from rest_framework import serializers
from unicef_attachments.fields import FileTypeModelChoiceField
from unicef_attachments.models import FileType
from unicef_attachments.serializers import BaseAttachmentSerializer
from unicef_attachments.models import AttachmentLink, FileType
from unicef_attachments.serializers import AttachmentLinkSerializer, BaseAttachmentSerializer


class TPMPartnerAttachmentsSerializer(BaseAttachmentSerializer):
Expand Down Expand Up @@ -57,3 +58,17 @@ class Meta(BaseAttachmentSerializer.Meta):
def create(self, validated_data):
validated_data['code'] = 'visit_attachments'
return super().create(validated_data)


class TPMActivityAttachmentLinkSerializer(serializers.Serializer):
attachments = AttachmentLinkSerializer(many=True, allow_empty=False)

def create(self, validated_data):
links = []
for attachment in validated_data["attachments"]:
links.append(AttachmentLink.objects.create(
attachment=attachment["attachment"],
content_type=self.context["content_type"],
object_id=self.context["object_id"],
))
return {"attachments": links}
45 changes: 40 additions & 5 deletions src/etools/applications/tpm/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

from datetime import datetime

from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from factory import fuzzy

from factory import fuzzy
from rest_framework import status
from unicef_attachments.models import AttachmentLink

from etools.applications.action_points.tests.factories import ActionPointFactory
from etools.applications.attachments.tests.factories import AttachmentFileTypeFactory, AttachmentFactory
from etools.applications.attachments.tests.factories import AttachmentFactory, AttachmentFileTypeFactory
from etools.applications.EquiTrack.tests.cases import BaseTenantTestCase
from etools.applications.partners.models import PartnerType
from etools.applications.reports.tests.factories import SectionFactory
from etools.applications.tpm.models import TPMVisit, ThirdPartyMonitor
from etools.applications.tpm.models import ThirdPartyMonitor, TPMVisit
from etools.applications.tpm.tests.base import TPMTestCaseMixin
from etools.applications.tpm.tests.factories import TPMPartnerFactory, TPMVisitFactory, UserFactory, _FUZZY_END_DATE
from etools.applications.tpm.tests.factories import _FUZZY_END_DATE, TPMPartnerFactory, TPMVisitFactory, UserFactory
from etools.applications.utils.common.tests.test_utils import TestExportMixin


Expand Down Expand Up @@ -761,3 +761,38 @@ def test_add(self):
)
self.assertEqual(list_response.status_code, status.HTTP_200_OK)
self.assertEqual(len(list_response.data['results']), attachments_num + 1)


class TestActivityAttachmentLinkView(TPMTestCaseMixin, BaseTenantTestCase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()

cls.visit = TPMVisitFactory(
status='draft',
tpm_partner=cls.tpm_user.tpmpartners_tpmpartnerstaffmember.tpm_partner,
tpm_partner_focal_points=[cls.tpm_user.tpmpartners_tpmpartnerstaffmember],
tpm_activities__count=1
)
cls.activity = cls.visit.tpm_activities.first()
partner = TPMPartnerFactory()
cls.attachment = AttachmentFactory(content_object=partner)

def test_add(self):
links_qs = AttachmentLink.objects
self.assertEqual(links_qs.count(), 0)
create_response = self.forced_auth_req(
'post',
reverse('tpm:activity-links', args=[self.activity.pk]),
user=self.pme_user,
data={'attachments': [{'attachment': self.attachment.pk}]}
)
self.assertEqual(create_response.status_code, status.HTTP_201_CREATED)

list_response = self.forced_auth_req(
'get',
reverse('tpm:activity-links', args=[self.activity.pk]),
user=self.pme_user
)
self.assertEqual(list_response.status_code, status.HTTP_200_OK)
self.assertEqual(links_qs.count(), 1)
7 changes: 6 additions & 1 deletion src/etools/applications/tpm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unicef_restlib.routers import NestedComplexRouter

from etools.applications.tpm.views import (
ActivityAttachmentLinksView,
ActivityAttachmentsViewSet,
ActivityReportAttachmentsViewSet,
PartnerAttachmentsViewSet,
Expand Down Expand Up @@ -36,7 +37,6 @@
base_name='activity-attachments')
visit_attachments_api.register('activities/report-attachments', ActivityReportAttachmentsViewSet,
base_name='activity-report-attachments')

tpm_action_points_api = NestedComplexRouter(tpm_visits_api, r'visits', lookup='tpm_activity__tpm_visit')
tpm_action_points_api.register(r'action-points', TPMActionPointViewSet, base_name='action-points')

Expand All @@ -49,4 +49,9 @@
url(r'^', include(tpm_action_points_api.urls)),
url(r'^', include(visit_attachments_api.urls)),
url(r'^', include(tpm_visits_api.urls)),
url(
r'^visits/activities/(?P<object_pk>\d+)/links',
view=ActivityAttachmentLinksView.as_view(),
name='activity-links'
)
]
Loading

0 comments on commit d7225c5

Please sign in to comment.