0001-tests-run-against-postgresql-67383.patch
tests/test_admin_pages.py | ||
---|---|---|
20 | 20 |
from wcs.formdef import FormDef |
21 | 21 |
from wcs import fields |
22 | 22 | |
23 |
from utilities import get_app, login, create_temporary_pub |
|
23 |
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
|
24 | 24 | |
25 | 25 | |
26 | 26 |
def setup_module(module): |
... | ... | |
36 | 36 |
pub.write_cfg() |
37 | 37 | |
38 | 38 | |
39 |
def teardown_module(module): |
|
40 |
clean_temporary_pub() |
|
41 | ||
42 | ||
39 | 43 |
def create_superuser(): |
40 | 44 |
global user1 |
41 |
if pub.user_class.has_key('admin'):
|
|
42 |
user1 = pub.user_class.get('admin')
|
|
45 |
if pub.user_class.get_users_with_name_identifier('admin'):
|
|
46 |
user1 = pub.user_class.get_users_with_name_identifier('admin')[0]
|
|
43 | 47 |
user1.is_admin = True |
44 | 48 |
user1.roles = [] |
45 | 49 |
return |
46 | 50 |
user1 = pub.user_class(name='admin') |
47 |
user1.id = 'admin' |
|
48 | 51 |
user1.is_admin = True |
52 |
user1.name_identifiers = ['admin'] |
|
49 | 53 |
user1.roles = [] |
50 | 54 |
user1.store() |
51 | 55 |
tests/test_backoffice_pages.py | ||
---|---|---|
10 | 10 |
from wcs.qommon.http_request import HTTPRequest |
11 | 11 |
from wcs.qommon.template import get_current_theme |
12 | 12 |
from wcs.categories import Category |
13 |
from wcs.roles import Role |
|
14 | 13 |
from wcs.workflows import Workflow |
15 | 14 |
from wcs.formdef import FormDef |
16 | 15 |
from wcs import fields |
17 | 16 | |
18 |
from utilities import get_app, login, create_temporary_pub |
|
17 |
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
|
19 | 18 | |
20 | 19 | |
21 | 20 |
def setup_module(module): |
... | ... | |
31 | 30 |
pub.write_cfg() |
32 | 31 | |
33 | 32 | |
33 |
def teardown_module(module): |
|
34 |
clean_temporary_pub() |
|
35 | ||
36 | ||
34 | 37 |
def create_agent(): |
35 |
if pub.user_class.has_key('agent'):
|
|
36 |
return |
|
38 |
if pub.user_class.get_users_with_name_identifier('agent'):
|
|
39 |
return pub.user_class.get_users_with_name_identifier('agent')[0]
|
|
37 | 40 |
user1 = pub.user_class(name='agent') |
38 |
user1.id = 'admin'
|
|
41 |
user1.name_identifiers = ['agent']
|
|
39 | 42 |
user1.is_admin = False |
40 | 43 |
user1.store() |
41 | 44 | |
... | ... | |
51 | 54 | |
52 | 55 | |
53 | 56 |
def create_role(): |
54 |
Role.wipe()
|
|
55 |
role = Role(name='foobar')
|
|
57 |
pub.role_class.wipe()
|
|
58 |
role = pub.role_class(name='foobar')
|
|
56 | 59 |
role.allows_backoffice_access = True |
57 | 60 |
role.store() |
58 | 61 |
return role |
tests/test_user_pages.py | ||
---|---|---|
10 | 10 |
from wcs.qommon.http_request import HTTPRequest |
11 | 11 |
from wcs.qommon.template import get_current_theme |
12 | 12 |
from wcs.categories import Category |
13 |
from wcs.roles import Role |
|
14 | 13 |
from wcs.workflows import Workflow |
15 | 14 |
from wcs.formdef import FormDef |
16 | 15 |
from wcs import fields |
17 | 16 | |
18 |
from utilities import get_app, login, create_temporary_pub |
|
17 |
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
|
19 | 18 | |
20 | 19 | |
21 | 20 |
def setup_module(module): |
... | ... | |
31 | 30 |
pub.write_cfg() |
32 | 31 | |
33 | 32 | |
33 |
def teardown_module(module): |
|
34 |
clean_temporary_pub() |
|
35 | ||
36 | ||
34 | 37 |
def create_user(): |
35 |
if pub.user_class.has_key('user'):
|
|
36 |
return |
|
38 |
if pub.user_class.get_users_with_name_identifier('user'):
|
|
39 |
return pub.user_class.get_users_with_name_identifier('user')[0]
|
|
37 | 40 |
user1 = pub.user_class(name='user') |
38 |
user1.id = 'admin'
|
|
41 |
user1.name_identifiers = ['user']
|
|
39 | 42 |
user1.is_admin = False |
40 | 43 |
user1.store() |
41 | 44 |
tests/utilities.py | ||
---|---|---|
1 | 1 |
import configparser |
2 | 2 |
import os |
3 |
import random |
|
4 |
import shutil |
|
3 | 5 |
import tempfile |
4 | 6 | |
7 |
import psycopg2 |
|
8 | ||
5 | 9 |
from webtest import TestApp |
6 | 10 |
from quixote import cleanup, get_publisher |
7 | 11 |
from django.conf import settings |
... | ... | |
10 | 14 |
import wcs |
11 | 15 |
import wcs.wsgi |
12 | 16 |
from wcs.qommon.http_request import HTTPRequest |
13 |
from wcs import publisher, compat |
|
17 |
from wcs import publisher, compat, sql
|
|
14 | 18 | |
15 | 19 |
import wcs.middleware |
16 | 20 | |
... | ... | |
31 | 35 |
compat.CompatWcsPublisher.configure(config) |
32 | 36 |
compat.CompatWcsPublisher.init_publisher_class() |
33 | 37 |
pub = compat.CompatWcsPublisher.create_publisher() |
34 |
# allow saving the user |
|
35 | 38 |
pub.app_dir = os.path.join(APP_DIR, 'example.net') |
36 | 39 |
os.mkdir(pub.app_dir) |
40 | ||
41 |
# set classes |
|
42 |
pub.user_class = sql.SqlUser |
|
43 |
pub.role_class = sql.Role |
|
44 |
pub.token_class = sql.Token |
|
45 |
pub.tracking_code_class = sql.TrackingCode |
|
46 |
pub.session_class = sql.Session |
|
47 |
pub.custom_view_class = sql.CustomView |
|
48 |
pub.snapshot_class = sql.Snapshot |
|
49 |
pub.loggederror_class = sql.LoggedError |
|
50 | ||
51 |
conn = psycopg2.connect(user=os.environ['USER'], dbname='postgres') |
|
52 |
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) |
|
53 |
i = 0 |
|
54 |
while True: |
|
55 |
dbname = 'wcstests%d' % random.randint(0, 100000) |
|
56 |
try: |
|
57 |
cur = conn.cursor() |
|
58 |
cur.execute('CREATE DATABASE %s' % dbname) |
|
59 |
break |
|
60 |
except psycopg2.Error: |
|
61 |
if i < 5: |
|
62 |
i += 1 |
|
63 |
continue |
|
64 |
raise |
|
65 |
finally: |
|
66 |
cur.close() |
|
67 | ||
68 |
pub.cfg['postgresql'] = {'database': dbname, 'user': os.environ['USER']} |
|
69 |
pub.write_cfg() |
|
70 | ||
71 |
sql.do_user_table() |
|
72 |
sql.do_role_table() |
|
73 |
sql.do_tokens_table() |
|
74 |
sql.do_tracking_code_table() |
|
75 |
sql.do_session_table() |
|
76 |
sql.do_transient_data_table() |
|
77 |
sql.do_custom_views_table() |
|
78 |
sql.do_snapshots_table() |
|
79 |
sql.do_loggederrors_table() |
|
80 |
sql.do_meta_table() |
|
81 |
sql.init_global_table() |
|
82 |
conn.close() |
|
83 | ||
37 | 84 |
return pub |
38 | 85 | |
39 | 86 | |
87 |
def clean_temporary_pub(): |
|
88 |
pub = get_publisher() |
|
89 |
conn = psycopg2.connect(user=os.environ['USER'], dbname='postgres') |
|
90 |
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) |
|
91 |
try: |
|
92 |
cur = conn.cursor() |
|
93 |
cur.execute('DROP DATABASE %s' % pub.cfg['postgresql']['database']) |
|
94 |
cur.close() |
|
95 |
except psycopg2.Error as e: |
|
96 |
print(e) |
|
97 |
shutil.rmtree(pub.app_dir) |
|
98 |
pub.cleanup() |
|
99 | ||
100 | ||
40 | 101 |
def get_app(pub, https=False): |
41 | 102 |
extra_environ = {'HTTP_HOST': 'example.net', 'REMOTE_ADDR': '127.0.0.1'} |
42 | 103 |
if https: |
43 |
- |