Esempio n. 1
0
    def setUpTestData(cls):
        call_command('update_tpm_permissions', verbosity=0)
        call_command('update_notifications')

        # clearing groups cache
        GroupWrapper.invalidate_instances()

        cls.pme_user = PMEUserFactory()
        cls.unicef_user = UserFactory()

        cls.tpm_partner = TPMPartnerFactory()
        cls.tpm_user = TPMUserFactory(tpm_partner=cls.tpm_partner)
Esempio n. 2
0
    def test_list(self):
        partner = TPMPartnerFactory()
        attachments_num = partner.attachments.count()

        AttachmentFactory(content_object=partner)

        response = self.forced_auth_req('get',
                                        reverse('tpm:partner-attachments-list',
                                                args=[partner.id]),
                                        user=self.pme_user)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['results']), attachments_num + 1)
Esempio n. 3
0
    def _test_partner(self, expected_status=status.HTTP_201_CREATED, **kwargs):
        partner = TPMPartnerFactory(**kwargs)

        response = self.forced_auth_req(
            'post',
            reverse('tpm:visits-list'),
            user=self.pme_user,
            data={'tpm_partner': partner.id},
        )
        self.assertEqual(response.status_code, expected_status)

        if expected_status == status.HTTP_400_BAD_REQUEST:
            self.assertIn('tpm_partner', response.data)
Esempio n. 4
0
    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)
Esempio n. 5
0
    def test_add(self):
        partner = TPMPartnerFactory()

        response = self.forced_auth_req(
            'post',
            reverse('tpm:partner-attachments-list', args=[partner.id]),
            user=self.pme_user,
            request_format='multipart',
            data={
                'file_type':
                AttachmentFileTypeFactory(code='tpm_partner').id,
                'file':
                SimpleUploadedFile('hello_world.txt',
                                   u'hello world!'.encode('utf-8')),
            })
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Esempio n. 6
0
    def test_activation(self):
        partner = TPMPartnerFactory(countries=[])
        # partner is deactivated yet, so wouldn't appear in list
        self._test_list_view(self.pme_user,
                             [self.tpm_partner, self.second_tpm_partner])

        activate_response = self.forced_auth_req('post',
                                                 reverse(
                                                     'tpm:partners-activate',
                                                     args=(partner.id, )),
                                                 user=self.pme_user)
        self.assertEqual(activate_response.status_code, status.HTTP_200_OK)

        self._test_list_view(
            self.pme_user,
            [self.tpm_partner, self.second_tpm_partner, partner])
Esempio n. 7
0
    def test_not_editable_by_tpm(self):
        partner = TPMPartnerFactory()

        response = self.forced_auth_req(
            'post',
            reverse('tpm:partner-attachments-list', args=[partner.id]),
            user=TPMUserFactory(tpm_partner=partner),
            request_format='multipart',
            data={
                'file_type':
                AttachmentFileTypeFactory(code='tpm_partner').id,
                'file':
                SimpleUploadedFile('hello_world.txt',
                                   'hello world!'.encode('utf-8')),
            })
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Esempio n. 8
0
 def setUpTestData(cls):
     super(TestTPMPartnerViewSet, cls).setUpTestData()
     cls.second_tpm_partner = TPMPartnerFactory()
Esempio n. 9
0
 def setUpTestData(cls):
     cls.firm = TPMPartnerFactory()
     call_command('update_notifications')
Esempio n. 10
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.second_tpm_partner = TPMPartnerFactory()