forked from django-json-api/django-rest-framework-json-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
43 lines (30 loc) · 1.23 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest
from tests.models import ForeignKeyTarget, ManyToManySource, ManyToManyTarget
@pytest.fixture(autouse=True)
def use_rest_framework_json_api_defaults(settings):
"""
Enfroce default settings for tests modules.
As for now example and tests modules share the same settings file
some defaults which have been overwritten in the example app need
to be overwritten. This way testing actually happens on default resp.
each test defines what non default setting it wants to test.
Once migration to tests module is finished and tests can have
its own settings file, this fixture can be removed.
"""
settings.JSON_API_FORMAT_FIELD_NAMES = False
settings.JSON_API_FORMAT_TYPES = False
settings.JSON_API_PLURALIZE_TYPES = False
@pytest.fixture
def foreign_key_target(db):
return ForeignKeyTarget.objects.create(name="Target")
@pytest.fixture
def many_to_many_source(db, many_to_many_targets):
source = ManyToManySource.objects.create(name="Source")
source.targets.add(*many_to_many_targets)
return source
@pytest.fixture
def many_to_many_targets(db):
return [
ManyToManyTarget.objects.create(name="Target1"),
ManyToManyTarget.objects.create(name="Target2"),
]