-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
71 lines (51 loc) · 1.29 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import pytest
import factory
from django_webtest import (
WebTest as BaseWebTest,
DjangoTestApp
)
from rest_framework.test import APIClient
@pytest.fixture() # NOQA
def factories(transactional_db):
from factories import ( # NOQA
SignatureFactory,
BytesSignatureFactory,
EventSignatureFactory
)
def is_factory(obj):
if not isinstance(obj, type):
return False
return issubclass(obj, factory.Factory)
dict_ = {k: v for k, v in locals().items() if is_factory(v)}
return type(
'fixtures',
(object,),
dict_,
)
@pytest.fixture() # NOQA
def models_no_db():
from django.apps import apps
dict_ = {M._meta.object_name: M for M in apps.get_models()}
return type(
'models',
(object,),
dict_,
)
@pytest.fixture() # NOQA
def models(models_no_db, transactional_db):
return models_no_db
class WebTest(BaseWebTest):
app_class = DjangoTestApp
@pytest.fixture() # NOQA
def webtest_client(transactional_db):
web_test = WebTest(methodName='__call__')
web_test()
return web_test.app
@pytest.fixture()
def api_client(transactional_db):
"""
A rest_framework api test client not auth'd.
"""
client = APIClient()
return client