Skip to content

Commit 67421e9

Browse files
Daan Rosendalmdonadoni
authored andcommitted
feat(fixtures): add user1 and user2 fixtures (#113)
BREAKING CHANGE: This commit replaces the default_user fixture with user1 and user2 fixtures. The default_user fixture is now deprecated and will be removed in the next release. Related to reanahub/reana-client#680
1 parent 023adcf commit 67421e9

3 files changed

Lines changed: 87 additions & 20 deletions

File tree

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The list of contributors in alphabetical order:
44

55
- [Audrius Mecionis](https://orcid.org/0000-0002-3759-1663)
66
- [Camila Diaz](https://orcid.org/0000-0001-5543-797X)
7+
- [Daan Rosendal](https://orcid.org/0000-0002-3447-9000)
78
- [Diego Rodriguez](https://orcid.org/0000-0003-0649-2002)
89
- [Dinos Kousidis](https://orcid.org/0000-0002-4914-4289)
910
- [Giuseppe Steduto](https://orcid.org/0009-0002-1258-8553)

pytest_reana/fixtures.py

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,35 +120,99 @@ def create_ninja_turtle()
120120

121121

122122
@pytest.fixture()
123-
def default_user(app, session):
124-
"""Create users.
123+
def user0(app, session):
124+
"""Create admin user.
125125
126126
Scope: function
127127
128-
This fixture creates an user with a default UUID
129-
``00000000-0000-0000-0000-000000000000``, ``email`` `info@reana.io`
130-
and ``access_token`` ``secretkey`` and returns it.
128+
This fixture creates an admin user with a default UUID
129+
``00000000-0000-0000-0000-000000000000``, ``email`` `user0@reana.io`
130+
and ``access_token`` ``user0token`` and returns it.
131131
132132
.. code-block:: python
133133
134-
def test_default_user_exists(default)
134+
def test_user0_exists(default)
135135
with app.test_client() as client:
136136
res = client.post(url_for('api.get_users'),
137-
query_string={"user": default_user.id_})
137+
query_string={"user": user0.id_})
138138
139139
assert res.status_code == 200
140140
141141
142142
"""
143143
from reana_db.models import User
144144

145-
default_user_id = "00000000-0000-0000-0000-000000000000"
146-
user = User.query.filter_by(id_=default_user_id).first()
145+
user0_id = "00000000-0000-0000-0000-000000000000"
146+
user = User.query.filter_by(id_=user0_id).first()
147147
if not user:
148148
with patch("reana_db.database.Session", return_value=session):
149-
user = User(
150-
id_=default_user_id, email="info@reana.io", access_token="secretkey"
151-
)
149+
user = User(id_=user0_id, email="user0@reana.io", access_token="user0token")
150+
session.add(user)
151+
session.commit()
152+
return user
153+
154+
155+
@pytest.fixture()
156+
def user1(app, session):
157+
"""Create first regular user.
158+
159+
Scope: function
160+
161+
This fixture creates a user with UUID
162+
``11111111-1111-1111-1111-111111111111``, ``email`` `user1@reana.io`
163+
and ``access_token`` ``user1token`` and returns it.
164+
165+
.. code-block:: python
166+
167+
def test_user1_exists(default)
168+
with app.test_client() as client:
169+
res = client.post(url_for('api.get_users'),
170+
query_string={"user": user1.id_})
171+
172+
assert res.status_code == 200
173+
174+
175+
"""
176+
from reana_db.models import User
177+
178+
user1_id = "11111111-1111-1111-1111-111111111111"
179+
user = User.query.filter_by(id_=user1_id).first()
180+
if not user:
181+
with patch("reana_db.database.Session", return_value=session):
182+
user = User(id_=user1_id, email="user1@reana.io", access_token="user1token")
183+
session.add(user)
184+
session.commit()
185+
return user
186+
187+
188+
@pytest.fixture()
189+
def user2(app, session):
190+
"""Create second regular user.
191+
192+
Scope: function
193+
194+
This fixture creates a user with UUID
195+
``22222222-2222-2222-2222-222222222222``, ``email`` `user2@reana.io`
196+
and ``access_token`` ``user2token`` and returns it.
197+
198+
.. code-block:: python
199+
200+
def test_user2_exists(default)
201+
with app.test_client() as client:
202+
res = client.post(url_for('api.get_users'),
203+
query_string={"user": user2.id_})
204+
205+
assert res.status_code == 200
206+
207+
208+
"""
209+
from reana_db.models import User
210+
211+
user2_id = "22222222-2222-2222-2222-222222222222"
212+
user = User.query.filter_by(id_=user2_id).first()
213+
if not user:
214+
with patch("reana_db.database.Session", return_value=session):
215+
user = User(id_=user2_id, email="user2@reana.io", access_token="user2token")
152216
session.add(user)
153217
session.commit()
154218
return user
@@ -712,7 +776,7 @@ def _create_sample_workflow_workspace(relative_workspace_path):
712776
@pytest.fixture()
713777
def sample_yadage_workflow_in_db(
714778
app,
715-
default_user,
779+
user0,
716780
session,
717781
yadage_workflow_with_name,
718782
sample_workflow_workspace,
@@ -728,13 +792,13 @@ def sample_yadage_workflow_in_db(
728792

729793
workflow_id = uuid4()
730794
relative_workspace_path = build_workspace_path(
731-
default_user.id_, workflow_id, tmp_shared_volume_path
795+
user0.id_, workflow_id, tmp_shared_volume_path
732796
)
733797
next(sample_workflow_workspace(relative_workspace_path))
734798
workflow = Workflow(
735799
id_=workflow_id,
736800
name="sample_serial_workflow_1",
737-
owner_id=default_user.id_,
801+
owner_id=user0.id_,
738802
reana_specification=yadage_workflow_with_name["reana_specification"],
739803
operational_options={},
740804
type_=yadage_workflow_with_name["reana_specification"]["workflow"]["type"],
@@ -753,7 +817,7 @@ def sample_yadage_workflow_in_db(
753817
@pytest.fixture()
754818
def sample_serial_workflow_in_db(
755819
app,
756-
default_user,
820+
user0,
757821
session,
758822
serial_workflow,
759823
sample_workflow_workspace,
@@ -769,13 +833,13 @@ def sample_serial_workflow_in_db(
769833

770834
workflow_id = uuid4()
771835
relative_workspace_path = build_workspace_path(
772-
default_user.id_, workflow_id, tmp_shared_volume_path
836+
user0.id_, workflow_id, tmp_shared_volume_path
773837
)
774838
next(sample_workflow_workspace(relative_workspace_path))
775839
workflow = Workflow(
776840
id_=workflow_id,
777841
name="sample_serial_workflow_1",
778-
owner_id=default_user.id_,
842+
owner_id=user0.id_,
779843
reana_specification=serial_workflow["reana_specification"],
780844
operational_options={},
781845
type_=serial_workflow["reana_specification"]["workflow"]["type"],

pytest_reana/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
default_exchange,
2121
default_in_memory_producer,
2222
default_queue,
23-
default_user,
2423
empty_user_secrets,
2524
in_memory_queue_connection,
2625
kerberos_user_secrets,
@@ -32,8 +31,11 @@
3231
session,
3332
snakemake_workflow_spec_loaded,
3433
tmp_shared_volume_path,
34+
user0,
35+
user1,
36+
user2,
3537
user_secrets,
38+
yadage_workflow_spec_loaded,
3639
yadage_workflow_with_name,
3740
yadage_workflow_without_name,
38-
yadage_workflow_spec_loaded,
3941
)

0 commit comments

Comments
 (0)