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)
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_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_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.')
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)
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')
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 setUp(self): self.phone_match = '9876543210' self.person_list = PersonFactory.create_batch(11) self.user = SuperUserFactory.create() self.client.force_authenticate(user=self.user) self.interceptee_list = IntercepteeNoPhotoFactory.create_batch(3) self.pb_list = PersonBoxFactory.create_batch(2) self.irf_list = IrfFactory.create_batch(2) self.vif_list = VifFactory.create_batch(2) self.alias_list = AliasGroupFactory.create_batch(1) self.interceptee_list[0].person = self.person_list[0] self.pb_list[0].person = self.person_list[0] self.pb_list[1].person = self.person_list[0] self.interceptee_list[1].person = self.person_list[1] self.vif_list[0].victim = self.person_list[2] self.interceptee_list[2].person = self.person_list[3] self.vif_list[1].victim = self.person_list[4] self.person_list[3].alias_group = self.alias_list[0] self.person_list[4].alias_group = self.alias_list[0] self.person_list[3].phone_contact = self.phone_match + '01' self.person_list[4].phone_contact = self.phone_match + '02' self.person_list[3].full_name = "Raymond Smith" self.person_list[4].full_name = "Raymond Smythe" self.interceptee_list[0].interception_record = self.irf_list[0] self.interceptee_list[1].interception_record = self.irf_list[1] self.interceptee_list[2].interception_record = self.irf_list[1] self.pb_list[0].victim_interview = self.vif_list[0] self.pb_list[1].victim_interview = self.vif_list[1] for idx in range(0,3): self.interceptee_list[idx].save() for idx in range(0,2): self.pb_list[idx].save() for idx in range(0,2): self.vif_list[idx].save() for idx in range(0,5): self.person_list[idx].save()
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)
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)
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()
def setUp(self): self.vif_list = VifFactory.create_batch(20) self.user = SuperUserFactory.create() self.client.force_authenticate(user=self.user)