Projet

Général

Profil

0001-tests-use-sql_mode-publisher-creation-in-test_sql.patch

Thomas Noël, 20 avril 2018 14:04

Télécharger (1,95 ko)

Voir les différences:

Subject: [PATCH 1/2] tests: use sql_mode publisher creation in test_sql

 tests/test_sql.py | 30 +++---------------------------
 1 file changed, 3 insertions(+), 27 deletions(-)
tests/test_sql.py
19 19
from wcs import sql
20 20
import wcs.qommon.storage as st
21 21

  
22
from utilities import create_temporary_pub
22
from utilities import create_temporary_pub, clean_temporary_pub
23 23

  
24 24
import pytest
25 25
postgresql = pytest.mark.postgresql
......
34 34

  
35 35
    cleanup()
36 36

  
37
    pub = create_temporary_pub()
38
    pub.user_class = sql.SqlUser
39
    pub.is_using_postgresql = lambda: True
40

  
41
    conn = psycopg2.connect(user=os.environ['USER'])
42
    conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
43
    cur = conn.cursor()
44
    dbname = 'wcstests%d' % random.randint(0, 100000)
45
    cur.execute('CREATE DATABASE %s' % dbname)
46
    cur.close()
47

  
48
    pub.cfg['postgresql'] = {'database': dbname, 'user': os.environ['USER']}
49
    pub.initialize_sql()
37
    pub = create_temporary_pub(sql_mode=True)
50 38

  
51 39
    formdef = formdef.FormDef()
52 40
    formdef.name = 'tests'
......
61 49
    ]
62 50
    formdef.store()
63 51

  
64
    conn.close()
65

  
66

  
67 52
def teardown_module(module):
68
    shutil.rmtree(pub.APP_DIR)
69

  
70
    if hasattr(pub, 'pgconn') and pub.pgconn:
71
        pub.pgconn.close()
72

  
73
    conn = psycopg2.connect(user=os.environ['USER'])
74
    conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
75
    cur = conn.cursor()
76
    cur.execute('DROP DATABASE %s' % pub.cfg['postgresql']['database'])
77
    cur.close()
53
    clean_temporary_pub()
78 54

  
79 55
@postgresql
80 56
def test_sql_table_name_invalid_chars():
81
-