Skip to content

Commit 1dcf321

Browse files
authored
Merge pull request #106 from equinor/testing-parameters
Testing parameters
2 parents 9ec5a19 + 3812645 commit 1dcf321

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def pytest_addoption(parser):
2+
parser.addoption("--token", action="store", default="")
3+
4+
def pytest_generate_tests(metafunc):
5+
token = metafunc.config.option.token
6+
token = token if len(token) > 0 else None
7+
8+
if "token" in metafunc.fixturenames:
9+
metafunc.parametrize("token", [token])

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ requests~=2.24.0
33
pytest~=6.1.1
44
PyYAML>=5.4
55
setuptools~=49.2.1
6+
pyjwt>=2.4.0

src/sumo/wrapper/_request_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, code, message):
3939
def __str__(self):
4040
return (
4141
f"Fatal Request Error with status code {self.code} "
42-
"and text {self.message}."
42+
f"and text {self.message}."
4343
)
4444

4545

tests/test_sumo_thin_client.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313

1414
class Connection:
15-
def __init__(self):
16-
self.api = SumoClient(env="dev")
15+
def __init__(self, token):
16+
self.api = SumoClient(env="dev", token=token)
1717

1818

1919
def _upload_parent_object(C, json):
@@ -25,7 +25,7 @@ def _upload_parent_object(C, json):
2525

2626

2727
def _upload_blob(C, blob, url=None, object_id=None):
28-
response = C.api.put(f"/objects('{object_id}')/blob", blob=blob)
28+
response = C.api.blob_client.upload_blob(blob=blob, url=url)
2929

3030
print("Blob save " + str(response.status_code), flush=True)
3131
if not 200 <= response.status_code < 202:
@@ -76,15 +76,15 @@ class ValueKeeper:
7676
""" TESTS """
7777

7878

79-
def test_upload_search_delete_ensemble_child():
79+
def test_upload_search_delete_ensemble_child(token):
8080
"""
8181
Testing the wrapper functionalities.
8282
8383
We upload an ensemble object along with a child. After that, we search for
8484
those objects to make sure they are available to the user. We then delete
8585
them and repeat the search to check if they were properly removed from sumo.
8686
"""
87-
C = Connection()
87+
C = Connection(token)
8888
B = b"123456789"
8989

9090
# Upload Ensemble
@@ -113,9 +113,10 @@ def test_upload_search_delete_ensemble_child():
113113
assert isinstance(response_surface.json(), dict)
114114

115115
surface_id = response_surface.json().get("objectid")
116+
blob_url = response_surface.json().get("blob_url")
116117

117118
# Upload BLOB
118-
response_blob = _upload_blob(C=C, blob=B, object_id=surface_id)
119+
response_blob = _upload_blob(C=C, blob=B, url=blob_url, object_id=surface_id)
119120
assert 200 <= response_blob.status_code <= 202
120121

121122
sleep(4)
@@ -161,20 +162,20 @@ def test_upload_search_delete_ensemble_child():
161162
assert total == 0
162163

163164

164-
def test_fail_on_wrong_metadata():
165+
def test_fail_on_wrong_metadata(token):
165166
"""
166167
Upload a parent object with erroneous metadata, confirm failure
167168
"""
168-
C = Connection()
169+
C = Connection(token)
169170
with pytest.raises(Exception):
170171
assert _upload_parent_object(C=C, json={"some field": "some value"})
171172

172173

173-
def test_upload_duplicate_ensemble():
174+
def test_upload_duplicate_ensemble(token):
174175
"""
175176
Adding a duplicate ensemble, both tries must return same id.
176177
"""
177-
C = Connection()
178+
C = Connection(token)
178179

179180
with open("tests/testdata/case.yml", "r") as stream:
180181
fmu_metadata1 = yaml.safe_load(stream)

0 commit comments

Comments
 (0)