def test_list_objectverzoeken(self):
        list_url = reverse(ObjectVerzoek)
        ObjectVerzoekFactory.create_batch(2)

        response = self.client.get(list_url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        data = response.json()
        self.assertEqual(len(data), 2)
Beispiel #2
0
    def test_pagination_page_param(self):
        ObjectVerzoekFactory.create_batch(2)
        url = reverse(ObjectVerzoek)

        response = self.client.get(url, {"page": 1})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_data = response.json()
        self.assertEqual(response_data["count"], 2)
        self.assertIsNone(response_data["previous"])
        self.assertIsNone(response_data["next"])
    def test_filter_object(self):
        oio = ObjectVerzoekFactory.create()

        response = self.client.get(self.list_url, {"object": oio.object})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["object"], oio.object)
    def test_destroy_objectverzoek(self, *mocks):
        objectverzoek = ObjectVerzoekFactory.create(
            object=ZAAK, object_type=ObjectTypes.zaak)
        detail_url = reverse(objectverzoek)
        responses = {"http://example.com/api/v1/zaakverzoeken": []}

        with mock_client(responses):
            response = self.client.delete(detail_url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(ObjectVerzoek.objects.count(), 0)
    def test_filter_verzoek(self):
        oio = ObjectVerzoekFactory.create()
        verzoek_url = reverse(oio.verzoek)

        response = self.client.get(
            self.list_url,
            {"verzoek": f"http://testserver.com{verzoek_url}"},
            HTTP_HOST="testserver.com",
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["verzoek"],
                         f"http://testserver.com{verzoek_url}"),
    def test_read_objectverzoek(self):
        verzoek = VerzoekFactory.create()
        verzoek_url = reverse(verzoek)
        objectverzoek = ObjectVerzoekFactory.create(verzoek=verzoek)
        detail_url = reverse(objectverzoek)

        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}",
                "verzoek": f"http://testserver{verzoek_url}",
                "objectType": objectverzoek.object_type,
                "object": objectverzoek.object,
            },
        )
    def test_destroy_fail_existing_relation(self, *mocks):
        objectverzoek = ObjectVerzoekFactory.create(
            object=ZAAK, object_type=ObjectTypes.zaak)
        detail_url = reverse(objectverzoek)
        responses = {
            "http://example.com/api/v1/zaakverzoeken": [{
                "url":
                f"https://example.com/api/v1/zaakverzoeken/{uuid.uuid4()}",
                "verzoek":
                f"http://testserver/api/v1/verzoeken/{uuid.uuid4()}",
                "zaak": ZAAK,
            }]
        }

        with mock_client(responses):
            response = self.client.delete(detail_url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        error = get_validation_errors(response, "nonFieldErrors")

        self.assertEqual(error["code"], "remote-relation-exists")