def test_create_item_already_exists( postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = load_test_data("test_collection.json") postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = load_test_data("test_item.json") postgres_transactions.create_item(item, request=MockStarletteRequest) with pytest.raises(ConflictError): postgres_transactions.create_item(item, request=MockStarletteRequest)
def test_delete_item( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = Collection.parse_obj(load_test_data("test_collection.json")) postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = Item.parse_obj(load_test_data("test_item.json")) postgres_transactions.create_item(item, request=MockStarletteRequest) postgres_transactions.delete_item(item.id, request=MockStarletteRequest) with pytest.raises(NotFoundError): postgres_core.get_item(item.id, request=MockStarletteRequest)
def test_create_item( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = Collection.parse_obj(load_test_data("test_collection.json")) postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = Item.parse_obj(load_test_data("test_item.json")) postgres_transactions.create_item(item, request=MockStarletteRequest) resp = postgres_core.get_item( item.id, item.collection, request=MockStarletteRequest ) assert item.dict( exclude={"links": ..., "properties": {"created", "updated"}} ) == resp.dict(exclude={"links": ..., "properties": {"created", "updated"}})
def test_get_item( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): collection_data = load_test_data("test_collection.json") postgres_transactions.create_collection(collection_data, request=MockStarletteRequest) data = load_test_data("test_item.json") postgres_transactions.create_item(data, request=MockStarletteRequest) coll = postgres_core.get_item( item_id=data["id"], collection_id=data["collection"], request=MockStarletteRequest, ) assert coll["id"] == data["id"] assert coll["collection"] == data["collection"]
def test_update_item( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = Collection.parse_obj(load_test_data("test_collection.json")) postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = Item.parse_obj(load_test_data("test_item.json")) postgres_transactions.create_item(item, request=MockStarletteRequest) item.properties.foo = "bar" postgres_transactions.update_item(item, request=MockStarletteRequest) updated_item = postgres_core.get_item(item.id, request=MockStarletteRequest) assert updated_item.properties.foo == "bar"
def test_update_item( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = load_test_data("test_collection.json") postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = load_test_data("test_item.json") postgres_transactions.create_item(item, request=MockStarletteRequest) item["properties"]["foo"] = "bar" postgres_transactions.update_item(item, request=MockStarletteRequest) updated_item = postgres_core.get_item(item["id"], item["collection"], request=MockStarletteRequest) assert updated_item["properties"]["foo"] == "bar"
def test_create_duplicate_item_different_collections( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): # create test-collection coll = load_test_data("test_collection.json") postgres_transactions.create_collection(coll, request=MockStarletteRequest) # create test-collection-2 coll["id"] = "test-collection-2" postgres_transactions.create_collection(coll, request=MockStarletteRequest) # add item to test-collection item = load_test_data("test_item.json") postgres_transactions.create_item(item, request=MockStarletteRequest) # get item from test-collection resp = postgres_core.get_item(item["id"], item["collection"], request=MockStarletteRequest) assert Item(**item).dict(exclude={ "links":..., "properties": {"created", "updated"} }) == Item(**resp).dict(exclude={ "links":..., "properties": {"created", "updated"} }) # add item to test-collection-2 item["collection"] = "test-collection-2" postgres_transactions.create_item(item, request=MockStarletteRequest) # get item with same id from test-collection-2 resp = postgres_core.get_item(item["id"], item["collection"], request=MockStarletteRequest) assert Item(**item).dict(exclude={ "links":..., "properties": {"created", "updated"} }) == Item(**resp).dict(exclude={ "links":..., "properties": {"created", "updated"} })
def test_create_item( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = load_test_data("test_collection.json") postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = load_test_data("test_item.json") postgres_transactions.create_item(item, request=MockStarletteRequest) resp = postgres_core.get_item(item["id"], item["collection"], request=MockStarletteRequest) assert Item(**item).dict(exclude={ "links":..., "properties": {"created", "updated"} }) == Item(**resp).dict(exclude={ "links":..., "properties": {"created", "updated"} })
def test_get_collection_items( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = Collection.parse_obj(load_test_data("test_collection.json")) postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = Item.parse_obj(load_test_data("test_item.json")) for _ in range(5): item.id = str(uuid.uuid4()) postgres_transactions.create_item(item, request=MockStarletteRequest) fc = postgres_core.item_collection(coll.id, request=MockStarletteRequest) assert len(fc.features) == 5 for item in fc.features: assert item.collection == coll.id
def test_update_geometry( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = load_test_data("test_collection.json") postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = load_test_data("test_item.json") postgres_transactions.create_item(item, request=MockStarletteRequest) item["geometry"]["coordinates"] = [[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]] postgres_transactions.update_item(item, request=MockStarletteRequest) updated_item = postgres_core.get_item(item["id"], item["collection"], request=MockStarletteRequest) assert updated_item["geometry"]["coordinates"] == item["geometry"][ "coordinates"]
def test_get_collection_items( postgres_core: CoreCrudClient, postgres_transactions: TransactionsClient, load_test_data: Callable, ): coll = load_test_data("test_collection.json") postgres_transactions.create_collection(coll, request=MockStarletteRequest) item = load_test_data("test_item.json") for _ in range(5): item["id"] = str(uuid.uuid4()) postgres_transactions.create_item(item, request=MockStarletteRequest) fc = postgres_core.item_collection(coll["id"], request=MockStarletteRequest) assert len(fc["features"]) == 5 for item in fc["features"]: assert item["collection"] == coll["id"]