-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow reassigning dataset owner (#505)
Allow reassigning data owner.
- Loading branch information
Showing
5 changed files
with
139 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,6 +306,10 @@ async def is_admin_mocked(): | |
return True | ||
|
||
|
||
async def not_admin_mocked(): | ||
return False | ||
|
||
|
||
async def is_service_account_mocked(): | ||
return True | ||
|
||
|
@@ -314,17 +318,36 @@ async def get_api_key_mocked() -> Tuple[Optional[str], Optional[str]]: | |
return str(uuid.uuid4()), "localhost" | ||
|
||
|
||
MANAGER = User( | ||
id="mr_manager123", | ||
name="Mr. Manager", | ||
email="[email protected]", | ||
createdAt="2021-06-13T03:18:23.000Z", | ||
role="MANAGER", | ||
provider="local", | ||
providerId="123", | ||
extraUserData={}, | ||
) | ||
|
||
|
||
NEW_OWNER = User( | ||
id="new_owner_id123", | ||
name="New Owner", | ||
email="[email protected]", | ||
createdAt="2021-06-13T03:18:23.000Z", | ||
role="MANAGER", | ||
provider="local", | ||
providerId="1234", | ||
extraUserData={}, | ||
) | ||
|
||
|
||
async def get_manager_mocked() -> User: | ||
return User( | ||
id="mr_manager123", | ||
name="Mr. Manager", | ||
email="[email protected]", | ||
createdAt="2021-06-13T03:18:23.000Z", | ||
role="MANAGER", | ||
provider="local", | ||
providerId="123", | ||
extraUserData={}, | ||
) | ||
return MANAGER | ||
|
||
|
||
async def get_new_owner_mocked() -> User: | ||
return NEW_OWNER | ||
|
||
|
||
def setup_clients(ec2_client, iam_client): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
import pytest | ||
|
||
from app.application import ContextEngine, db | ||
from app.authentication.token import get_manager | ||
from app.models.pydantic.authentication import User | ||
from tests import MANAGER, NEW_OWNER, get_manager_mocked, get_new_owner_mocked | ||
from tests.utils import create_default_asset, dataset_metadata | ||
|
||
payload = {"metadata": dataset_metadata} | ||
|
@@ -70,16 +73,55 @@ async def test_datasets(async_client): | |
assert len(rows) == 1 | ||
assert rows[0][0] == "mr_manager123" | ||
|
||
new_payload = {"metadata": {"title": "New Title"}} | ||
response = await async_client.patch(f"/dataset/{dataset}", json=new_payload) | ||
assert response.status_code == 200 | ||
assert response.json()["data"]["metadata"] != payload["metadata"] | ||
assert response.json()["data"]["metadata"]["title"] == "New Title" | ||
assert ( | ||
response.json()["data"]["metadata"]["data_language"] | ||
== payload["metadata"]["data_language"] | ||
with patch("app.routes.datasets.dataset.get_rw_user", return_value=NEW_OWNER): | ||
new_payload = { | ||
"metadata": {"title": "New Title"}, | ||
"owner_id": "new_owner_id123", | ||
} | ||
response = await async_client.patch(f"/dataset/{dataset}", json=new_payload) | ||
assert response.status_code == 200 | ||
assert response.json()["data"]["metadata"] != payload["metadata"] | ||
assert response.json()["data"]["metadata"]["title"] == "New Title" | ||
assert ( | ||
response.json()["data"]["metadata"]["data_language"] | ||
== payload["metadata"]["data_language"] | ||
) | ||
|
||
async with ContextEngine("READ"): | ||
rows = await db.all( | ||
f"SELECT owner_id FROM datasets WHERE dataset = '{dataset}';" | ||
) | ||
|
||
assert len(rows) == 1 | ||
assert rows[0][0] == "new_owner_id123" | ||
|
||
# assign original owner back | ||
with patch("app.routes.datasets.dataset.get_rw_user", return_value=MANAGER): | ||
from app.main import app | ||
|
||
app.dependency_overrides[get_manager] = get_new_owner_mocked | ||
new_payload = {"owner_id": "mr_manager123"} | ||
response = await async_client.patch(f"/dataset/{dataset}", json=new_payload) | ||
assert response.status_code == 200 | ||
|
||
app.dependency_overrides[get_manager] = get_manager_mocked | ||
|
||
bad_user = User( | ||
id="bad_user123", | ||
name="Bad User", | ||
email="[email protected]", | ||
createdAt="2021-06-13T03:18:23.000Z", | ||
role="USER", | ||
provider="local", | ||
providerId="1234", | ||
extraUserData={}, | ||
) | ||
|
||
with patch("app.routes.datasets.dataset.get_rw_user", return_value=bad_user): | ||
new_payload = {"owner_id": "bad_user123"} | ||
response = await async_client.patch(f"/dataset/{dataset}", json=new_payload) | ||
assert response.status_code == 400 | ||
|
||
response = await async_client.delete(f"/dataset/{dataset}") | ||
assert response.status_code == 200 | ||
assert response.json()["data"]["dataset"] == "test" | ||
|