Skip to content

Commit 5143f00

Browse files
committed
Adding extra tests.
1 parent 65ebbea commit 5143f00

File tree

1 file changed

+164
-1
lines changed

1 file changed

+164
-1
lines changed

stac_fastapi/elasticsearch/tests/api/test_api.py

Lines changed: 164 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,22 @@ async def test_search_point_does_not_intersect(app_client, ctx):
402402

403403

404404
@pytest.mark.asyncio
405-
async def test_datetime_non_interval(app_client, ctx):
405+
async def test_datetime_response_format(app_client, txn_client, ctx):
406+
first_item = ctx.item
407+
408+
second_item = dict(first_item)
409+
second_item["id"] = "second-item"
410+
second_item["properties"]["datetime"] = None
411+
412+
await create_item(txn_client, second_item)
413+
414+
third_item = dict(first_item)
415+
third_item["id"] = "third-item"
416+
del third_item["properties"]["start_datetime"]
417+
del third_item["properties"]["end_datetime"]
418+
419+
await create_item(txn_client, third_item)
420+
406421
dt_formats = [
407422
"2020-02-12T12:30:22+00:00",
408423
"2020-02-12T12:30:22.00Z",
@@ -423,6 +438,154 @@ async def test_datetime_non_interval(app_client, ctx):
423438
assert resp_json["features"][0]["properties"]["datetime"][0:19] == dt[0:19]
424439

425440

441+
@pytest.mark.asyncio
442+
async def test_datetime_non_interval(app_client, txn_client, ctx):
443+
first_item = ctx.item
444+
445+
second_item = dict(first_item)
446+
second_item["id"] = "second-item"
447+
second_item["properties"]["datetime"] = None
448+
449+
await create_item(txn_client, second_item)
450+
451+
third_item = dict(first_item)
452+
third_item["id"] = "third-item"
453+
del third_item["properties"]["start_datetime"]
454+
del third_item["properties"]["end_datetime"]
455+
456+
await create_item(txn_client, third_item)
457+
458+
dt_formats = [
459+
"2020-02-12T12:30:22+00:00",
460+
"2020-02-12T12:30:22.00Z",
461+
"2020-02-12T12:30:22Z",
462+
"2020-02-12T12:30:22.00+00:00",
463+
]
464+
465+
for dt in dt_formats:
466+
params = {
467+
"datetime": dt,
468+
"collections": [ctx.item["collection"]],
469+
}
470+
471+
resp = await app_client.post("/search", json=params)
472+
assert resp.status_code == 200
473+
resp_json = resp.json()
474+
assert len(resp_json["features"]) == 3
475+
476+
477+
@pytest.mark.asyncio
478+
async def test_datetime_interval(app_client, txn_client, ctx):
479+
first_item = ctx.item
480+
481+
second_item = dict(first_item)
482+
second_item["id"] = "second-item"
483+
second_item["properties"]["datetime"] = None
484+
485+
await create_item(txn_client, second_item)
486+
487+
third_item = dict(first_item)
488+
third_item["id"] = "third-item"
489+
del third_item["properties"]["start_datetime"]
490+
del third_item["properties"]["end_datetime"]
491+
492+
await create_item(txn_client, third_item)
493+
494+
print("CREATED ITEMS")
495+
496+
dt_formats = [
497+
"2020-02-06T12:30:22+00:00/2020-02-13T12:30:22+00:00",
498+
"2020-02-12T12:30:22.00Z/2020-02-20T12:30:22.00Z",
499+
"2020-02-12T12:30:22Z/2020-02-13T12:30:22Z",
500+
"2020-02-06T12:30:22.00+00:00/2020-02-20T12:30:22.00+00:00",
501+
]
502+
503+
for dt in dt_formats:
504+
params = {
505+
"datetime": dt,
506+
"collections": [ctx.item["collection"]],
507+
}
508+
509+
resp = await app_client.post("/search", json=params)
510+
assert resp.status_code == 200
511+
resp_json = resp.json()
512+
assert len(resp_json["features"]) == 3
513+
514+
515+
@pytest.mark.asyncio
516+
async def test_datetime_bad_non_interval(app_client, txn_client, ctx):
517+
first_item = ctx.item
518+
519+
second_item = dict(first_item)
520+
second_item["id"] = "second-item"
521+
second_item["properties"]["datetime"] = None
522+
523+
await create_item(txn_client, second_item)
524+
525+
third_item = dict(first_item)
526+
third_item["id"] = "third-item"
527+
del third_item["properties"]["start_datetime"]
528+
del third_item["properties"]["end_datetime"]
529+
530+
await create_item(txn_client, third_item)
531+
532+
dt_formats = [
533+
"2020-02-06T12:30:22+00:00",
534+
"2020-02-06:30:22.00Z",
535+
"2020-02-06:30:22Z",
536+
"2020-02-06T12:30:22.00+00:00",
537+
]
538+
539+
for dt in dt_formats:
540+
params = {
541+
"datetime": dt,
542+
"collections": [ctx.item["collection"]],
543+
}
544+
545+
resp = await app_client.post("/search", json=params)
546+
assert resp.status_code == 200
547+
resp_json = resp.json()
548+
assert len(resp_json["features"]) == 0
549+
550+
551+
@pytest.mark.asyncio
552+
async def test_datetime_bad_interval(app_client, txn_client, ctx):
553+
first_item = ctx.item
554+
555+
second_item = dict(first_item)
556+
second_item["id"] = "second-item"
557+
second_item["properties"]["datetime"] = None
558+
559+
await create_item(txn_client, second_item)
560+
561+
third_item = dict(first_item)
562+
third_item["id"] = "third-item"
563+
del third_item["properties"]["start_datetime"]
564+
del third_item["properties"]["end_datetime"]
565+
566+
await create_item(txn_client, third_item)
567+
568+
print("CREATED ITEMS")
569+
570+
dt_formats = [
571+
"1920-02-04T12:30:22+00:00/1920-02-06T12:30:22+00:00",
572+
"1920-02-04T12:30:22.00Z/1920-02-06T12:30:22.00Z",
573+
"1920-02-04T12:30:22Z/1920-02-06T12:30:22Z",
574+
"1920-02-04T12:30:22.00+00:00/1920-02-06T12:30:22.00+00:00",
575+
]
576+
577+
for dt in dt_formats:
578+
params = {
579+
"datetime": dt,
580+
"collections": [ctx.item["collection"]],
581+
}
582+
583+
resp = await app_client.post("/search", json=params)
584+
assert resp.status_code == 200
585+
resp_json = resp.json()
586+
assert len(resp_json["features"]) == 0
587+
588+
426589
@pytest.mark.asyncio
427590
async def test_bbox_3d(app_client, ctx):
428591
australia_bbox = [106.343365, -47.199523, 0.1, 168.218365, -19.437288, 0.1]

0 commit comments

Comments
 (0)