Ejemplo n.º 1
0
    def test_delete_without_geo_headers(self):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        url = reverse("object-detail", args=[object.uuid])

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Ejemplo n.º 2
0
    def test_get_with_incorrect_get_headers(self):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        url = reverse("object-detail", args=[object.uuid])

        response = self.client.get(url, HTTP_ACCEPT_CRS="EPSG:3857")

        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
Ejemplo n.º 3
0
    def test_filter_registration_date_list(self):
        # object 1 - show
        object1 = ObjectFactory.create(object_type=OBJECT_TYPE)
        record11 = ObjectRecordFactory.create(
            object=object1, registration_at="2020-01-01"
        )
        record12 = ObjectRecordFactory.create(
            object=object1, registration_at="2021-01-01"
        )
        # object 2 - don't show
        record21 = ObjectRecordFactory.create(
            object__object_type=OBJECT_TYPE, registration_at="2021-01-01"
        )

        url = reverse_lazy("object-list")

        response = self.client.get(url, {"registrationDate": "2020-07-01"})

        data = response.json()

        self.assertEqual(len(data), 1)
        self.assertEqual(
            data[0]["url"],
            f"http://testserver{reverse('object-detail', args=[object1.uuid])}",
        )
        self.assertEqual(data[0]["record"]["index"], record11.index)
Ejemplo n.º 4
0
    def test_filter_object_type(self):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        ObjectRecordFactory.create(object=object)
        ObjectFactory.create(object_type=OTHER_OBJECT_TYPE)

        response = self.client.get(self.url, {"type": OBJECT_TYPE})

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

        data = response.json()

        self.assertEqual(len(data), 1)
        self.assertEqual(
            data[0]["url"],
            f"http://testserver{reverse('object-detail', args=[object.uuid])}",
        )
Ejemplo n.º 5
0
    def test_retrieve_object(self, m):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        object_record = ObjectRecordFactory.create(
            object=object,
            start_at=date.today(),
            geometry="POINT (4.910649523925713 52.37240093589432)",
        )
        url = reverse("object-detail", args=[object.uuid])

        response = self.client.get(url)

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

        data = response.json()

        self.assertEqual(
            data,
            {
                "url":
                f'http://testserver{reverse("object-detail", args=[object.uuid])}',
                "type": object.object_type,
                "record": {
                    "index": object_record.index,
                    "typeVersion": object_record.version,
                    "data": object_record.data,
                    "geometry": json.loads(object_record.geometry.json),
                    "startAt": object_record.start_at.isoformat(),
                    "endAt": object_record.end_at,
                    "registrationAt":
                    object_record.registration_at.isoformat(),
                    "correctionFor": None,
                    "correctedBy": None,
                },
            },
        )
Ejemplo n.º 6
0
    def test_history_no_object_permissions(self):
        object = ObjectFactory.create()
        url = reverse("object-history", args=[object.uuid])

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 7
0
    def test_get_with_geo_headers(self):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        url = reverse("object-detail", args=[object.uuid])

        response = self.client.get(url, **GEO_READ_KWARGS)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertResponseHasGeoHeaders(response)
Ejemplo n.º 8
0
    def test_filter_registration_date_detail_no_record(self):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        record = ObjectRecordFactory.create(object=object, registration_at="2021-01-01")

        url = reverse_lazy("object-detail", args=[object.uuid])

        response = self.client.get(url, {"registrationDate": "2020-07-01"})

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Ejemplo n.º 9
0
    def test_destroy_with_read_only_perm(self):
        ObjectPermissionFactory.create(object_type=OBJECT_TYPE,
                                       mode=PermissionModes.read_only,
                                       users=[self.user])
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        url = reverse("object-detail", args=[object.uuid])

        response = self.client.delete(url, **GEO_WRITE_KWARGS)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 10
0
    def test_history_with_read_only_permissions(self):
        ObjectPermissionFactory.create(object_type=OBJECT_TYPE,
                                       mode=PermissionModes.read_only,
                                       users=[self.user])
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        url = reverse("object-history", args=[object.uuid])

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
Ejemplo n.º 11
0
    def test_list_objects_limited_to_object_permission(self):
        ObjectPermissionFactory.create(object_type=OBJECT_TYPE,
                                       mode=PermissionModes.read_only,
                                       users=[self.user])
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        ObjectRecordFactory.create(object=object)
        ObjectFactory.create()
        url = reverse_lazy("object-list")

        response = self.client.get(url)

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

        data = response.json()

        self.assertEqual(len(data), 1)
        self.assertEqual(
            data[0]["url"],
            f"http://testserver{reverse('object-detail', args=[object.uuid])}",
        )
Ejemplo n.º 12
0
    def test_non_auth(self):
        object = ObjectFactory.create()
        urls = [
            reverse("object-list"),
            reverse("object-detail", args=[object.uuid])
        ]

        for url in urls:
            with self.subTest(url=url):
                response = self.client.get(url)
                self.assertEqual(response.status_code,
                                 status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 13
0
    def test_filter_date_detail(self):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        record1 = ObjectRecordFactory.create(
            object=object, start_at="2020-01-01", end_at="2020-12-31"
        )
        record2 = ObjectRecordFactory.create(object=object, start_at="2021-01-01")

        url = reverse_lazy("object-detail", args=[object.uuid])

        response = self.client.get(url, {"date": "2020-07-01"})

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

        data = response.json()

        self.assertEqual(data["record"]["index"], record1.index)
Ejemplo n.º 14
0
    def test_update_without_geo_headers(self):
        object = ObjectFactory.create(object_type=OBJECT_TYPE)
        url = reverse("object-detail", args=[object.uuid])
        data = {
            "type": OBJECT_TYPE,
            "record": {
                "typeVersion": 1,
                "data": {
                    "diameter": 30
                },
                "startAt": "2020-01-01",
            },
        }

        for method in ("put", "patch"):
            with self.subTest(method=method):
                do_request = getattr(self.client, method)

                response = do_request(url, data)

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