-
Notifications
You must be signed in to change notification settings - Fork 3
/
conftest.py
110 lines (90 loc) · 2.96 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pytest
import os
import sys
from djwebdapp.models import Account, Blockchain
from djwebdapp_multisig.models import MultisigContract
from djwebdapp_tezos.models import TezosTransaction
def evil(path, *scripts, variables=None):
"""
100% Evil code so that test code be documentation too.
Example usage::
variables = include(
'djwebdapp_example/tezos',
'client', 'deploy', 'blockchain', 'index', 'normalize',
)
Or (old syntax)::
variables = {}
evil('djwebdapp_example/tezos_deploy.py', variables)
evil('djwebdapp_example/tezos_index.py', variables)
"""
variables = variables if variables is not None else {}
def abspath(script):
return os.path.abspath(os.path.join(path, f'{script}.py'))
path = os.path.join(
os.path.dirname(__file__),
'src',
path,
)
for number, script in enumerate(scripts, start=0):
script_path = abspath(script)
with open(script_path) as f:
source = f.read()
code = compile(source, script_path, 'exec')
try:
exec(code, variables, variables)
except:
if number:
print('Executed successfuly:')
for i in range(0, number):
print(abspath(scripts[i]))
print('Failed:\n' + script_path)
exctype, exc, tb = sys.exc_info()
raise exctype(exc).with_traceback(tb)
return variables
@pytest.fixture
def include():
return evil
@pytest.fixture
def admin_smoketest(admin_client):
def _():
urls = (
'/admin/djwebdapp/account/',
'/admin/djwebdapp/account/add/',
'/admin/djwebdapp/blockchain/',
'/admin/djwebdapp/blockchain/add/',
'/admin/djwebdapp/node/',
'/admin/djwebdapp/node/add/',
'/admin/djwebdapp/transaction/',
'/admin/djwebdapp/transaction/add/',
'/admin/djwebdapp_tezos/tezostransaction/',
'/admin/djwebdapp_tezos/tezostransaction/add/',
'/admin/djwebdapp_ethereum/ethereumtransaction/',
'/admin/djwebdapp_ethereum/ethereumtransaction/add/',
)
for url in urls:
assert admin_client.get(url).status_code == 200
return _
@pytest.fixture
@pytest.mark.django_db
def deploy_and_index():
def f(transaction, no_assert=False):
res = transaction.blockchain.provider.spool()
if not no_assert:
assert res == transaction
transaction.blockchain.wait()
transaction.blockchain.provider.index()
transaction.refresh_from_db()
return f
@pytest.fixture
@pytest.mark.django_db
def blockchain():
return Blockchain.objects.create(
provider_class='djwebdapp.provider.Success',
)
@pytest.fixture
@pytest.mark.django_db
def account(blockchain):
return Account.objects.create(
address='testacc',
blockchain=blockchain,
)