Skip to content

Commit fc55ef9

Browse files
Fix test typing and fixture usage
1 parent 7664ced commit fc55ef9

15 files changed

+92
-65
lines changed

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def default_nodes():
174174

175175
@pytest.fixture(scope='function')
176176
def array_data_node():
177-
"""Populate database with downloadable node (implmenting a _prepare_* function)."""
177+
"""Populate database with downloadable node (implementing a _prepare_* function)."""
178178

179179
return orm.ArrayData(np.arange(4)).store()
180180

@@ -213,7 +213,7 @@ def mutate_mapping(
213213

214214
@pytest.fixture
215215
def orm_regression(data_regression):
216-
"""A variant of data_regression.check, that replaces nondetermistic fields (like uuid)."""
216+
"""A variant of data_regression.check, that replaces non-deterministic fields (like uuid)."""
217217

218218
def _func(
219219
data: dict,
@@ -289,7 +289,7 @@ def _func(
289289
level_name: str = 'level 1',
290290
message='',
291291
node: Optional[orm.nodes.Node] = None,
292-
) -> orm.Comment:
292+
) -> orm.Log:
293293
orm_node = node or orm.Data().store()
294294
return orm.Log(datetime.now(pytz.UTC), loggername, level_name, orm_node.pk, message=message).store()
295295

tests/test_auth.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
from fastapi.testclient import TestClient
44

5-
from aiida_restapi import app
65

7-
client = TestClient(app)
8-
9-
10-
def test_authenticate_user():
6+
def test_authenticate_user(client: TestClient):
117
"""Test authenticating as a user."""
128
# authenticate with username and password
139
response = client.post('/token', data={'username': 'johndoe@example.com', 'password': 'secret'})

tests/test_computers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
"""Test the /computers endpoint"""
22

3+
import pytest
34
from aiida import orm
5+
from fastapi.testclient import TestClient
46

57

6-
def test_get_computer_projectable_properties(client):
8+
def test_get_computer_projectable_properties(client: TestClient):
79
"""Test get projectable properties for computer."""
810
response = client.get('/computers/projectable_properties')
911
assert response.status_code == 200
1012
assert response.json() == sorted(orm.Computer.fields.keys())
1113

1214

13-
def test_get_computers(default_computers, client): # pylint: disable=unused-argument
15+
@pytest.mark.usefixtures('default_computers')
16+
def test_get_computers(client: TestClient):
1417
"""Test listing existing computer."""
1518
response = client.get('/computers/')
1619
assert response.status_code == 200
1720
assert len(response.json()['results']) == 2
1821

1922

20-
def test_get_computer(default_computers, client): # pylint: disable=unused-argument
23+
def test_get_computer(client: TestClient, default_computers):
2124
"""Test retrieving a single computer."""
2225
for comp_id in default_computers:
2326
response = client.get(f'/computers/{comp_id}')
2427
assert response.status_code == 200
2528

2629

27-
def test_create_computer(client, authenticate): # pylint: disable=unused-argument
30+
@pytest.mark.usefixtures('authenticate')
31+
def test_create_computer(client: TestClient):
2832
"""Test creating a new computer."""
2933
response = client.post(
3034
'/computers',

tests/test_daemon.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
import pytest
44
from fastapi.testclient import TestClient
55

6-
from aiida_restapi import app
7-
8-
client = TestClient(app)
9-
106

117
@pytest.mark.usefixtures('stopped_daemon_client', 'authenticate')
12-
def test_status_and_start():
8+
def test_status_and_start(client: TestClient):
139
"""Test ``/daemon/status`` when the daemon is not running and ``/daemon/start``."""
1410
response = client.get('/daemon/status')
1511
assert response.status_code == 200, response.content
@@ -30,7 +26,7 @@ def test_status_and_start():
3026

3127

3228
@pytest.mark.usefixtures('started_daemon_client', 'authenticate')
33-
def test_status_and_stop():
29+
def test_status_and_stop(client: TestClient):
3430
"""Test ``/daemon/status`` when the daemon is running and ``/daemon/stop``."""
3531
response = client.get('/daemon/status')
3632
assert response.status_code == 200, response.content

tests/test_graphql/test_comments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_comment(create_comment, orm_regression):
1313
fields = field_names_from_orm(type(comment))
1414
schema = create_schema([CommentQueryPlugin])
1515
client = Client(schema)
16-
executed = client.execute('{ comment(id: %r) { %s } }' % (comment.id, ' '.join(fields)))
16+
executed = client.execute('{ comment(id: %r) { %s } }' % (comment.pk, ' '.join(fields)))
1717
orm_regression(executed)
1818

1919

tests/test_graphql/test_computers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_computer(create_computer, orm_regression):
1313
fields = field_names_from_orm(type(computer))
1414
schema = create_schema([ComputerQueryPlugin])
1515
client = Client(schema)
16-
executed = client.execute('{ computer(id: %r) { %s } }' % (computer.id, ' '.join(fields)))
16+
executed = client.execute('{ computer(id: %r) { %s } }' % (computer.pk, ' '.join(fields)))
1717
orm_regression(executed)
1818

1919

@@ -24,7 +24,7 @@ def test_computer_nodes(create_computer, create_node, orm_regression):
2424
create_node(label='node 2', computer=computer)
2525
schema = create_schema([ComputerQueryPlugin])
2626
client = Client(schema)
27-
executed = client.execute('{ computer(id: %r) { nodes { count rows{ label } } } }' % (computer.id))
27+
executed = client.execute('{ computer(id: %r) { nodes { count rows{ label } } } }' % (computer.pk))
2828
orm_regression(executed)
2929

3030

tests/test_graphql/test_full.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ def test_full(create_node, orm_regression):
99
"""Test loading the full schema."""
1010
node = create_node(label='node 1')
1111
client = Client(SCHEMA)
12-
executed = client.execute('{ aiidaVersion node(id: %r) { label } }' % (node.id))
12+
executed = client.execute('{ aiidaVersion node(id: %r) { label } }' % (node.pk))
1313
orm_regression(executed)

tests/test_graphql/test_groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_group(create_group, orm_regression):
1313
fields = field_names_from_orm(type(group))
1414
schema = create_schema([GroupQueryPlugin])
1515
client = Client(schema)
16-
executed = client.execute('{ group(id: %r) { %s } }' % (group.id, ' '.join(fields)))
16+
executed = client.execute('{ group(id: %r) { %s } }' % (group.pk, ' '.join(fields)))
1717
orm_regression(executed)
1818

1919

@@ -34,7 +34,7 @@ def test_group_nodes(create_group, create_node, orm_regression):
3434
group.add_nodes([create_node(label='node 1'), create_node(label='node 2')])
3535
schema = create_schema([GroupQueryPlugin])
3636
client = Client(schema)
37-
executed = client.execute('{ group(id: %r) { nodes { count rows{ label } } } }' % (group.id))
37+
executed = client.execute('{ group(id: %r) { nodes { count rows{ label } } } }' % (group.pk))
3838
orm_regression(executed)
3939

4040

tests/test_graphql/test_logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_log(create_log, orm_regression):
1313
fields = field_names_from_orm(type(log))
1414
schema = create_schema([LogQueryPlugin])
1515
client = Client(schema)
16-
executed = client.execute('{ log(id: %r) { %s } }' % (log.id, ' '.join(fields)))
16+
executed = client.execute('{ log(id: %r) { %s } }' % (log.pk, ' '.join(fields)))
1717
orm_regression(executed)
1818

1919

tests/test_graphql/test_nodes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_node(create_node, orm_regression):
1414
fields = field_names_from_orm(type(node))
1515
schema = create_schema([NodeQueryPlugin])
1616
client = Client(schema)
17-
executed = client.execute('{ node(id: %r) { %s } }' % (node.id, ' '.join(fields)))
17+
executed = client.execute('{ node(id: %r) { %s } }' % (node.pk, ' '.join(fields)))
1818
orm_regression(executed)
1919

2020

@@ -25,7 +25,7 @@ def test_node_logs(create_node, create_log, orm_regression):
2525
create_log(message='log 2', node=node)
2626
schema = create_schema([NodeQueryPlugin])
2727
client = Client(schema)
28-
executed = client.execute('{ node(id: %r) { logs { count rows{ message } } } }' % (node.id))
28+
executed = client.execute('{ node(id: %r) { logs { count rows{ message } } } }' % (node.pk))
2929
orm_regression(executed)
3030

3131

@@ -36,7 +36,7 @@ def test_node_comments(create_node, create_comment, orm_regression):
3636
create_comment(content='comment 2', node=node)
3737
schema = create_schema([NodeQueryPlugin])
3838
client = Client(schema)
39-
executed = client.execute('{ node(id: %r) { comments { count rows{ content } } } }' % (node.id))
39+
executed = client.execute('{ node(id: %r) { comments { count rows{ content } } } }' % (node.pk))
4040
orm_regression(executed)
4141

4242

@@ -53,7 +53,7 @@ def test_node_incoming(create_node, orm_regression):
5353
schema = create_schema([NodeQueryPlugin])
5454
client = Client(schema)
5555
executed = client.execute(
56-
'{ node(id: %r) { incoming { count rows{ node { label } link { label type } } } } }' % (node.id)
56+
'{ node(id: %r) { incoming { count rows{ node { label } link { label type } } } } }' % (node.pk)
5757
)
5858
orm_regression(executed)
5959

@@ -72,7 +72,7 @@ def test_node_outgoing(create_node, orm_regression):
7272
schema = create_schema([NodeQueryPlugin])
7373
client = Client(schema)
7474
executed = client.execute(
75-
'{ node(id: %r) { outgoing { count rows{ node { label } link { label type } } } } }' % (node.id)
75+
'{ node(id: %r) { outgoing { count rows{ node { label } link { label type } } } } }' % (node.pk)
7676
)
7777
orm_regression(executed)
7878

@@ -89,7 +89,7 @@ def test_node_ancestors(create_node, orm_regression):
8989

9090
schema = create_schema([NodeQueryPlugin])
9191
client = Client(schema)
92-
executed = client.execute('{ node(id: %r) { ancestors { count rows{ label } } } }' % (node.id))
92+
executed = client.execute('{ node(id: %r) { ancestors { count rows{ label } } } }' % (node.pk))
9393
orm_regression(executed)
9494

9595

@@ -106,7 +106,7 @@ def test_node_descendants(create_node, orm_regression):
106106

107107
schema = create_schema([NodeQueryPlugin])
108108
client = Client(schema)
109-
executed = client.execute('{ node(id: %r) { descendants { count rows{ label } } } }' % (node.id))
109+
executed = client.execute('{ node(id: %r) { descendants { count rows{ label } } } }' % (node.pk))
110110
orm_regression(executed)
111111

112112

0 commit comments

Comments
 (0)