Skip to content

Commit ad8d557

Browse files
committed
test: Use module scope to separate fixtures
1 parent 118fb5d commit ad8d557

File tree

4 files changed

+22
-83
lines changed

4 files changed

+22
-83
lines changed

graphene_mongo/tests/fixtures.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import pytest
12
from .models import (
23
Article, Editor, EmbeddedArticle, Player,
34
Reporter, Child, ProfessorMetadata, ProfessorVector,
45
)
56

6-
7+
@pytest.fixture(scope='module')
78
def setup_fixtures():
9+
print('setup_fixtures')
810
Editor.drop_collection()
911
editor1 = Editor(
1012
id='1',

graphene_mongo/tests/test_mutation.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
from .types import (ArticleNode, EditorNode)
88

99

10-
setup_fixtures()
11-
12-
13-
def test_should_create():
10+
def test_should_create(setup_fixtures):
1411

1512
class CreateArticle(graphene.Mutation):
1613

@@ -60,7 +57,7 @@ class Mutation(graphene.ObjectType):
6057
assert result.data == expected
6158

6259

63-
def test_should_update():
60+
def test_should_update(setup_fixtures):
6461

6562
class UpdateEditor(graphene.Mutation):
6663

@@ -71,7 +68,6 @@ class Arguments:
7168
editor = graphene.Field(EditorNode)
7269

7370
def mutate(self, info, id, first_name):
74-
print(id, first_name)
7571
editor = Editor.objects.get(id=id)
7672
editor.first_name = first_name
7773
editor.save()

graphene_mongo/tests/test_query.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
EditorType, PlayerType, ReporterType, ProfessorVectorType
1111
)
1212

13-
setup_fixtures()
1413

15-
16-
def test_should_query_editor():
14+
def test_should_query_editor(setup_fixtures):
1715

1816
class Query(graphene.ObjectType):
1917

@@ -65,7 +63,7 @@ def resolve_editors(self, *args, **kwargs):
6563
assert all(item in result.data['editors'] for item in expected['editors'])
6664

6765

68-
def test_should_query_reporter():
66+
def test_should_query_reporter(setup_fixtures):
6967

7068
class Query(graphene.ObjectType):
7169
reporter = graphene.Field(ReporterType)
@@ -127,7 +125,7 @@ def resolve_reporter(self, *args, **kwargs):
127125
assert dict(result.data['reporter']) == expected['reporter']
128126

129127

130-
def test_should_custom_kwargs():
128+
def test_should_custom_kwargs(setup_fixtures):
131129

132130
class Query(graphene.ObjectType):
133131

@@ -165,7 +163,7 @@ def resolve_editors(self, *args, **kwargs):
165163
assert all(item in result.data['editors'] for item in expected['editors'])
166164

167165

168-
def test_should_self_reference():
166+
def test_should_self_reference(setup_fixtures):
169167

170168
class Query(graphene.ObjectType):
171169

@@ -229,7 +227,7 @@ def resolve_all_players(self, *args, **kwargs):
229227
assert json.dumps(result.data, sort_keys=True) == json.dumps(expected, sort_keys=True)
230228

231229

232-
def test_should_query_with_embedded_document():
230+
def test_should_query_with_embedded_document(setup_fixtures):
233231

234232
class Query(graphene.ObjectType):
235233
professor_vector = graphene.Field(ProfessorVectorType, id=graphene.String())

graphene_mongo/tests/test_relay_query.py

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
ChildNode,)
1414
from ..fields import MongoengineConnectionField
1515

16-
setup_fixtures()
17-
1816

1917
def get_nodes(data, key):
2018
return map(lambda edge: edge['node'], data[key]['edges'])
2119

2220

23-
def test_should_query_reporter():
21+
def test_should_query_reporter(setup_fixtures):
2422

2523
class Query(graphene.ObjectType):
2624
node = Node.Field()
@@ -115,7 +113,7 @@ def resolve_reporter(self, *args, **kwargs):
115113
assert dict(result.data['reporter']) == expected['reporter']
116114

117115

118-
def test_should_query_all_editors():
116+
def test_should_query_all_editors(setup_fixtures):
119117

120118
class Query(graphene.ObjectType):
121119
node = Node.Field()
@@ -168,7 +166,7 @@ class Query(graphene.ObjectType):
168166
assert dict(result.data['allEditors']) == expected['allEditors']
169167

170168

171-
def test_should_filter_editors_by_id():
169+
def test_should_filter_editors_by_id(setup_fixtures):
172170

173171
class Query(graphene.ObjectType):
174172
node = Node.Field()
@@ -207,57 +205,7 @@ class Query(graphene.ObjectType):
207205
assert dict(result.data['allEditors']) == expected['allEditors']
208206

209207

210-
def test_should_mutate():
211-
212-
class CreateArticle(graphene.Mutation):
213-
214-
class Arguments:
215-
216-
headline = graphene.String()
217-
218-
article = graphene.Field(ArticleNode)
219-
220-
def mutate(self, info, headline):
221-
article = Article(
222-
headline=headline
223-
)
224-
article.save()
225-
226-
return CreateArticle(article=article)
227-
228-
class Query(graphene.ObjectType):
229-
230-
node = Node.Field()
231-
232-
class Mutation(graphene.ObjectType):
233-
234-
create_article = CreateArticle.Field()
235-
236-
query = '''
237-
mutation ArticleCreator {
238-
createArticle(
239-
headline: "My Article"
240-
) {
241-
article {
242-
headline
243-
}
244-
}
245-
}
246-
'''
247-
expected = {
248-
'createArticle': {
249-
'article': {
250-
'headline': 'My Article'
251-
}
252-
}
253-
}
254-
schema = graphene.Schema(query=Query, mutation=Mutation)
255-
result = schema.execute(query)
256-
assert not result.errors
257-
assert result.data == expected
258-
259-
260-
def test_should_filter():
208+
def test_should_filter(setup_fixtures):
261209

262210
class Query(graphene.ObjectType):
263211
node = Node.Field()
@@ -297,7 +245,7 @@ class Query(graphene.ObjectType):
297245
assert result.data == expected
298246

299247

300-
def test_should_filter_by_reference_field():
248+
def test_should_filter_by_reference_field(setup_fixtures):
301249

302250
class Query(graphene.ObjectType):
303251
node = Node.Field()
@@ -337,7 +285,7 @@ class Query(graphene.ObjectType):
337285
assert result.data == expected
338286

339287

340-
def test_should_filter_through_inheritance():
288+
def test_should_filter_through_inheritance(setup_fixtures):
341289

342290
class Query(graphene.ObjectType):
343291
node = Node.Field()
@@ -374,7 +322,7 @@ class Query(graphene.ObjectType):
374322
expected, sort_keys=True)
375323

376324

377-
def test_should_get_node_by_id():
325+
def test_should_get_node_by_id(setup_fixtures):
378326
# Notes: https://goo.gl/hMNRgs
379327
class Query(graphene.ObjectType):
380328
reporter = Node.Field(ReporterNode)
@@ -400,7 +348,7 @@ class Query(graphene.ObjectType):
400348
assert result.data == expected
401349

402350

403-
def test_should_first_n():
351+
def test_should_first_n(setup_fixtures):
404352

405353
class Query(graphene.ObjectType):
406354

@@ -456,7 +404,7 @@ class Query(graphene.ObjectType):
456404
for item in get_nodes(expected, 'editors'))
457405

458406

459-
def test_should_after():
407+
def test_should_after(setup_fixtures):
460408
class Query(graphene.ObjectType):
461409

462410
players = MongoengineConnectionField(PlayerNode)
@@ -499,7 +447,7 @@ class Query(graphene.ObjectType):
499447
expected, sort_keys=True)
500448

501449

502-
def test_should_before():
450+
def test_should_before(setup_fixtures):
503451
class Query(graphene.ObjectType):
504452

505453
players = MongoengineConnectionField(PlayerNode)
@@ -542,7 +490,7 @@ class Query(graphene.ObjectType):
542490
expected, sort_keys=True)
543491

544492

545-
def test_should_last_n():
493+
def test_should_last_n(setup_fixtures):
546494
class Query(graphene.ObjectType):
547495
players = MongoengineConnectionField(PlayerNode)
548496

@@ -584,7 +532,7 @@ class Query(graphene.ObjectType):
584532
expected, sort_keys=True)
585533

586534

587-
def test_should_self_reference():
535+
def test_should_self_reference(setup_fixtures):
588536

589537
class Query(graphene.ObjectType):
590538

@@ -683,8 +631,3 @@ class Query(graphene.ObjectType):
683631
assert not result.errors
684632
assert json.dumps(result.data, sort_keys=True) == json.dumps(
685633
expected, sort_keys=True)
686-
687-
688-
# TODO:
689-
def test_should_paging():
690-
pass

0 commit comments

Comments
 (0)