예제 #1
0
    def test_item_deserialization_update_remove_title(self):
        original_sample = self.data_factory.create_item_sample(
            collection=self.collection.model,
            sample='item-1',
        )
        sample = self.data_factory.create_item_sample(
            collection=self.collection.model,
            sample='item-2',
            name=original_sample["name"],
            properties={"datetime": isoformat(utc_aware(datetime.utcnow()))})
        serializer = ItemSerializer(original_sample.model,
                                    data=sample.get_json('deserialize'))
        serializer.is_valid(raise_exception=True)
        item = serializer.save()

        # mock a request needed for the serialization of links
        context = {
            'request':
            api_request_mocker.get(
                f'{STAC_BASE_V}/collections/{self.collection["name"]}/items/{sample["name"]}'
            )
        }
        serializer = ItemSerializer(item, context=context)
        python_native = serializer.data
        self.check_stac_item(sample.json, python_native,
                             self.collection["name"])
        self.assertNotIn('title',
                         python_native['properties'].keys(),
                         msg="Title was not removed")
예제 #2
0
    def test_item_deserialization_update(self):
        original_sample = self.data_factory.create_item_sample(
            collection=self.collection.model,
            sample='item-1',
        )
        sample = self.data_factory.create_item_sample(
            collection=self.collection.model,
            sample='item-2',
            name=original_sample["name"])
        serializer = ItemSerializer(original_sample.model,
                                    data=sample.get_json('deserialize'))
        serializer.is_valid(raise_exception=True)
        item = serializer.save()

        # mock a request needed for the serialization of links
        context = {
            'request':
            api_request_mocker.get(
                f'{STAC_BASE_V}/collections/{self.collection["name"]}/items/{sample["name"]}'
            )
        }
        serializer = ItemSerializer(item, context=context)
        python_native = serializer.data
        self.check_stac_item(sample.json, python_native,
                             self.collection["name"])
        self.assertIsNone(get_link(python_native['links'], 'describedBy'),
                          msg='Link describedBy was not removed in update')
예제 #3
0
    def test_item_deserialization_invalid_link(self):
        sample = self.data_factory.create_item_sample(
            collection=self.collection.model,
            sample='item-invalid-link',
        )

        # translate to Python native:
        serializer = ItemSerializer(data=sample.get_json('deserialize'))
        with self.assertRaises(ValidationError):
            serializer.is_valid(raise_exception=True)
예제 #4
0
    def test_item_deserialization_missing_required(self):
        data = OrderedDict([
            ("collection", self.collection["name"]),
            ("id", "test"),
        ])

        # translate to Python native:
        serializer = ItemSerializer(data=data)
        with self.assertRaises(ValidationError):
            serializer.is_valid(raise_exception=True)
예제 #5
0
    def test_item_deserialization_end_date_before_start_date(self):
        today = datetime.utcnow()
        yesterday = today - timedelta(days=1)
        sample = self.data_factory.create_item_sample(
            collection=self.collection.model,
            sample='item-1',
            properties={
                'start_datetime': isoformat(utc_aware(today)),
                "end_datetime": isoformat(utc_aware(yesterday))
            })

        # translate to Python native:
        serializer = ItemSerializer(data=sample.get_json('deserialize'))
        with self.assertRaises(ValidationError):
            serializer.is_valid(raise_exception=True)
예제 #6
0
    def test_item_deserialization_create_full(self):
        sample = self.data_factory.create_item_sample(
            collection=self.collection.model, sample='item-1')

        # translate to Python native:
        serializer = ItemSerializer(data=sample.get_json('deserialize'))
        serializer.is_valid(raise_exception=True)
        item = serializer.save()

        # serialize the object and test it against the one above
        # mock a request needed for the serialization of links
        context = {
            'request':
            api_request_mocker.get(
                f'{STAC_BASE_V}/collections/{self.collection["name"]}/items/{sample["name"]}'
            )
        }
        serializer = ItemSerializer(item, context=context)
        python_native = serializer.data
        self.check_stac_item(sample.json, python_native,
                             self.collection["name"])