Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
90f774e
Do not add suffixes to urls in `UserApiSdk`
oleksii-symon-corva-ai May 17, 2022
2a57c8f
Added default `logger` value
oleksii-symon-corva-ai May 17, 2022
3e1b799
Added TestUserApiSdk.test_get
oleksii-symon-corva-ai May 17, 2022
0e7b979
Use `coverage` instead of `test` in `all` target
oleksii-symon-corva-ai May 17, 2022
c73978d
Increased code coverage
oleksii-symon-corva-ai May 17, 2022
6b2809f
Added env vars for integration tests to `test` step
oleksii-symon-corva-ai May 17, 2022
3392040
Fix CI
oleksii-symon-corva-ai May 17, 2022
3f91e44
Deleted env vars from `test` step
oleksii-symon-corva-ai May 17, 2022
0401187
Raise for status immediately
oleksii-symon-corva-ai May 17, 2022
50e9328
Added DataApiV1Sdk.insert
oleksii-symon-corva-ai May 18, 2022
a18242a
Fixed docstr
oleksii-symon-corva-ai May 18, 2022
f043c07
Rollback Makefile changes
oleksii-symon-corva-ai May 18, 2022
60d9a1c
Set env variables inline in `integration-tests`
oleksii-symon-corva-ai May 18, 2022
2801cd6
Merge branch 'feature/dc-3562_add-find-data' into feature/dc-3564_add…
oleksii-symon-corva-ai May 18, 2022
136bbb2
Added `DataApiV1Sdk.replace` method
oleksii-symon-corva-ai May 18, 2022
56773e1
Added `InsertResult` to `DataApiV1Sdk.insert`
oleksii-symon-corva-ai May 18, 2022
1b85b09
Merge branch 'feature/dc-3564_add-post-documents' into feature/dc-356…
oleksii-symon-corva-ai May 18, 2022
0a0ee5e
Deleted debug logging in tests
oleksii-symon-corva-ai May 18, 2022
4b5e6d3
Merge branch 'feature/api20' into feature/dc-3564_add-post-documents
oleksii-symon-corva-ai May 23, 2022
5d5c0ab
Merge branch 'feature/dc-3564_add-post-documents' into feature/dc-356…
oleksii-symon-corva-ai May 23, 2022
ab049d3
Regenerated test_insert.yaml with generic app name and dataset
oleksii-symon-corva-ai May 23, 2022
940d6e2
Merge branch 'feature/dc-3564_add-post-documents' into feature/dc-356…
oleksii-symon-corva-ai May 23, 2022
3220624
Regenerated test_replace.yaml with generic app name and dataset
oleksii-symon-corva-ai May 23, 2022
088225a
Merge branch 'feature/api20' into feature/dc-3567_add-replace-documen…
oleksii-symon-corva-ai May 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ integration-tests:
DATA_API_ROOT_URL=https://data.localhost.ai \
TEST_API_KEY='' \
TEST_BEARER_TOKEN='' \
TEST_COMPANY_ID='-1' \
coverage run -m pytest --vcr-record=none $(test_path)

## coverage: Display code coverage in the console.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parallel = True

[coverage:report]
precision = 2
fail_under = 98.45
fail_under = 98.47
skip_covered = True
show_missing = True
exclude_lines =
Expand Down
25 changes: 25 additions & 0 deletions src/corva/api_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,31 @@ def insert(

return InsertResult.parse_obj(response.json())

def replace(self, provider: str, dataset: str, id_: str, *, document: dict) -> dict:
"""Replaces all document data.

Replace all document data using the endpoint PUT
'data/{provider}/{dataset}/{id}/'.

Args:
provider: company name owning the dataset.
dataset: dataset name.
id_: document id to replace.
document: new document data.

Raises:
httpx.HTTPStatusError: if request was unsuccessful.

Returns:
Updated document.
"""

response = self.http.put(url=f"data/{provider}/{dataset}/{id_}/", json=document)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it technically possible for one company provide company name of another company and replace their document?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is regulated by permissions of the company making the request. As far as I know company A can request access to read some dataset of company B.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, it should be technically possible within the sdk and "permission regulating" part is in place in data-api. Correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct


response.raise_for_status()

return response.json()


class PlatformApiV1Sdk:
def __init__(self, client: httpx.Client):
Expand Down
6 changes: 6 additions & 0 deletions src/corva/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ def get_test_dataset() -> str:
"""Dataset for testing"""

return os.environ['TEST_DATASET']


def get_test_company_id() -> int:
"""Company id for testing"""

return int(os.environ['TEST_COMPANY_ID'])
320 changes: 320 additions & 0 deletions tests/integration/cassettes/TestUserApiSdk.test_replace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
interactions:
- request:
body: '{"well": {"name": "deleteme-python-sdk-autotest-d4a1214c"}}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '59'
content-type:
- application/json
user-agent:
- python-httpx/0.22.0
method: POST
uri: null
response:
content: '{"data":{"id":"328568","type":"well","attributes":{"name":"deleteme-python-sdk-autotest-d4a1214c","status":"unknown","state":"planned"},"relationships":{}}}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=utf-8
Date:
- Mon, 23 May 2022 11:41:15 GMT
ETag:
- W/"11b6d1d9eb9720313d1fd72196df9595"
Referrer-Policy:
- strict-origin-when-cross-origin
Server:
- nginx/1.18.0
Transfer-Encoding:
- chunked
Vary:
- Origin
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- SAMEORIGIN
X-Permitted-Cross-Domain-Policies:
- none
X-Rack-CORS:
- miss; no-origin
X-Request-Id:
- ce585d4e-d4dc-47bb-9f2a-f109e6a3a59b
X-Runtime:
- '0.101889'
X-XSS-Protection:
- 1; mode=block
http_version: HTTP/1.1
status_code: 200
- request:
body: ''
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
user-agent:
- python-httpx/0.22.0
method: GET
uri: null
response:
content: '{"data":{"id":"328568","type":"well","attributes":{"asset_id":30719716},"relationships":{}}}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=utf-8
Date:
- Mon, 23 May 2022 11:41:15 GMT
ETag:
- W/"b161ea51687ef8fd4b47fd4dc1ca754d"
Referrer-Policy:
- strict-origin-when-cross-origin
Server:
- nginx/1.18.0
Transfer-Encoding:
- chunked
Vary:
- Origin
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- SAMEORIGIN
X-Permitted-Cross-Domain-Policies:
- none
X-Rack-CORS:
- miss; no-origin
X-Request-Id:
- 05e9b6f6-ab30-4478-8f0d-dfe7e7679ac7
X-Runtime:
- '0.044065'
X-XSS-Protection:
- 1; mode=block
http_version: HTTP/1.1
status_code: 200
- request:
body: ''
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
user-agent:
- python-httpx/0.22.0
method: DELETE
uri: null
response:
content: '{"deleted_count":0}'
headers:
Connection:
- keep-alive
Content-Length:
- '19'
Content-Type:
- application/json
Date:
- Mon, 23 May 2022 11:41:16 GMT
server:
- uvicorn
http_version: HTTP/1.1
status_code: 200
- request:
body: '[{"asset_id": 30719716, "version": 1, "data": {"k1": "v1"}, "timestamp":
10}]'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '77'
content-type:
- application/json
user-agent:
- python-httpx/0.22.0
method: POST
uri: null
response:
content: '{"inserted_ids":["628b72dcd6aff355ccea8b78"],"failed_count":0,"messages":[]}'
headers:
Connection:
- keep-alive
Content-Length:
- '76'
Content-Type:
- application/json
Date:
- Mon, 23 May 2022 11:41:16 GMT
server:
- uvicorn
http_version: HTTP/1.1
status_code: 200
- request:
body: '{"data": {"k2": "v2"}, "version": 2, "company_id": 80, "timestamp": 11,
"asset_id": 30719716}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '93'
content-type:
- application/json
user-agent:
- python-httpx/0.22.0
x-corva-app:
- python-sdk-autotest-2022-05-23 11:41:14+00:00
method: PUT
uri: null
response:
content: '{"_id":"628b72dcd6aff355ccea8b78","company_id":80,"asset_id":30719716,"version":2,"provider":"big-data-energy","collection":"python-sdk-autotests","data":{"k2":"v2"},"timestamp":11,"app_key":"big-data-energy.python_sdk_app_for_autotests"}'
headers:
Connection:
- keep-alive
Content-Length:
- '238'
Content-Type:
- application/json
Date:
- Mon, 23 May 2022 11:41:17 GMT
server:
- uvicorn
http_version: HTTP/1.1
status_code: 200
- request:
body: ''
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
user-agent:
- python-httpx/0.22.0
method: GET
uri: null
response:
content: '{"_id":"628b72dcd6aff355ccea8b78","company_id":80,"asset_id":30719716,"version":2,"provider":"big-data-energy","collection":"python-sdk-autotests","data":{"k2":"v2"},"timestamp":11,"app_key":"big-data-energy.python_sdk_app_for_autotests"}'
headers:
Connection:
- keep-alive
Content-Length:
- '238'
Content-Type:
- application/json
Date:
- Mon, 23 May 2022 11:41:17 GMT
server:
- uvicorn
http_version: HTTP/1.1
status_code: 200
- request:
body: ''
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
user-agent:
- python-httpx/0.22.0
method: DELETE
uri: null
response:
content: '{"status":"deleted"}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=utf-8
Date:
- Mon, 23 May 2022 11:41:18 GMT
ETag:
- W/"4df20f95e824b2af44a61642d88daaf0"
Referrer-Policy:
- strict-origin-when-cross-origin
Server:
- nginx/1.18.0
Transfer-Encoding:
- chunked
Vary:
- Origin
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- SAMEORIGIN
X-Permitted-Cross-Domain-Policies:
- none
X-Rack-CORS:
- miss; no-origin
X-Request-Id:
- db6d7a71-cce6-4279-8050-eb7c52cecd26
X-Runtime:
- '0.073215'
X-XSS-Protection:
- 1; mode=block
http_version: HTTP/1.1
status_code: 200
- request:
body: ''
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
user-agent:
- python-httpx/0.22.0
method: DELETE
uri: null
response:
content: '{"deleted_count":1}'
headers:
Connection:
- keep-alive
Content-Length:
- '19'
Content-Type:
- application/json
Date:
- Mon, 23 May 2022 11:41:18 GMT
server:
- uvicorn
http_version: HTTP/1.1
status_code: 200
version: 1
Loading