def test_when_user_not_authenticated_should_deny_access(self):
        vif_to_put = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_put.id])

        response = self.client.put(url)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
Exemple #2
0
    def test_vifexists_allows_optional_letters_after_the_number(self):
        vif_number = "BHD123BA"
        vif = VifFactory.create(vif_number="BHD123BA")
        url = reverse('VifExists', args=[vif_number])

        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, vif_number)
    def test_when_user_not_authenticated_should_deny_access(self):
        vif_to_get = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_get.id])

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
        self.assertEqual(response.data['detail'],
                         'Authentication credentials were not provided.')
    def test_when_user_authenticated_and_has_permission_should_allow_access(
            self):
        user = ViewUserFactory.create()
        vif_to_get = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_get.id])
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
    def test_when_user_authenticated_and_does_not_have_permission_should_deny_access(
            self):
        user = NoPermissionUserFactory.create()
        vif_to_get = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_get.id])
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
    def test_when_user_authenticated_and_has_permission_should_delete_vif(
            self):
        user = SuperUserFactory.create()
        vif_to_delete = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_delete.id])
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
    def test_when_user_authenticated_and_has_permission_should_update_vif(
            self):
        user = SuperUserFactory.create()
        vif_to_put = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_put.id])
        self.login(user)

        new_irf = self.get_updated_vif(vif_to_put, "Fred")

        response = self.client.put(url, new_irf)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
    def test_when_user_authenticated_and_does_not_have_permission_should_deny_access(
            self):
        user = ViewUserFactory.create()
        vif_to_delete = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_delete.id])
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(
            response.data['detail'],
            'You do not have the right permission to access this data')
    def test_when_user_authenticated_and_has_permission_and_vif_does_not_exist_should_return_error(
            self):
        user = SuperUserFactory.create()
        vif_to_put = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[2342534])
        self.login(user)

        new_irf = self.get_updated_vif(vif_to_put, "Fred")

        response = self.client.put(url, new_irf)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(response.data['detail'], 'Not found.')
Exemple #10
0
    def test_address_related_items_swap(self):
        address2 = Address2Factory.create(canonical_name=Address2Factory.create())
        related_address2 = Address2Factory.create()
        related_address2.canonical_name = address2
        related_address2.save()

        person = PersonFactory.create(address2=address2)
        vif = VifFactory.create(victim_guardian_address2=address2)
        viflb = VictimInterviewLocationBoxFactory.create(address2=address2)

        url = reverse('Address2RelatedItemsSwap', args=[address2.id, related_address2.id])
        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Exemple #11
0
    def test_remove_address1_with_related_items__should_not_work(self):
        address2 = Address2Factory.create()
        address1 = address2.address1
        person = PersonFactory.create(address1=address1)
        vif = VifFactory.create(victim_guardian_address1=address1)
        url = reverse('Address1detail', args=[address1.id])

        for related_object in [address2, person, vif]:
            response = self.client.delete(url)
            self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
            related_object.delete()

        # All related objects are deleted now, so the Address should be able to be deleted now
        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
    def test_when_user_authenticated_and_does_not_have_permission_should_deny_access(
            self):
        user = NoPermissionUserFactory.create()
        vif_to_put = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_put.id])
        self.login(user)

        new_irf = self.get_updated_vif(vif_to_put, "Fred")

        response = self.client.put(url, new_irf)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(
            response.data['detail'],
            'You do not have the right permission to access this data')
Exemple #13
0
    def test_retrieve_related_items(self):
        address2 = Address2Factory.create()
        address1 = address2.address1
        person = PersonFactory.create(address1=address1)
        vif = VifFactory.create(victim_guardian_address1=address1)

        mapperD = {'person': person, 'victiminterview': vif, 'address2': address2 }

        url = reverse('Address1RelatedItems', args=[address1.id])
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], address1.id)

        related_items = response.data['related_items']
        for item in related_items:
            if item['type'] in mapperD:
                self.assertEqual(True, mapperD[item['type']].id in [obj['id'] for obj in item['objects']])
        self.assertEqual(response.data['id'], address1.id)
Exemple #14
0
    def test_address_related_items_swap(self):
        address2 = Address2Factory.create()
        address1 = address2.address1
        new_address1 = Address1Factory.create()
        person = PersonFactory.create(address1=address1)
        vif = VifFactory.create(victim_guardian_address1=address1)
        viflb = VictimInterviewLocationBoxFactory.create(address1=address1)

        url = reverse('Address1RelatedItemsSwap', args=[address1.id, new_address1.id])
        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(Address2.objects.filter(address1=address1).count(), 0)
        self.assertEqual(Person.objects.filter(address1=address1).count(), 0)
        self.assertEqual(VictimInterview.objects.filter(victim_guardian_address1=address1).count(), 0)
        self.assertEqual(VictimInterviewLocationBox.objects.filter(address1=address1).count(), 0)

        self.assertEqual(Person.objects.filter(address1=new_address1).count(), 1)
        self.assertEqual(Address2.objects.filter(address1=new_address1).count(), 1)
        self.assertEqual(VictimInterview.objects.filter(victim_guardian_address1=new_address1).count(), 1)
        self.assertEqual(VictimInterviewLocationBox.objects.filter(address1=new_address1).count(), 1)
Exemple #15
0
 def setUp(self):
     self.user = SuperUserFactory.create()
     self.intercept = IntercepteeFactory.create(
     )  # This creates an IRF as a SubFactory used in the tests
     self.vif = VifFactory.create()