def test_create_objectcontactmoment_fail_no_remote_relation(self, *mocks): contactmoment = ContactMomentFactory.create() contactmoment_url = reverse(contactmoment) list_url = reverse(ObjectContactMoment) data = { "contactmoment": contactmoment_url, "objectType": ObjectTypes.zaak, "object": ZAAK, } responses = {"http://example.com/api/v1/zaakcontactmomenten": []} with mock_client(responses): response = self.client.post(list_url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "inconsistent-relation")
def test_read_contactmoment_with_medewerker(self): contactmoment = ContactMomentFactory.create( registratiedatum=make_aware(datetime(2019, 1, 1)), initiatiefnemer=InitiatiefNemer.gemeente, medewerker="", voorkeurstaal="nld", ) medewerker = MedewerkerFactory.create(contactmoment=contactmoment) detail_url = reverse(contactmoment) response = self.client.get(detail_url) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() self.assertEqual( data, { "url": f"http://testserver{detail_url}", "vorigContactmoment": None, "volgendContactmoment": None, "bronorganisatie": contactmoment.bronorganisatie, "registratiedatum": "2019-01-01T00:00:00Z", "kanaal": contactmoment.kanaal, "voorkeurskanaal": contactmoment.voorkeurskanaal, "voorkeurstaal": contactmoment.voorkeurstaal, "tekst": contactmoment.tekst, "onderwerpLinks": [], "initiatiefnemer": InitiatiefNemer.gemeente, "medewerker": "", "medewerkerIdentificatie": { "identificatie": medewerker.identificatie, "achternaam": medewerker.achternaam, "voorletters": medewerker.voorletters, "voorvoegselAchternaam": medewerker.voorvoegsel_achternaam, }, }, )
def test_read_objectcontactmoment(self): contactmoment = ContactMomentFactory.create() contactmoment_url = reverse(contactmoment) objectcontactmoment = ObjectContactMomentFactory.create( contactmoment=contactmoment) detail_url = reverse(objectcontactmoment) response = self.client.get(detail_url) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() self.assertEqual( data, { "url": f"http://testserver{detail_url}", "contactmoment": f"http://testserver{contactmoment_url}", "objectType": objectcontactmoment.object_type, "object": objectcontactmoment.object, }, )
def test_create_contactmoment_vorig_contactmoment(self): vorig_cmc = ContactMomentFactory.create() list_url = reverse(ContactMoment) data = { "bronorganisatie": "423182687", "kanaal": "telephone", "tekst": "some text", "onderwerpLinks": [], "initiatiefnemer": InitiatiefNemer.gemeente, "medewerker": "http://example.com/medewerker/1", "vorigContactmoment": reverse(vorig_cmc), } response = self.client.post(list_url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) contactmoment = ContactMoment.objects.last() self.assertEqual(contactmoment.kanaal, "telephone") self.assertEqual(contactmoment.tekst, "some text") self.assertEqual(contactmoment.initiatiefnemer, InitiatiefNemer.gemeente) self.assertEqual(contactmoment.medewerker, "http://example.com/medewerker/1") self.assertEqual(contactmoment.vorig_contactmoment, vorig_cmc) # Check if volgendContactmoment is set correctly response = self.client.get(reverse(vorig_cmc)) self.assertEqual( response.data["volgend_contactmoment"], f"http://testserver{reverse(contactmoment)}", ) vorig_cmc.refresh_from_db() self.assertEqual(vorig_cmc.volgend_contactmoment, contactmoment)
def test_create_klantcontactmoment_klant_url_invalid(self): cmc = ContactMomentFactory.create( registratiedatum=make_aware(datetime(2019, 1, 1)), initiatiefnemer=InitiatiefNemer.gemeente, ) cmc_url = reverse(cmc) list_url = reverse(KlantContactMoment) data = { "klant": "http://testserver.com/klant/1", "contactmoment": f"http://testserver{cmc_url}", "rol": Rol.gesprekspartner, } with requests_mock.Mocker() as m: m.get("http://testserver.com/klant/1", status_code=404) response = self.client.post(list_url, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(KlantContactMoment.objects.count(), 0) error = get_validation_errors(response, "klant") self.assertEqual(error["code"], "bad-url")