예제 #1
0
 def test_intervention(self):
     code_prc = "partners_intervention_prc_review"
     file_type_prc = AttachmentFileTypeFactory(code=code_prc)
     code_pd = "partners_intervention_signed_pd"
     file_type_pd = AttachmentFileTypeFactory(code=code_pd)
     AttachmentFactory(
         file_type=file_type_prc,
         code=code_prc,
         file="sample1.pdf",
         content_object=self.intervention,
         uploaded_by=self.user
     )
     AttachmentFactory(
         file_type=file_type_pd,
         code=code_pd,
         file="sample1.pdf",
         content_object=self.intervention,
         uploaded_by=self.user
     )
     response = self.forced_auth_req(
         "get",
         self.url,
         user=self.unicef_staff,
     )
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data), 4)
     self.assert_keys(response)
     self.assert_values(response, self.default_partner_response + [{
         "partner": self.partner.name,
         "partner_type": self.partner.partner_type,
         "vendor_number": self.partner.vendor_number,
         "pd_ssfa_number": self.intervention.number,
     }, {
         "partner": self.partner.name,
         "partner_type": self.partner.partner_type,
         "vendor_number": self.partner.vendor_number,
         "pd_ssfa_number": self.intervention.number,
     }])
예제 #2
0
 def test_get_no_file(self):
     attachment = AttachmentFactory(
         file_type=self.file_type_1,
         code=self.code_1,
         content_object=self.file_type_1
     )
     self.assertFalse(attachment.file)
     response = self.forced_auth_req(
         "get",
         self.url,
         user=self.unicef_staff,
     )
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data), 2)
     self.assert_keys(response)
예제 #3
0
 def test_no_url(self):
     attachment = AttachmentFactory(
         file_type=self.file_type,
         code=self.code,
         file=None,
         content_object=self.file_type,
         uploaded_by=self.unicef_staff
     )
     response = self.forced_auth_req(
         "get",
         reverse("attachments:file", args=[attachment.pk]),
         user=self.unicef_staff,
     )
     self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
     self.assertIn("Attachment has no file or hyperlink", response.content)
예제 #4
0
 def test_get_hyperlink(self):
     attachment = AttachmentFactory(
         file_type=self.file_type_1,
         code=self.code_1,
         hyperlink="https://example.com/sample.pdf",
         content_object=self.file_type_1
     )
     self.assertTrue(attachment.hyperlink)
     response = self.forced_auth_req(
         "get",
         self.url,
         user=self.unicef_staff,
     )
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data), 3)
     self.assert_keys(response)
예제 #5
0
 def test_agreement_amendment(self):
     code = "partners_agreement_amendment"
     file_type = AttachmentFileTypeFactory(code=code)
     AttachmentFactory(
         file_type=file_type,
         code=code,
         file="sample1.pdf",
         content_object=self.amendment,
         uploaded_by=self.user
     )
     response = self.forced_auth_req(
         "get",
         self.url,
         user=self.unicef_staff,
     )
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data), 3)
     self.assert_keys(response)
     self.assert_values(response, self.default_partner_response + [{
         "partner": self.partner.name,
         "partner_type": self.partner.partner_type,
         "vendor_number": self.partner.vendor_number,
         "pd_ssfa_number": "",
     }])
예제 #6
0
    def attachments(self, create, extracted, count, **kwargs):
        if not create:
            return

        for i in range(count):
            AttachmentFactory(code='activity_attachments', content_object=self)
예제 #7
0
    def report_attachments(self, create, extracted, count, **kwargs):
        if not create:
            return

        for i in range(count):
            AttachmentFactory(code='visit_report', content_object=self, **kwargs)
예제 #8
0
 def test_invalid(self):
     invalid_attachment = AttachmentFactory(
         content_object=self.simple_object)
     with self.assertRaises(ValidationError):
         invalid_attachment.clean()
예제 #9
0
 def test_filename_hyperlink(self):
     instance = AttachmentFactory(
         hyperlink="http://example.com/test_file.txt",
         content_object=self.simple_object)
     self.assertEqual(instance.filename, "test_file.txt")
예제 #10
0
 def test_filename(self):
     instance = AttachmentFactory(file="test.pdf",
                                  content_object=self.simple_object)
     self.assertEqual(instance.filename, "test.pdf")