Beispiel #1
0
 def test_export_csv(self):
     HactHistoryFactory(
         partner=self.partner,
         year=2017,
         partner_values=self.hact_data
     )
     response = self.forced_auth_req(
         "get",
         self.url,
         user=self.unicef_user,
         data={"format": "csv"}
     )
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     dataset = Dataset().load(response.content.decode('utf-8'), "csv")
     self.assertEqual(dataset.height, 1)
     self.assertEqual(dataset._get_headers(), [
         "Implementing Partner",
         "Partner Type",
         "Shared",
         "Shared IP",
         "TOTAL for current CP cycle",
         "PLANNED for current year",
         "Current Year (1 Oct - 30 Sep)",
         "Micro Assessment",
         "Risk Rating",
         "Expiring Threshold",
         "Approach Threshold",
         "Programmatic Visits Planned",
         "Programmatic Visits M.R",
         "Programmatic Visits Done",
         "Spot Checks M.R",
         "Spot Checks Done",
         "Audits M.R",
         "Audits Done",
         "Flag for Follow up",
     ])
     self.assertEqual(dataset[0], (
         "Partner Name",
         PartnerType.UN_AGENCY,
         "with UNFPA",
         PartnerOrganization.AGENCY_CHOICES.UN,
         "200.00",
         "300.00",
         "150.00",
         "Yes",
         "High",
         "False",
         "False",
         "10",  # programmatic visits
         "8",
         "5",
         "3",  # spot checks
         "2",
         "4",  # audits
         "2",
         "No",
     ))
Beispiel #2
0
 def test_csv_export(self):
     response = self.forced_auth_req(
         'get',
         self.url,
         user=self.unicef_staff,
         data={"format": "csv"}
     )
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
     self.assertEqual(dataset.height, 1)
     self.assertEqual(len(dataset._get_headers()), 33)
     self.assertEqual(len(dataset[0]), 33)
    def test_csv_flat_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-staff-members-list', args=[self.partner.pk]),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 2)
        self.assertEqual(len(dataset._get_headers()), 11)
        self.assertEqual(len(dataset[0]), 11)
Beispiel #4
0
    def test_csv_flat_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('reports:applied-indicator'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(len(dataset._get_headers()), 31)
        self.assertEqual(len(dataset[0]), 31)
Beispiel #5
0
    def test_csv_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-assessment'),
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(len(dataset._get_headers()), 18)
        self.assertEqual(len(dataset[0]), 18)
Beispiel #6
0
    def test_csv_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('funds:funds-reservation-header'),
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(len(dataset._get_headers()), 19)
        self.assertEqual(len(dataset[0]), 19)
    def test_csv_flat_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:intervention-results'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(len(dataset._get_headers()), 42)
        self.assertEqual(len(dataset[0]), 42)
Beispiel #8
0
    def test_csv_flat_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('funds:funds-reservation-header'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(len(dataset._get_headers()), 20)
        self.assertEqual(len(dataset[0]), 20)
Beispiel #9
0
    def test_agreement_export_api(self):
        response = self.forced_auth_req(
            'get',
            '/api/v2/agreements/',
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 2)
        self.assertEqual(dataset._get_headers(), [
            'Reference Number',
            'Status',
            'Partner Name',
            'Partner Number',
            'Agreement Type',
            'Start Date',
            'End Date',
            'Signed By Partner',
            'Signed By Partner Date',
            'Signed By UNICEF',
            'Signed By UNICEF Date',
            'Partner Authorized Officer',
            'Amendments',
            'URL',
        ])

        # we're interested in the first agreement, so it will be last in the exported list
        exported_agreement = dataset[-1]
        self.assertEqual(exported_agreement, (
            self.agreement.agreement_number,
            str(self.agreement.status),
            str(self.agreement.partner.name),
            str(self.agreement.partner.vendor_number),
            self.agreement.agreement_type,
            '{}'.format(self.agreement.start),
            '{}'.format(self.agreement.end),
            u'',
            '{}'.format(self.agreement.signed_by_partner_date),
            self.unicef_staff.get_full_name(),
            '{}'.format(self.agreement.signed_by_unicef_date),
            ', '.join([
                sm.get_full_name()
                for sm in self.agreement.authorized_officers.all()
            ]),
            u'',
            u'https://testserver/pmp/agreements/{}/details/'.format(
                self.agreement.id),
        ))
Beispiel #10
0
    def test_agreement_export_api(self):
        response = self.forced_auth_req(
            'get',
            '/api/v2/agreements/',
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 2)
        self.assertEqual(dataset._get_headers(), [
            'Reference Number',
            'Status',
            'Partner Name',
            'Partner Number',
            'Agreement Type',
            'Start Date',
            'End Date',
            'Signed By Partner',
            'Signed By Partner Date',
            'Signed By UNICEF',
            'Signed By UNICEF Date',
            'Partner Authorized Officer',
            'Amendments',
            'URL',
            'Special Conditions PCA',
        ])

        # we're interested in the first agreement, so it will be last in the exported list
        exported_agreement = dataset[-1]
        self.assertEqual(exported_agreement, (
            self.agreement.agreement_number,
            str(self.agreement.status),
            str(self.agreement.partner.name),
            str(self.agreement.partner.vendor_number),
            self.agreement.agreement_type,
            '{}'.format(self.agreement.start),
            '{}'.format(self.agreement.end),
            '',
            '{}'.format(self.agreement.signed_by_partner_date),
            self.unicef_staff.get_full_name(),
            '{}'.format(self.agreement.signed_by_unicef_date),
            ', '.join([sm.get_full_name() for sm in self.agreement.authorized_officers.all()]),
            '',
            'https://testserver/pmp/agreements/{}/details/'.format(self.agreement.id),
            'No',
        )
        )
Beispiel #11
0
    def test_csv_flat_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-assessment'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        headers = dataset._get_headers()
        self.assertEqual(len(headers), 15)
        self.assertIn("Country", headers)
        self.assertEqual(len(dataset[0]), 15)
Beispiel #12
0
    def test_partners_export_api(self):
        response = self.forced_auth_req(
            'get',
            '/api/v2/partners/',
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 2)
        self.assertEqual(dataset._get_headers(), [
            'Vendor Number', 'Organizations Full Name', 'Short Name',
            'Alternate Name', 'Partner Type', 'Shared Partner', 'Address',
            'Phone Number', 'Email Address', 'Risk Rating',
            'Date Last Assessed Against Core Values',
            'Actual Cash Transfer for CP (USD)',
            'Actual Cash Transfer for Current Year (USD)',
            'Marked for Deletion', 'Blocked', 'Assessment Type',
            'Date Assessed', 'Assessment Type (Date Assessed)',
            'Staff Members', 'URL'
        ])
        deleted_flag = "Yes" if self.partner.deleted_flag else "No"
        blocked = "Yes" if self.partner.blocked else "No"

        test_option = [
            e for e in dataset if e[0] == self.partner.vendor_number
        ][0]
        self.assertEqual(
            test_option,
            (self.partner.vendor_number, six.text_type(self.partner.name),
             self.partner.short_name, self.partner.alternate_name, "{}".format(
                 self.partner.partner_type), u', '.join([
                     x for x in self.partner.shared_with
                 ]), self.partner.address, self.partner.phone_number,
             self.partner.email, self.partner.rating, u'{}'.format(
                 self.partner.core_values_assessment_date), u'{:.2f}'.format(
                     self.partner.total_ct_cp), u'{:.2f}'.format(
                         self.partner.total_ct_cy), deleted_flag, blocked,
             self.partner.type_of_assessment, u'{}'.format(
                 self.partner.last_assessment_date), u'', ', '.join([
                     "{} ({})".format(sm.get_full_name(), sm.email)
                     for sm in self.partner.staff_members.filter(
                         active=True).all()
                 ]), u'https://testserver/pmp/partners/{}/details/'.format(
                     self.partner.id)))
Beispiel #13
0
    def test_csv_flat_export_api_hact_value_string(self):
        partner = self.partner
        partner.pk = None
        partner.vendor_number = "Vendor New Num"
        partner.hact_values = json.dumps('{"key": "random string"}')
        partner.save()
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-list'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 2)
        self.assertEqual(len(dataset._get_headers()), 49)
        self.assertEqual(len(dataset[0]), 49)
Beispiel #14
0
    def test_csv_flat_export_api_hact_value_string(self):
        partner = self.partner
        partner.pk = None
        partner.vendor_number = "Vendor New Num"
        partner.hact_values = json.dumps('{"key": "random string"}')
        partner.save()
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-list'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 2)
        self.assertEqual(len(dataset._get_headers()), 49)
        self.assertEqual(len(dataset[0]), 49)
Beispiel #15
0
    def test_csv_flat_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('funds:funds-donor'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertCountEqual(dataset._get_headers(), [
            "Grant",
            "ID",
            "Name",
            "created",
            "modified",
        ])
        self.assertEqual(len(dataset[0]), 5)
Beispiel #16
0
    def test_agreement_export_api(self):
        response = self.forced_auth_req(
            'get',
            '/api/partners/{}/agreements/export/'.format(self.partner.id),
            user=self.unicef_staff)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        dataset = Dataset().load(response.content, 'csv')

        self.assertEqual(dataset.height, 1)
        self.assertEqual(dataset._get_headers(), [
            'reference_number', 'partner__vendor_number', 'partner__name',
            'partner__short_name', 'start_date', 'end_date',
            'signed_by_partner', 'signed_by_partner_date', 'signed_by_unicef',
            'signed_by_unicef_date', 'authorized_officers'
        ])
        self.assertEqual(dataset[0],
                         (self.agreement.reference_number, '',
                          self.partner.name, '', '', '', '', '', '', '', ''))
Beispiel #17
0
    def test_csv_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:agreement-list'),
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(dataset._get_headers(), [
            'Reference Number',
            'Status',
            'Partner Name',
            'Agreement Type',
            'Start Date',
            'End Date',
            'Signed By Partner',
            'Signed By Partner Date',
            'Signed By UNICEF',
            'Signed By UNICEF Date',
            'Partner Authorized Officer',
            'Amendments',
            'URL'
        ])

        exported_agreement = dataset[0]
        self.assertEqual(exported_agreement, (
            self.agreement.agreement_number,
            six.text_type(self.agreement.status),
            six.text_type(self.agreement.partner.name),
            self.agreement.agreement_type,
            '{}'.format(self.agreement.start),
            '{}'.format(self.agreement.end),
            u'',
            '{}'.format(self.agreement.signed_by_partner_date),
            u'',
            '{}'.format(self.agreement.signed_by_unicef_date),
            ', '.join([sm.get_full_name() for sm in self.agreement.authorized_officers.all()]),
            u'',
            u'https://testserver/pmp/agreements/{}/details/'.format(self.agreement.id)
        ))
Beispiel #18
0
    def test_csv_flat_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('funds:funds-donor'),
            user=self.unicef_staff,
            data={"format": "csv_flat"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        six.assertCountEqual(self, dataset._get_headers(), [
            "Grant",
            "ID",
            "Name",
            "created",
            "modified",
        ])
        self.assertEqual(len(dataset[0]), 5)
Beispiel #19
0
    def test_government_export_api(self):
        response = self.forced_auth_req(
            'get',
            '/api/partners/{}/government_interventions/export/'.format(
                self.partner.id),
            user=self.unicef_staff)
        self.assertEquals(response.status_code, status.HTTP_200_OK,
                          response.content)

        dataset = Dataset().load(response.content, 'csv')

        self.assertEqual(dataset.height, 1)
        self.assertEqual(dataset._get_headers(), [
            'number', 'partner__name', 'result_structure__name', 'sectors',
            'cash_transfer', 'year'
        ])
        self.assertEqual(dataset[0],
                         ('RefNumber', self.partner.name,
                          self.government_intervention.result_structure.name,
                          '', '0', datetime.now().strftime('%Y')))
Beispiel #20
0
    def test_partner_export_api(self):
        response = self.forced_auth_req('get',
                                        '/api/partners/export/',
                                        user=self.unicef_staff)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        dataset = Dataset().load(response.content, 'csv')

        self.assertEqual(dataset.height, 2)
        self.assertEqual(dataset._get_headers(), [
            'vendor_number', 'vision_synced', 'deleted_flag', 'name',
            'short_name', 'alternate_id', 'alternate_name', 'partner_type',
            'cso_type', 'shared_partner', 'address', 'email', 'phone_number',
            'risk_rating', 'type_of_assessment', 'last_assessment_date',
            'total_ct_cp', 'total_ct_cy', 'agreement_count',
            'intervention_count', 'active_staff_members'
        ])
        self.assertEqual(
            dataset[0],
            ('', '0', '0', self.partner.name, '', '', '', '', '', 'No', '', '',
             '', '', '', '', '', '', '1', '1', 'Mace Windu'))
Beispiel #21
0
    def test_csv_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-list'),
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(dataset._get_headers(), [
            'Vendor Number', 'Organizations Full Name', 'Short Name',
            'Alternate Name', 'Partner Type', 'Shared Partner', 'Address',
            'Phone Number', 'Email Address', 'Risk Rating',
            'Date Last Assessed Against Core Values',
            'Actual Cash Transfer for CP (USD)',
            'Actual Cash Transfer for Current Year (USD)',
            'Marked for Deletion', 'Blocked', 'Assessment Type',
            'Date Assessed', 'Assessment Type (Date Assessed)',
            'Staff Members', 'URL', 'Planned Programmatic Visits'
        ])
        deleted_flag = "Yes" if self.partner.deleted_flag else "No"
        blocked = "Yes" if self.partner.blocked else "No"

        test_option = [
            e for e in dataset if e[0] == self.partner.vendor_number
        ][0]

        # the order of staff members in the results is hard to determine
        # so just ensuring that all relevant staff members are in the results
        for sm in self.partner.staff_members.filter(active=True).all():
            member = "{} ({})".format(sm.get_full_name(), sm.email)
            self.assertIn(member, test_option[18])

        self.assertEqual(test_option, (
            self.partner.vendor_number,
            str(self.partner.name),
            self.partner.short_name,
            self.partner.alternate_name,
            "{}".format(self.partner.partner_type),
            ', '.join([x for x in self.partner.shared_with]),
            self.partner.address,
            self.partner.phone_number,
            self.partner.email,
            self.partner.rating,
            '{}'.format(self.partner.core_values_assessment_date),
            '{:.2f}'.format(self.partner.total_ct_cp),
            '{:.2f}'.format(self.partner.total_ct_ytd),
            deleted_flag,
            blocked,
            self.partner.type_of_assessment,
            '{}'.format(self.partner.last_assessment_date),
            '',
            test_option[18],
            'https://testserver/pmp/partners/{}/details/'.format(
                self.partner.id),
            '{} (Q1:{} Q2:{}, Q3:{}, Q4:{})'.format(
                self.planned_visit.year,
                self.planned_visit.programmatic_q1,
                self.planned_visit.programmatic_q2,
                self.planned_visit.programmatic_q3,
                self.planned_visit.programmatic_q4,
            ),
        ))
Beispiel #22
0
    def test_intervention_export_api(self):
        response = self.forced_auth_req(
            'get',
            '/api/v2/interventions/',
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)

        self.assertEqual(dataset._get_headers(), [
            "Partner",
            "Vendor Number",
            "Status",
            "Partner Type",
            "Agreement",
            "Country Programme",
            "Document Type",
            "Reference Number",
            "Document Title",
            "Start Date",
            "End Date",
            "UNICEF Office",
            "Sections",
            "Locations",
            "Contingency PD",
            "Cluster",
            "UNICEF Focal Points",
            "CSO Authorized Officials",
            "Budget Currency",
            "Total CSO Contribution",
            "UNICEF Cash",
            "UNICEF Supply",
            "Total PD/SSFA Budget",
            "FR Number(s)",
            "FR Currency",
            "FR Posting Date",
            "FR Amount",
            "FR Actual CT",
            "Outstanding DCT",
            "Document Submission Date by CSO",
            "Submission Date to PRC",
            "Review Date by PRC",
            "Signed by Partner",
            "Signed by Partner Date",
            "Signed by UNICEF",
            "Signed by UNICEF Date",
            "Days from Submission to Signed",
            "Days from Review to Signed",
            "Total no. of amendments",
            "Last amendment date",
            "Attachment type",
            "# of attachments",
            "CP Outputs",
            "URL",
        ])

        self.assertEqual(dataset[0], (
            str(self.intervention.agreement.partner.name),
            str(self.intervention.agreement.partner.vendor_number),
            self.intervention.status,
            self.intervention.agreement.partner.partner_type,
            self.intervention.agreement.agreement_number,
            str(self.intervention.country_programme.name),
            self.intervention.document_type,
            self.intervention.number,
            str(self.intervention.title),
            '{}'.format(self.intervention.start),
            '{}'.format(self.intervention.end),
            u'',
            u'',
            u'',
            str("Yes" if self.intervention.contingency_pd else "No"),
            u'',
            u'',
            u'',
            str(self.ib.currency),
            u'{:.2f}'.format(self.intervention.total_partner_contribution),
            u'{:.2f}'.format(self.intervention.total_unicef_cash),
            u'{:.2f}'.format(self.intervention.total_in_kind_amount),
            u'{:.2f}'.format(self.intervention.total_budget),
            u', '.join([fr.fr_numbers for fr in self.intervention.frs.all()]),
            u'',
            u'',
            u'',
            u'',
            u'',
            '{}'.format(self.intervention.submission_date),
            '{}'.format(self.intervention.submission_date_prc),
            '{}'.format(self.intervention.review_date_prc),
            u'{}'.format(self.intervention.
                         partner_authorized_officer_signatory.get_full_name()),
            '{}'.format(self.intervention.signed_by_partner_date),
            self.unicef_staff.get_full_name(),
            '{}'.format(self.intervention.signed_by_unicef_date),
            '{}'.format(self.intervention.days_from_submission_to_signed),
            '{}'.format(self.intervention.days_from_review_to_signed),
            str(self.intervention.amendments.count()),
            u'',
            str(', '.join([
                '{}'.format(att.type.name)
                for att in self.intervention.attachments.all()
            ])),
            str(self.intervention.attachments.count()),
            u'',
            u'https://testserver/pmp/interventions/{}/details/'.format(
                self.intervention.id),
        ))
Beispiel #23
0
    def test_intervention_export_api(self):
        response = self.forced_auth_req(
            'get',
            '/api/v2/interventions/',
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)

        self.assertEqual(dataset._get_headers(), [
            "Partner",
            "Vendor Number",
            "Status",
            "Partner Type",
            "CSO Type",
            "Agreement",
            "Country Programme",
            "Document Type",
            "Reference Number",
            "Document Title",
            "Start Date",
            "End Date",
            "UNICEF Office",
            "Sections",
            "Locations",
            "Contingency PD",
            "Cluster",
            "UNICEF Focal Points",
            "CSO Authorized Officials",
            "Budget Currency",
            "Total CSO Contribution",
            "UNICEF Cash",
            "UNICEF Supply",
            "Total PD/SSFA Budget",
            "FR Number(s)",
            "FR Currency",
            "FR Posting Date",
            "FR Amount",
            "FR Actual CT",
            "Outstanding DCT",
            "Planned Programmatic Visits",
            "Document Submission Date by CSO",
            "Submission Date to PRC",
            "Review Date by PRC",
            "Signed by Partner",
            "Signed by Partner Date",
            "Signed by UNICEF",
            "Signed by UNICEF Date",
            "Days from Submission to Signed",
            "Days from Review to Signed",
            "Total no. of amendments",
            "Last amendment date",
            "Attachment type",
            "# of attachments",
            "CP Outputs",
            "URL",
        ])

        self.assertEqual(dataset[0], (
            str(self.intervention.agreement.partner.name),
            str(self.intervention.agreement.partner.vendor_number),
            self.intervention.status,
            self.intervention.agreement.partner.partner_type,
            '',
            self.intervention.agreement.agreement_number,
            str(self.intervention.country_programme.name),
            self.intervention.document_type,
            self.intervention.number,
            str(self.intervention.title),
            '{}'.format(self.intervention.start),
            '{}'.format(self.intervention.end),
            '',
            '',
            '',
            str("Yes" if self.intervention.contingency_pd else "No"),
            '',
            '',
            '',
            str(self.ib.currency),
            '{:.2f}'.format(self.intervention.total_partner_contribution),
            '{:.2f}'.format(self.intervention.total_unicef_cash),
            '{:.2f}'.format(self.intervention.total_in_kind_amount),
            '{:.2f}'.format(self.intervention.total_budget),
            ', '.join([fr.fr_numbers for fr in self.intervention.frs.all()]),
            '',
            '',
            '',
            '',
            '',
            '{} (Q1:{} Q2:{}, Q3:{}, Q4:{})'.format(self.planned_visit.year,
                                                    self.planned_visit.programmatic_q1,
                                                    self.planned_visit.programmatic_q2,
                                                    self.planned_visit.programmatic_q3,
                                                    self.planned_visit.programmatic_q4),
            '{}'.format(self.intervention.submission_date),
            '{}'.format(self.intervention.submission_date_prc),
            '{}'.format(self.intervention.review_date_prc),
            '{}'.format(self.intervention.partner_authorized_officer_signatory.get_full_name()),
            '{}'.format(self.intervention.signed_by_partner_date),
            self.unicef_staff.get_full_name(),
            '{}'.format(self.intervention.signed_by_unicef_date),
            '{}'.format(self.intervention.days_from_submission_to_signed),
            '{}'.format(self.intervention.days_from_review_to_signed),
            str(self.intervention.amendments.count()),
            '',
            str(', '.join(['{}'.format(att.type.name) for att in self.intervention.attachments.all()])),
            str(self.intervention.attachments.count()),
            '',
            'https://testserver/pmp/interventions/{}/details/'.format(self.intervention.id),
        ))
Beispiel #24
0
    def test_csv_export_api(self):
        response = self.forced_auth_req(
            'get',
            reverse('partners_api:partner-list'),
            user=self.unicef_staff,
            data={"format": "csv"},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        dataset = Dataset().load(response.content.decode('utf-8'), 'csv')
        self.assertEqual(dataset.height, 1)
        self.assertEqual(dataset._get_headers(), [
            'Vendor Number',
            'Organizations Full Name',
            'Short Name',
            'Alternate Name',
            'Partner Type',
            'Shared Partner',
            'Address',
            'Phone Number',
            'Email Address',
            'Risk Rating',
            'Date Last Assessed Against Core Values',
            'Actual Cash Transfer for CP (USD)',
            'Actual Cash Transfer for Current Year (USD)',
            'Marked for Deletion',
            'Blocked',
            'Assessment Type',
            'Date Assessed',
            'Assessment Type (Date Assessed)',
            'Staff Members',
            'URL',
            'Planned Programmatic Visits'
        ])
        deleted_flag = "Yes" if self.partner.deleted_flag else "No"
        blocked = "Yes" if self.partner.blocked else "No"

        test_option = [e for e in dataset if e[0] == self.partner.vendor_number][0]

        # the order of staff members in the results is hard to determine
        # so just ensuring that all relevant staff members are in the results
        for sm in self.partner.staff_members.filter(active=True).all():
            member = "{} ({})".format(sm.get_full_name(), sm.email)
            self.assertIn(member, test_option[18])

        self.assertEqual(test_option, (
            self.partner.vendor_number,
            str(self.partner.name),
            self.partner.short_name,
            self.partner.alternate_name,
            "{}".format(self.partner.partner_type),
            ', '.join([x for x in self.partner.shared_with]),
            self.partner.address,
            self.partner.phone_number,
            self.partner.email,
            self.partner.rating,
            '{}'.format(self.partner.core_values_assessment_date),
            '{:.2f}'.format(self.partner.total_ct_cp),
            '{:.2f}'.format(self.partner.total_ct_ytd),
            deleted_flag,
            blocked,
            self.partner.type_of_assessment,
            '{}'.format(self.partner.last_assessment_date),
            '',
            test_option[18],
            'https://testserver/pmp/partners/{}/details/'.format(self.partner.id),
            '{} (Q1:{} Q2:{}, Q3:{}, Q4:{})'.format(
                self.planned_visit.year,
                self.planned_visit.programmatic_q1,
                self.planned_visit.programmatic_q2,
                self.planned_visit.programmatic_q3,
                self.planned_visit.programmatic_q4,
            ),
        ))