def test_wrong_media_type(self):
        client_login(self.client)

        for (request_methods, endpoint, data) in [
            (
                ['put', 'patch'],
                f'collections/{self.collection["name"]}',
                {},
            ),
            (
                ['put', 'patch'],
                f'collections/{self.collection["name"]}/items/{self.item["name"]}',
                {},
            ),
            (['post'], 'search', {
                "query": {
                    "title": {
                        "eq": "My item 1"
                    }
                }
            }),
        ]:
            with self.subTest(endpoint=endpoint):
                client_requests = [
                    getattr(self.client, method) for method in request_methods
                ]
                for client_request in client_requests:
                    response = client_request(f"/{STAC_BASE_V}/{endpoint}",
                                              data=data,
                                              content_type="plain/text")
                    self.assertStatusCode(415, response)
    def test_delete_precondition(self):
        client_login(self.client)
        for endpoint in [
                f'collections/{self.collection["name"]}/items/{self.item["name"]}'
                f'/assets/{self.asset["name"]}',
                f'collections/{self.collection["name"]}/items/{self.item["name"]}',
                # f'collections/{self.collection["name"]}',
        ]:
            with self.subTest(endpoint=endpoint):
                # Get first the ETag
                response = self.client.get(f"/{STAC_BASE_V}/{endpoint}")
                self.assertStatusCode(200, response)
                # The ETag change between each test call due to the created, updated time that are
                # in the hash computation of the ETag
                self.check_header_etag(None, response)
                etag1 = response['ETag']

                response = self.client.delete(f"/{STAC_BASE_V}/{endpoint}",
                                              content_type="application/json",
                                              HTTP_IF_MATCH='"abc"')
                self.assertStatusCode(
                    412,
                    response,
                    msg='Request should be refused due to precondition failed')

                response = self.client.delete(f"/{STAC_BASE_V}/{endpoint}",
                                              content_type="application/json",
                                              HTTP_IF_MATCH=etag1)
                self.assertStatusCode(200, response)
 def setUp(self):
     self.client = Client()
     client_login(self.client)
     self.factory = Factory()
     self.collection = self.factory.create_collection_sample().model
     self.items = self.factory.create_item_samples(
         ['item-switzerland-west'], self.collection, db_create=True)
 def setUp(self):  # pylint: disable=invalid-name
     self.client = Client()
     client_login(self.client)
     self.factory = Factory()
     self.collection = self.factory.create_collection_sample(db_create=True)
     self.item = self.factory.create_item_sample(self.collection.model, db_create=True)
     self.maxDiff = None  # pylint: disable=invalid-name
 def setUp(self):  # pylint: disable=invalid-name
     self.factory = Factory()
     self.collection = self.factory.create_collection_sample().model
     self.item = self.factory.create_item_sample(
         collection=self.collection).model
     self.asset = self.factory.create_asset_sample(item=self.item).model
     self.client = Client()
     client_login(self.client)
     self.maxDiff = None  # pylint: disable=invalid-name
    def test_patch_precondition(self):
        client_login(self.client)
        for (endpoint, data) in [
            (
                f'collections/{self.collection["name"]}',
                {
                    'title': 'New title patched'
                },
            ),
            (
                f'collections/{self.collection["name"]}/items/{self.item["name"]}',
                {
                    'properties': {
                        'title': 'New title patched'
                    }
                },
            ),
            (
                f'collections/{self.collection["name"]}/items/{self.item["name"]}'
                f'/assets/{self.asset["name"]}',
                {
                    'title': 'New title patched'
                },
            ),
        ]:
            with self.subTest(endpoint=endpoint):
                # Get first the ETag
                response = self.client.get(f"/{STAC_BASE_V}/{endpoint}")
                self.assertStatusCode(200, response)
                # The ETag change between each test call due to the created, updated time that are
                # in the hash computation of the ETag
                self.check_header_etag(None, response)
                etag1 = response['ETag']

                response = self.client.patch(f"/{STAC_BASE_V}/{endpoint}",
                                             data,
                                             content_type="application/json",
                                             HTTP_IF_MATCH='"abc"')
                self.assertStatusCode(412, response)

                response = self.client.patch(f"/{STAC_BASE_V}/{endpoint}",
                                             data,
                                             content_type="application/json",
                                             HTTP_IF_MATCH=etag1)
                self.assertStatusCode(200, response)
    def test_put_precondition(self):
        client_login(self.client)
        for (endpoint, sample) in [
            (f'collections/{self.collection["name"]}',
             self.factory.create_collection_sample(
                 name=self.collection["name"],
                 sample='collection-2',
             )),
            (f'collections/{self.collection["name"]}/items/{self.item["name"]}',
             self.factory.create_item_sample(
                 collection=self.collection.model,
                 name=self.item["name"],
                 sample='item-2',
             )),
            (f'collections/{self.collection["name"]}/items/{self.item["name"]}'
             f'/assets/{self.asset["name"]}',
             self.factory.create_asset_sample(
                 item=self.item.model,
                 name=self.asset["name"],
                 sample='asset-1-updated',
                 checksum_multihash=self.asset.model.checksum_multihash)),
        ]:
            with self.subTest(endpoint=endpoint):
                # Get first the ETag
                response = self.client.get(f"/{STAC_BASE_V}/{endpoint}")
                self.assertStatusCode(200, response)
                # The ETag change between each test call due to the created, updated time that are
                # in the hash computation of the ETag
                self.check_header_etag(None, response)
                etag1 = response['ETag']

                response = self.client.put(f"/{STAC_BASE_V}/{endpoint}",
                                           sample.get_json('put'),
                                           content_type="application/json",
                                           HTTP_IF_MATCH='"abc"')
                self.assertStatusCode(412, response)

                response = self.client.put(f"/{STAC_BASE_V}/{endpoint}",
                                           sample.get_json('put'),
                                           content_type="application/json",
                                           HTTP_IF_MATCH=etag1)
                self.assertStatusCode(200, response)
    def test_patch_precondition(self):
        client_login(self.client)
        for (endpoint, data) in [
            (
                f'collections/{self.collection["name"]}',
                {
                    'title': 'New title patched'
                },
            ),
            (
                f'collections/{self.collection["name"]}/items/{self.item["name"]}',
                {
                    'properties': {
                        'title': 'New title patched'
                    }
                },
            ),
            (
                f'collections/{self.collection["name"]}/items/{self.item["name"]}'
                f'/assets/{self.asset["name"]}',
                {
                    'title': 'New title patched'
                },
            ),
        ]:
            with self.subTest(endpoint=endpoint):

                response = self.client.patch(f"/{STAC_BASE_V}/{endpoint}",
                                             data,
                                             content_type="application/json",
                                             HTTP_IF_MATCH='"abc"')
                self.assertStatusCode(412, response)

                response = self.client.patch(
                    f"/{STAC_BASE_V}/{endpoint}",
                    data,
                    content_type="application/json",
                    HTTP_IF_MATCH=self.get_etag(endpoint))
                self.assertStatusCode(200, response)
    def test_delete_precondition(self):
        client_login(self.client)
        for endpoint in [
                f'collections/{self.collection["name"]}/items/{self.item["name"]}'
                f'/assets/{self.asset["name"]}',
                f'collections/{self.collection["name"]}/items/{self.item["name"]}',
                # f'collections/{self.collection["name"]}',
        ]:
            with self.subTest(endpoint=endpoint):
                etag1 = self.get_etag(endpoint)

                response = self.client.delete(f"/{STAC_BASE_V}/{endpoint}",
                                              content_type="application/json",
                                              HTTP_IF_MATCH='"abc"')
                self.assertStatusCode(
                    412,
                    response,
                    msg='Request should be refused due to precondition failed')

                response = self.client.delete(f"/{STAC_BASE_V}/{endpoint}",
                                              content_type="application/json",
                                              HTTP_IF_MATCH=etag1)
                self.assertStatusCode(200, response)
Example #10
0
    def test_put_precondition(self):
        client_login(self.client)
        for (endpoint, sample) in [
            (f'collections/{self.collection["name"]}',
             self.factory.create_collection_sample(
                 name=self.collection["name"],
                 sample='collection-2',
             )),
            (f'collections/{self.collection["name"]}/items/{self.item["name"]}',
             self.factory.create_item_sample(
                 collection=self.collection.model,
                 name=self.item["name"],
                 sample='item-2',
             )),
            (f'collections/{self.collection["name"]}/items/{self.item["name"]}'
             f'/assets/{self.asset["name"]}',
             self.factory.create_asset_sample(
                 item=self.item.model,
                 name=self.asset["name"],
                 sample='asset-1-updated',
                 media_type=self.asset['media_type'],
                 checksum_multihash=self.asset["checksum_multihash"])),
        ]:
            with self.subTest(endpoint=endpoint):

                response = self.client.put(f"/{STAC_BASE_V}/{endpoint}",
                                           sample.get_json('put'),
                                           content_type="application/json",
                                           HTTP_IF_MATCH='"abc"')
                self.assertStatusCode(412, response)

                response = self.client.put(
                    f"/{STAC_BASE_V}/{endpoint}",
                    sample.get_json('put'),
                    content_type="application/json",
                    HTTP_IF_MATCH=self.get_etag(endpoint))
                self.assertStatusCode(200, response)
 def setUp(self):
     self.client = Client()
     client_login(self.client)
Example #12
0
 def setUp(self):  # pylint: disable=invalid-name
     self.client = Client()
     client_login(self.client)
     self.collection_factory = CollectionFactory()
     self.maxDiff = None  # pylint: disable=invalid-name
 def setUp(self):
     self.client = Client()
     client_login(self.client)
     self.collection = self.factory.create_collection_sample().model
     self.item = self.factory.create_item_sample(self.collection, sample='item-1').model
     self.asset = self.factory.create_asset_sample(self.item, sample='asset-1').model
 def setUp(self):  # pylint: disable=invalid-name
     self.client = Client()
     client_login(self.client)
     self.factory = Factory()
     self.collection = self.factory.create_collection_sample()
     self.maxDiff = None  # pylint: disable=invalid-name
 def setUp(self):  # pylint: disable=invalid-name
     self.client = Client()
     client_login(self.client)
     self.path = f'/{STAC_BASE_V}/search'
     self.maxDiff = None  # pylint: disable=invalid-name