Skip to content

Commit

Permalink
[AT-2461] implement get feasibility endpoint (#431)
Browse files Browse the repository at this point in the history
* initial commit: get_feasibility

* add feasibility response

* add function to decided feasibility option

* wip: tests

* wip: add assertions for live tests

* update global variable name

* add tests and mock responses for feasibility endpoint

* disable pylint for too long line

* PR suggestions; linting; live test env vars

* add mock for decision param

* fotgot to add mock response json

* split long line into 2 lines

* add test for wrong decision param
  • Loading branch information
seedlit authored Jun 19, 2023
1 parent f78900e commit 9632889
Show file tree
Hide file tree
Showing 9 changed files with 1,156 additions and 16 deletions.
3 changes: 3 additions & 0 deletions tests/fixtures/fixtures_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
PROJECT_NAME = "project_name_123"
PROJECT_DESCRIPTION = "project_description_123"

# tasking constants
QUOTATION_ID = "some_quotation_id"
WRONG_FEASIBILITY_ID = "296ef160-d890-430d-8d14-e9b579ab08ba"
WRONG_OPTION_ID = "296ef160-7890-430d-8d14-e9b579ab08ba"

WORKFLOW_ID = "workflow_id_123"
WORKFLOW_NAME = "workflow_name_123"
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/fixtures_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

@pytest.fixture()
def storage_mock(auth_mock, requests_mock):

# pystac client authentication
url_pystac_client = f"{auth_mock._endpoint()}/v2/assets/stac"
requests_mock.get(url=url_pystac_client, json=PYSTAC_MOCK_CLIENT)
Expand Down
109 changes: 94 additions & 15 deletions tests/fixtures/fixtures_tasking.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from pathlib import Path
import json

import os
import pytest
from ..context import (
Tasking,
)

from .fixtures_globals import (
DATA_PRODUCT_ID,
WORKSPACE_ID,
QUOTATION_ID,
WRONG_FEASIBILITY_ID,
)

from ..context import (
Tasking,
)
LIVE_FEASIBILITY_ID = os.getenv("LIVE_FEASIBILITY_ID")

ENDPOINT = "/v2/tasking/quotation"

QUOTATION_ENDPOINT = "/v2/tasking/quotation"


@pytest.fixture()
Expand All @@ -27,7 +30,7 @@ def tasking_mock(auth_mock, requests_mock):
requests_mock.get(url=url_data_product_schema, json=json_data_product_schema)

url_get_quotations_mp1 = (
f"{auth_mock._endpoint()}{ENDPOINT}?page=0&sort=createdAt,desc"
f"{auth_mock._endpoint()}{QUOTATION_ENDPOINT}?page=0&sort=createdAt,desc"
)
with open(
Path(__file__).resolve().parents[1]
Expand All @@ -37,7 +40,7 @@ def tasking_mock(auth_mock, requests_mock):
requests_mock.get(url=url_get_quotations_mp1, json=json_data_get_quotation)

url_get_quotations_mp2 = (
f"{auth_mock._endpoint()}{ENDPOINT}?page=1&sort=createdAt,desc"
f"{auth_mock._endpoint()}{QUOTATION_ENDPOINT}?page=1&sort=createdAt,desc"
)
with open(
Path(__file__).resolve().parents[1]
Expand All @@ -47,7 +50,7 @@ def tasking_mock(auth_mock, requests_mock):
requests_mock.get(url=url_get_quotations_mp2, json=json_data_get_quotation)

url_get_quotations_mp3 = (
f"{auth_mock._endpoint()}{ENDPOINT}?page=2&sort=createdAt,desc"
f"{auth_mock._endpoint()}{QUOTATION_ENDPOINT}?page=2&sort=createdAt,desc"
)
with open(
Path(__file__).resolve().parents[1]
Expand All @@ -57,9 +60,11 @@ def tasking_mock(auth_mock, requests_mock):
requests_mock.get(url=url_get_quotations_mp3, json=json_data_get_quotation)

sorting = "page=0&sort=createdAt,desc"

url_get_quotations_workspace_filtered = (
f"{auth_mock._endpoint()}{ENDPOINT}?{sorting}&workspaceId={WORKSPACE_ID}"
f"{auth_mock._endpoint()}"
f"{QUOTATION_ENDPOINT}?"
f"{sorting}&"
f"workspaceId={WORKSPACE_ID}"
)
with open(
Path(__file__).resolve().parents[1]
Expand All @@ -71,7 +76,7 @@ def tasking_mock(auth_mock, requests_mock):
)

url_get_quotations_decision_filtered = (
f"{auth_mock._endpoint()}{ENDPOINT}?{sorting}&decision=ACCEPTED"
f"{auth_mock._endpoint()}{QUOTATION_ENDPOINT}?{sorting}&decision=ACCEPTED"
)
with open(
Path(__file__).resolve().parents[1]
Expand All @@ -82,12 +87,12 @@ def tasking_mock(auth_mock, requests_mock):
url=url_get_quotations_decision_filtered, json=json_data_get_quotation
)
url_get_quotations_decision_filtered = (
f"{auth_mock._endpoint()}{ENDPOINT}?{sorting}&decision=ACCEPTED"
f"{auth_mock._endpoint()}{QUOTATION_ENDPOINT}?{sorting}&decision=ACCEPTED"
)

desicion_filter = "&decision=ACCEPTED&decision=REJECTED"
decision_filter = "&decision=ACCEPTED&decision=REJECTED"
url_get_quotations_decision_filtered = (
f"{auth_mock._endpoint()}{ENDPOINT}?{sorting}{desicion_filter}"
f"{auth_mock._endpoint()}{QUOTATION_ENDPOINT}?{sorting}{decision_filter}"
)
with open(
Path(__file__).resolve().parents[1]
Expand Down Expand Up @@ -127,7 +132,81 @@ def tasking_mock(auth_mock, requests_mock):
return Tasking(auth=auth_mock)


@pytest.fixture()
def tasking_get_feasibility_mock(auth_mock, requests_mock):
get_feasibility_page0_url = (
f"{auth_mock._endpoint()}/v2/tasking/feasibility?page=0&sort=createdAt,desc"
)
with open(
Path(__file__).resolve().parents[1]
/ "mock_data/tasking_data/get_feasibility_multi_page_01.json"
) as json_file:
json_data = json.load(json_file)
requests_mock.get(url=get_feasibility_page0_url, json=json_data)

get_feasibility_page1_url = (
f"{auth_mock._endpoint()}/v2/tasking/feasibility?page=1&sort=createdAt,desc"
)
with open(
Path(__file__).resolve().parents[1]
/ "mock_data/tasking_data/get_feasibility_multi_page_02.json"
) as json_file:
json_data = json.load(json_file)
requests_mock.get(url=get_feasibility_page1_url, json=json_data)

get_feasibility_page2_url = (
f"{auth_mock._endpoint()}/v2/tasking/feasibility?page=2&sort=createdAt,desc"
)
with open(
Path(__file__).resolve().parents[1]
/ "mock_data/tasking_data/get_feasibility_multi_page_03.json"
) as json_file:
json_data = json.load(json_file)
requests_mock.get(url=get_feasibility_page2_url, json=json_data)

get_feasibility_decision_param = (
f"{auth_mock._endpoint()}/v2/tasking/feasibility?"
"page=0&sort=createdAt,desc&decision=NOT_DECIDED"
)
with open(
Path(__file__).resolve().parents[1]
/ "mock_data/tasking_data/get_feasibility_NOT_DECIDED.json"
) as json_file:
json_data = json.load(json_file)
requests_mock.get(url=get_feasibility_decision_param, json=json_data)

return Tasking(auth=auth_mock)


@pytest.fixture()
def tasking_choose_feasibility_mock(auth_mock, requests_mock):
wrong_feasibility_url = (
f"{auth_mock._endpoint()}/v2/tasking/feasibility/{WRONG_FEASIBILITY_ID}"
)
response = json.dumps(
{
"status": 404,
"title": "Resource (FeasibilityStudy) not found with Id='296ef160-7890-430d-8d14-e9b579ab08ba'.",
"detail": {},
}
)
requests_mock.patch(url=wrong_feasibility_url, status_code=404, json=response)

choose_feasibility_url = (
f"{auth_mock._endpoint()}/v2/tasking/feasibility/{LIVE_FEASIBILITY_ID}"
)
response = json.dumps(
{
"status": 405,
"title": "Resource (FeasibilityStudy) is write-protected.",
"detail": {},
}
)
requests_mock.patch(url=choose_feasibility_url, status_code=405, json=response)
return Tasking(auth=auth_mock)


@pytest.fixture()
def tasking_live(auth_live):
tasking = Tasking(auth=auth_live)
return tasking
return tasking
59 changes: 59 additions & 0 deletions tests/mock_data/tasking_data/get_feasibility_NOT_DECIDED.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"content": [
{
"id": "f3fa5e07-a156-4eb1-9f25-07a2fa68a2b1",
"createdAt": "2023-06-14T01:02:24.410534Z",
"updatedAt": "2023-06-14T01:02:24.410534Z",
"accountId": "3c86279b-610a-4dba-ad12-abe3bdc51428",
"workspaceId": "eb1626d2-8015-43e9-acab-fbfaee89466c",
"orderId": "1f82558b-a235-47f8-9965-9128f4bd0156",
"type": "MANUAL",
"options": [
{
"id": "e24b289d-25b0-456b-ae47-0046a76babec",
"createdAt": "2023-06-14T01:02:25.465404Z",
"updatedAt": "2023-06-14T01:02:25.465404Z",
"studyId": "f3fa5e07-a156-4eb1-9f25-07a2fa68a2b1",
"description": "Option 1: Extend dates"
},
{
"id": "7859ae61-9ec9-447b-962e-a84fcea9f683",
"createdAt": "2023-06-14T01:02:43.274035Z",
"updatedAt": "2023-06-14T01:02:56.732208Z",
"studyId": "f3fa5e07-a156-4eb1-9f25-07a2fa68a2b1",
"description": "Option 2: increase cloud cover percentage"
}
],
"decision": "NOT_DECIDED",
"decisionById": null,
"decisionByType": null,
"decisionAt": null,
"decisionOption": null
}
],
"pageable": {
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"pageNumber": 0,
"pageSize": 10,
"offset": 0,
"unpaged": false,
"paged": true
},
"totalPages": 1,
"totalElements": 1,
"last": true,
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"numberOfElements": 1,
"first": true,
"size": 10,
"number": 0,
"empty": false
}
Loading

0 comments on commit 9632889

Please sign in to comment.