Ejemplo n.º 1
0
    def test_user_cannot_delete_organization(self):
        self.client.force_authenticate(self.user)
        organization = OrganizationFactory()

        response = self.client.delete(
            OrganizationFactory.get_url(organization))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 2
0
    def test_staff_can_delete_organization(self):
        self.client.force_authenticate(self.staff_user)
        organization = OrganizationFactory()

        response = self.client.delete(
            OrganizationFactory.get_url(organization))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Ejemplo n.º 3
0
 def test_user_can_create_organization_user(self):
     organization = OrganizationFactory()
     self.client.force_authenticate(self.user)
     data = {
         'user': structure_factories.UserFactory.get_url(self.user),
         'organization': OrganizationFactory.get_url(organization)
     }
     response = self.client.post(OrganizationUserFactory.get_list_url(),
                                 data)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Ejemplo n.º 4
0
    def test_after_removing_organization_customer_still_exist(self):
        self.client.force_authenticate(self.staff_user)
        organization = OrganizationFactory()

        response = self.client.delete(
            OrganizationFactory.get_url(organization))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        customer = structure_models.Customer.objects.filter(
            uuid=organization.customer.uuid)
        self.assertTrue(customer.exists())
Ejemplo n.º 5
0
    def test_staff_user_can_update_organization(self):
        self.client.force_authenticate(self.staff_user)
        organization = OrganizationFactory()
        data = {
            'abbreviation': 'test',
            'native_name': 'Test organization',
            'name': 'Organization2',
            'customer': None
        }

        response = self.client.put(OrganizationFactory.get_url(organization),
                                   data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 6
0
    def test_customer_owner_can_delete_his_customer_organization_user(self):
        organization = OrganizationFactory(customer=self.customer)
        organization_user = OrganizationUserFactory(organization=organization)
        self.client.force_authenticate(self.customer_owner)

        response = self.client.delete(
            OrganizationUserFactory.get_url(organization_user))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Ejemplo n.º 7
0
    def test_customer_owner_can_access_his_customer_organization_users(self):
        organization = OrganizationFactory(customer=self.customer)
        organization_user = OrganizationUserFactory(organization=organization)

        self.client.force_authenticate(self.customer_owner)
        response = self.client.get(
            OrganizationUserFactory.get_url(organization_user))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 8
0
    def test_user_cannot_create_organization(self):
        self.client.force_authenticate(self.user)
        data = {
            'abbreviation': 'test',
            'native_name': 'Test organization',
            'name': 'Organization'
        }

        response = self.client.post(OrganizationFactory.get_list_url(), data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 9
0
    def test_customer_owner_can_approve_his_customer_organization_user(self):
        self.client.force_authenticate(self.customer_owner)
        organization = OrganizationFactory(customer=self.customer)
        organization_user = OrganizationUserFactory(organization=organization)

        response = self.client.post(
            OrganizationUserFactory.get_url(organization_user,
                                            action='approve'))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        organization_user = models.OrganizationUser.objects.get(
            uuid=organization_user.uuid)
        self.assertTrue(organization_user.is_approved)
Ejemplo n.º 10
0
    def test_user_can_access_organization(self):
        organization = OrganizationFactory()
        self.client.force_authenticate(self.user)

        response = self.client.get(OrganizationFactory.get_url(organization))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 11
0
 def test_authenticated_user_can_list_organizations(self):
     self.client.force_authenticate(self.user)
     response = self.client.get(OrganizationFactory.get_list_url())
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 12
0
 def test_anonymous_user_cannot_list_organizations(self):
     response = self.client.get(OrganizationFactory.get_list_url())
     self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)