Skip to content

Commit 523db63

Browse files
committed
[FLPY-37] Added mock responses for shared account and tests
1 parent 2e81e58 commit 523db63

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

flow360/cli/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def flow360():
5454
is_flag=True,
5555
help='Always prompt for confirmation for "submit()" when creating new resources while logged into a shared account',
5656
)
57+
# pylint: disable=too-many-arguments
5758
def configure(
5859
apikey,
5960
profile,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"data": {
3+
"credit": 100000000000.0,
4+
"s3Usage": 0,
5+
"totalTaskCount": 0,
6+
"monthlyTaskCount": 0,
7+
"creditExpiration": "2029-05-31T07:28:31.829Z",
8+
"accountType": "tenant",
9+
"tenantId": "0000000-0000-0000-0000-000000000000",
10+
"tenantName": "Test",
11+
"clientAdmin": true,
12+
"allowanceCurrentCycleAmount": null,
13+
"allowanceCurrentCycleTotalAmount": null,
14+
"allowanceCurrentCycleStartDate": null,
15+
"allowanceCurrentCycleEndDate": null,
16+
"allowanceNextCycleStartDate": null,
17+
"allowanceAllCycleStartDate": null,
18+
"allowanceAllCycleEndDate": null,
19+
"tenantMembers": [
20+
{"userIdentity": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "userId": "AAAAAAAAAAAAAAAAAAAAA", "userEmail": "user1@test.com"},
21+
{"userIdentity": "us-east-1:bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", "userId": "BBBBBBBBBBBBBBBBBBBBB", "userEmail": "user2@test.com"}],
22+
"intraCompanySharingEnabled": true,
23+
"taskDeInfo": null,
24+
"userId": "ABCDEFGHIJKLMNOPRSTUV",
25+
"internal": true
26+
}
27+
}
28+

tests/mock_server.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ def json():
7575
return res
7676

7777

78+
class MockResponseOrganizationAccounts(MockResponse):
79+
"""response to retrieving shared account list"""
80+
81+
@staticmethod
82+
def json():
83+
with open(os.path.join(here, "data/mock_webapi/organization_accounts_resp.json")) as fh:
84+
res = json.load(fh)
85+
return res
86+
87+
7888
class MockResponseCase(MockResponse):
7989
"""response if Case(id="00000000-0000-0000-0000-000000000000")"""
8090

@@ -136,6 +146,7 @@ def json():
136146
"/cases/00112233-4455-6677-8899-bbbbbbbbbbbb/runtimeParams": MockResponseCaseRuntimeParams,
137147
"/cases/c58e7a75-e349-476a-9020-247af6b2e92b": MockResponseCase,
138148
"-python-client-v2": MockResponseVersions,
149+
"/account": MockResponseOrganizationAccounts,
139150
}
140151

141152

tests/test_shared_accounts.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import pytest
22

3-
import flow360 as fl
3+
from flow360 import Accounts, Env
44

5+
from .mock_server import mock_response
56

6-
def test_shared_account():
7-
pass
7+
8+
def test_shared_account(mock_response):
9+
Accounts.choose_shared_account("user1@test.com")
10+
11+
assert Accounts.shared_account_info() == "user1@test.com"
12+
assert Env.impersonate == "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
13+
14+
Accounts.leave_shared_account()
15+
16+
assert Accounts.shared_account_info() is None
17+
assert Env.impersonate is None
18+
19+
with pytest.raises(ValueError):
20+
Accounts.choose_shared_account("user3@test.com")

0 commit comments

Comments
 (0)