Skip to content

Commit 39fdd0e

Browse files
committed
Convert bookmark tests to use fixture data
1 parent a5edcee commit 39fdd0e

File tree

5 files changed

+117
-77
lines changed

5 files changed

+117
-77
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trim_trailing_whitespace = true
1313
[*.md]
1414
trim_trailing_whitespace = false
1515

16-
[*.{json,yml}]
16+
[*.{json,yml,yaml}]
1717
indent_size = 2
1818

1919
[Makefile]

globus_cli/services/transfer.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ class RetryingTransferClient(TransferClient):
2525
Wrapper around TransferClient that retries safe resources on NetworkErrors
2626
"""
2727

28-
def __init__(self, tries=10, *args, **kwargs):
28+
default_retries = 10
29+
30+
def __init__(self, tries=None, *args, **kwargs):
2931
super(RetryingTransferClient, self).__init__(*args, **kwargs)
30-
self.tries = tries
32+
self.tries = tries or self.default_retries
3133

3234
def retry(self, f, *args, **kwargs):
3335
"""
@@ -124,9 +126,7 @@ def get_client():
124126
on_refresh=_update_tokens,
125127
)
126128

127-
return RetryingTransferClient(
128-
tries=10, authorizer=authorizer, app_name=version.app_name
129-
)
129+
return RetryingTransferClient(authorizer=authorizer, app_name=version.app_name)
130130

131131

132132
def display_name_or_cname(ep_doc):

tests/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ruamel.yaml import YAML
1111

1212
from globus_cli.services.auth import get_auth_client
13+
from globus_cli.services.transfer import RetryingTransferClient
1314
from globus_cli.services.transfer import get_client as get_transfer_client
1415
from tests.constants import GO_EP1_ID, GO_EP2_ID
1516
from tests.utils import patch_config
@@ -162,3 +163,9 @@ def func(filename):
162163
return data
163164

164165
return func
166+
167+
168+
@pytest.fixture(autouse=True)
169+
def _reduce_transfer_client_retries(monkeypatch):
170+
"""to make tests fail faster on network errors"""
171+
monkeypatch.setattr(RetryingTransferClient, "default_retries", 1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
metadata:
2+
bookmark_id: "1405823f-0597-4a16-b296-46d4f0ae4b15"
3+
bookmark_name: sharebm
4+
bookmark_name_after_update: updated_sharebm
5+
6+
transfer:
7+
/bookmark:
8+
post:
9+
json:
10+
{
11+
"DATA_TYPE": "bookmark",
12+
"id": "1405823f-0597-4a16-b296-46d4f0ae4b15",
13+
"name": "sharebm",
14+
"endpoint_id": "ddb59aef-6d04-11e5-ba46-22000b92c6ec",
15+
"path": "/share/"
16+
}
17+
/bookmark/1405823f-0597-4a16-b296-46d4f0ae4b15:
18+
get:
19+
json:
20+
{
21+
"DATA_TYPE": "bookmark",
22+
"id": "1405823f-0597-4a16-b296-46d4f0ae4b15",
23+
"name": "sharebm",
24+
"endpoint_id": "ddb59aef-6d04-11e5-ba46-22000b92c6ec",
25+
"path": "/share/"
26+
}
27+
put:
28+
json:
29+
{
30+
"DATA_TYPE": "bookmark",
31+
"id": "1405823f-0597-4a16-b296-46d4f0ae4b15",
32+
"name": "updated_sharebm",
33+
"endpoint_id": "ddb59aef-6d04-11e5-ba46-22000b92c6ec",
34+
"path": "/share/"
35+
}
36+
delete:
37+
json:
38+
{
39+
"DATA_TYPE": "result",
40+
"code": "Deleted",
41+
"message": "Bookmark '1405823f-0597-4a16-b296-46d4f0ae4b15' deleted successfully",
42+
"resource": "/bookmark/a624df8b",
43+
"request_id": "ABCdef789"
44+
}
45+
/bookmark_list:
46+
get:
47+
json:
48+
{
49+
"DATA_TYPE": "bookmark_list",
50+
"DATA": [
51+
{
52+
"DATA_TYPE": "bookmark",
53+
"id": "1405823f-0597-4a16-b296-46d4f0ae4b15",
54+
"name": "sharebm",
55+
"endpoint_id": "ddb59aef-6d04-11e5-ba46-22000b92c6ec",
56+
"path": "/share/"
57+
}
58+
]
59+
}
+45-71
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,94 @@
11
import json
2-
import uuid
3-
4-
import pytest
52

63
from tests.constants import GO_EP1_ID
74

85

9-
@pytest.fixture
10-
def gen_bookmark_name(created_bookmark_names):
11-
def f(name=""):
12-
if name:
13-
name = name + "-"
14-
bmname = "{}{}".format(name, str(uuid.uuid1()))
15-
created_bookmark_names.append(bmname)
16-
return bmname
17-
18-
return f
19-
20-
21-
@pytest.fixture
22-
def bookmark1(gen_bookmark_name, tc):
23-
bm1name = gen_bookmark_name(name="bm1")
24-
res = tc.create_bookmark(
25-
{"endpoint_id": GO_EP1_ID, "path": "/home/", "name": bm1name}
26-
)
27-
bm1id = res["id"]
28-
return (bm1name, bm1id)
29-
30-
31-
@pytest.fixture
32-
def bm1name(bookmark1):
33-
return bookmark1[0]
34-
35-
36-
@pytest.fixture
37-
def bm1id(bookmark1):
38-
return bookmark1[1]
39-
40-
41-
def test_bookmark_create(gen_bookmark_name, run_line):
6+
def test_bookmark_create(run_line, load_api_fixtures):
427
"""
438
Runs bookmark create, confirms simple things about text and json output
449
"""
45-
result = run_line(
46-
("globus bookmark create " "{}:{} {}").format(
47-
GO_EP1_ID, "/share/", gen_bookmark_name(name="sharebm")
48-
)
49-
)
50-
assert "Bookmark ID: " in result.output
10+
data = load_api_fixtures("bookmark_operations.yaml")
11+
bookmark_id = data["metadata"]["bookmark_id"]
12+
result = run_line("globus bookmark create {}:/share/ sharebm".format(GO_EP1_ID))
13+
assert "Bookmark ID: {}".format(bookmark_id) in result.output
5114

52-
bm2name = gen_bookmark_name(name="share bookmark 2")
15+
# repeat, but with JSON output
5316
json_output = json.loads(
5417
run_line(
55-
('globus bookmark create -F json {}:{} "{}"').format(
56-
GO_EP1_ID, "/share/dne/", bm2name
57-
)
18+
"globus bookmark create -Fjson {}:/share/ sharebm".format(GO_EP1_ID)
5819
).output
5920
)
60-
assert json_output["name"] == bm2name
61-
assert json_output["path"] == "/share/dne/"
21+
assert json_output["id"] == bookmark_id
22+
assert json_output["name"] == "sharebm"
23+
assert json_output["path"] == "/share/"
6224
assert json_output["endpoint_id"] == GO_EP1_ID
6325

6426

65-
def test_bookmark_show(gen_bookmark_name, bm1name, bm1id, run_line):
27+
def test_bookmark_show(run_line, load_api_fixtures):
6628
"""
6729
Runs bookmark show on bm1's name and id.
6830
Confirms both inputs work, and verbose output is as expected.
6931
"""
32+
data = load_api_fixtures("bookmark_operations.yaml")
33+
bookmark_id = data["metadata"]["bookmark_id"]
34+
bookmark_name = data["metadata"]["bookmark_name"]
35+
7036
# id
71-
result = run_line('globus bookmark show "{}"'.format(bm1id))
72-
assert "{}:/home/\n".format(GO_EP1_ID) == result.output
37+
result = run_line('globus bookmark show "{}"'.format(bookmark_id))
38+
assert "{}:/share/\n".format(GO_EP1_ID) == result.output
7339

7440
# name
75-
result = run_line('globus bookmark show "{}"'.format(bm1name))
76-
assert "{}:/home/\n".format(GO_EP1_ID) == result.output
41+
result = run_line('globus bookmark show "{}"'.format(bookmark_name))
42+
assert "{}:/share/\n".format(GO_EP1_ID) == result.output
7743

7844
# verbose
79-
result = run_line("globus bookmark show -v {}".format(bm1id))
45+
result = run_line("globus bookmark show -v {}".format(bookmark_id))
8046
assert "Endpoint ID: {}".format(GO_EP1_ID) in result.output
8147

8248

83-
def test_bookmark_rename_by_id(gen_bookmark_name, run_line, bm1id):
49+
def test_bookmark_rename_by_id(run_line, load_api_fixtures):
8450
"""
85-
Runs bookmark rename on bm1's id. Confirms can be shown by new name.
51+
Runs bookmark rename on bm1's id.
8652
"""
87-
new_name = gen_bookmark_name(name="new_bm1")
88-
result = run_line('globus bookmark rename "{}" "{}"'.format(bm1id, new_name))
89-
assert "Success" in result.output
53+
data = load_api_fixtures("bookmark_operations.yaml")
54+
bookmark_id = data["metadata"]["bookmark_id"]
55+
updated_bookmark_name = data["metadata"]["bookmark_name_after_update"]
9056

91-
result = run_line('globus bookmark show -v "{}"'.format(new_name))
92-
assert "ID: {}".format(bm1id) in result.output
57+
result = run_line(
58+
'globus bookmark rename "{}" "{}"'.format(bookmark_id, updated_bookmark_name)
59+
)
60+
assert "Success" in result.output
9361

9462

95-
def test_bookmark_rename_by_name(gen_bookmark_name, run_line, bm1name, bm1id):
63+
def test_bookmark_rename_by_name(run_line, load_api_fixtures):
9664
"""
9765
Runs bookmark rename on bm1's name. Confirms can be shown by new name.
9866
"""
99-
new_name = gen_bookmark_name(name="new_bm1")
100-
result = run_line('globus bookmark rename "{}" "{}"'.format(bm1name, new_name))
101-
assert "Success" in result.output
67+
data = load_api_fixtures("bookmark_operations.yaml")
68+
bookmark_name = data["metadata"]["bookmark_name"]
69+
updated_bookmark_name = data["metadata"]["bookmark_name_after_update"]
10270

103-
result = run_line('globus bookmark show -v "{}"'.format(new_name))
104-
assert "ID: {}".format(bm1id) in result.output
71+
result = run_line(
72+
'globus bookmark rename "{}" "{}"'.format(bookmark_name, updated_bookmark_name)
73+
)
74+
assert "Success" in result.output
10575

10676

107-
def test_bookmark_delete_by_id(gen_bookmark_name, run_line, bm1id):
77+
def test_bookmark_delete_by_id(run_line, load_api_fixtures):
10878
"""
10979
Runs bookmark delete on bm1's id. Confirms success message.
11080
"""
111-
result = run_line('globus bookmark delete "{}"'.format(bm1id))
81+
data = load_api_fixtures("bookmark_operations.yaml")
82+
bookmark_id = data["metadata"]["bookmark_id"]
83+
result = run_line('globus bookmark delete "{}"'.format(bookmark_id))
11284
assert "deleted successfully" in result.output
11385

11486

115-
def test_bookmark_delete_by_name(gen_bookmark_name, run_line, bm1name):
87+
def test_bookmark_delete_by_name(run_line, load_api_fixtures):
11688
"""
11789
Runs bookmark delete on bm1's name. Confirms success message.
11890
"""
119-
result = run_line('globus bookmark delete "{}"'.format(bm1name))
91+
data = load_api_fixtures("bookmark_operations.yaml")
92+
bookmark_name = data["metadata"]["bookmark_name"]
93+
result = run_line('globus bookmark delete "{}"'.format(bookmark_name))
12094
assert "deleted successfully" in result.output

0 commit comments

Comments
 (0)