@@ -16,23 +16,27 @@ def test_my_resources_can_be_empty(client: TestClient) -> None:
1616 with logged_in_user (ALICE ):
1717 response = client .get ("/user/resources" , headers = {"Authorization" : "fake token" })
1818 assert response .status_code == HTTPStatus .OK
19- assert response .json () == [], "A user with no resources should get an empty list"
19+ msg = "A user with no resources should get an empty list"
20+ assert all (items == [] for items in response .json ().values ()), msg
21+ assert len (response .json ()) >= 16 , "Every asset type should always be included in the response"
2022
2123
2224def test_my_resources_shows_draft_assets (client : TestClient , publication : Publication ) -> None :
2325 register_asset (publication , owner = ALICE , status = EntryStatus .DRAFT )
2426 with logged_in_user (ALICE ):
2527 response = client .get ("/user/resources" , headers = {"Authorization" : "fake token" })
2628 assert response .status_code == HTTPStatus .OK
27- assert len (response .json ()) == 1 , "Draft assets should be included in this view."
29+ assert len (response .json ()["publication" ]) == 1 , "Draft assets should be included in this view."
30+ msg = "Properties should be deserialized"
31+ assert response .json ()["publication" ][0 ]["aiod_entry" ]["status" ] == "draft" , msg
2832
2933
3034def test_my_resources_shows_published_assets (client : TestClient , publication : Publication ) -> None :
3135 register_asset (publication , owner = ALICE , status = EntryStatus .PUBLISHED )
3236 with logged_in_user (ALICE ):
3337 response = client .get ("/user/resources" , headers = {"Authorization" : "fake token" })
3438 assert response .status_code == HTTPStatus .OK
35- assert len (response .json ()) == 1 , "Published assets should be included in this view."
39+ assert len (response .json ()[ "publication" ] ) == 1 , "Published assets should be included in this view."
3640
3741
3842def test_my_resources_shows_mixed_assets (client : TestClient , publication : Publication , organisation : Organisation ) -> None :
@@ -42,26 +46,32 @@ def test_my_resources_shows_mixed_assets(client: TestClient, publication: Public
4246 response = client .get ("/user/resources" , headers = {"Authorization" : "fake token" })
4347 assert response .status_code == HTTPStatus .OK
4448
45- pub = next (asset for asset in response .json () if asset ["aiod_entry_identifier" ] == 1 )
46- org = next (asset for asset in response .json () if asset ["aiod_entry_identifier" ] == 2 )
49+ assert len (response .json ()["contact" ]) == 0
50+ assert len (response .json ()["publication" ]) == 1
51+ assert len (response .json ()["organisation" ]) == 1
52+
53+ pub = response .json ()["publication" ][0 ]
54+ org = response .json ()["organisation" ][0 ]
55+
4756 dataset_property = "legal_name"
4857 publication_property = "isbn"
4958
5059 assert dataset_property in org and publication_property in pub , "Assets should report properties unique to their type"
5160 assert dataset_property not in pub and publication_property not in org , "Assets should not report properties they do not have"
5261
62+
5363def test_my_resources_shows_only_own_resources (client : TestClient , publication_factory : Callable [[], Publication ]) -> None :
5464 register_asset (publication_factory (), owner = ALICE , status = EntryStatus .DRAFT )
5565 register_asset (publication_factory (), owner = ALICE , status = EntryStatus .PUBLISHED )
5666 register_asset (publication_factory (), owner = BOB , status = EntryStatus .PUBLISHED )
5767
5868 with logged_in_user (ALICE ):
5969 response = client .get ("/user/resources" , headers = {"Authorization" : "fake token" })
60- assert len (response .json ()) == 2
70+ assert len (response .json ()[ "publication" ] ) == 2
6171
6272 with logged_in_user (BOB ):
6373 response = client .get ("/user/resources" , headers = {"Authorization" : "fake token" })
64- assert len (response .json ()) == 1
74+ assert len (response .json ()[ "publication" ] ) == 1
6575
6676
6777def test_my_resources_counts_only_if_admin (client : TestClient , publication_factory : Callable [[], Publication ]) -> None :
@@ -81,8 +91,8 @@ def test_my_resources_counts_only_if_admin(client: TestClient, publication_facto
8191
8292 with logged_in_user (BOB ):
8393 response = client .get ("/user/resources" , headers = {"Authorization" : "fake token" })
84- assert len (response .json ()) == 1 , "Bob has ADMIN permission to one asset."
85- assert response .json ()[0 ]["identifier" ] == identifier_three
94+ assert len (response .json ()[ "publication" ] ) == 1 , "Bob has ADMIN permission to one asset."
95+ assert response .json ()["publication" ][ 0 ]["identifier" ] == identifier_three
8696
8797
8898def test_my_resources_must_be_authorized (client : TestClient ) -> None :
0 commit comments