21
by Samus CTO
[FIX] prop instance and cost center for test cases and from hq_data + [FIX] self.db.db_name to self.db.name to avoid connection error + [IMP] Added finance.py test + [FIX] use groups of hq_data + [IMP] remove shortname and version |
1 |
#!/usr/bin/env python2
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
||
4 |
#Load common script tests
|
|
5 |
from scripts.common import Synchro, HQ, Coordo, Project |
|
6 |
||
7 |
#Load config file
|
|
8 |
import config |
|
9 |
||
10 |
#Load OpenERP Client Library
|
|
11 |
import openerplib |
|
12 |
from tests.openerplib import * |
|
13 |
||
14 |
#Other stuffs
|
|
15 |
from datetime import datetime |
|
16 |
from random import choice |
|
17 |
||
30
by Samus CTO
[FIX] finance.py use right unittest |
18 |
#Load tests procedures
|
19 |
if sys.version_info >= (2, 7): |
|
20 |
import unittest |
|
21 |
else: |
|
22 |
# Needed for setUpClass and skipIf methods
|
|
23 |
import unittest27 as unittest |
|
24 |
||
25 |
try: |
|
26 |
import ipdb as pdb |
|
27 |
except: |
|
28 |
import pdb |
|
21
by Samus CTO
[FIX] prop instance and cost center for test cases and from hq_data + [FIX] self.db.db_name to self.db.name to avoid connection error + [IMP] Added finance.py test + [FIX] use groups of hq_data + [IMP] remove shortname and version |
29 |
|
30 |
class finance(unittest.TestCase): |
|
31 |
||
32 |
models = ('res.currency','res.currency.table','res.currency.rate') |
|
33 |
||
34 |
def sync(self, db=None): |
|
35 |
if db is None: db = self.db |
|
36 |
if not db.get('sync.client.entity').sync(): |
|
37 |
monitor = db.get('sync.monitor') |
|
38 |
ids = monitor.search([], 0, 1, '"end" desc') |
|
39 |
self.fail('Synchronization process of database "%s" failed!\n%s' % (db.db_name,monitor.read(ids, ['error'])[0]['error'])) |
|
40 |
||
41 |
def clean(self): |
|
42 |
for db in (HQ, Coordo, Project): |
|
43 |
db.clean('res.currency.rate', self.rate_data) |
|
44 |
db.clean('res.currency', self.currency_data, active='both', domain=['|','!',('currency_table_id','=',False),('currency_table_id','=',False)]) |
|
45 |
db.clean('res.currency.table', self.hq_data) |
|
46 |
for db in (Coordo, Project): |
|
47 |
db.clean('res.currency.table', self.coordo_data) |
|
48 |
||
49 |
def setUp(self): |
|
50 |
Synchro.connect('admin') |
|
51 |
HQ.connect('admin') |
|
52 |
Coordo.connect('admin') |
|
53 |
Project.connect('admin') |
|
54 |
||
55 |
def test_20_currency(self): |
|
56 |
# Make data
|
|
57 |
self.id = datetime.now().strftime('%m%d%H%M') |
|
58 |
self.hq_data = { |
|
59 |
'code':'TEST_%s' % self.id, |
|
60 |
'name':'TEST_%s' % self.id, |
|
61 |
}
|
|
62 |
self.coordo_data = { |
|
63 |
'code':'TEST_%s_X' % self.id, |
|
64 |
}
|
|
65 |
self.currency_data = { |
|
66 |
'accuracy' : 4, |
|
67 |
'currency_name' : 'TEST_%s' % self.id, |
|
68 |
'name' : 'TEST_%s' % self.id, |
|
69 |
'rounding' : 0.01, |
|
70 |
'symbol' : 'T%s' % self.id, |
|
71 |
}
|
|
72 |
self.rate_data = { |
|
73 |
'name' : datetime.now().strftime('%Y-%m-%d'), |
|
74 |
'rate' : '0.9999', |
|
75 |
}
|
|
76 |
self.clean() |
|
77 |
# Activate rule
|
|
78 |
#Synchro.desactivate('sync_server.sync_rule', [])
|
|
79 |
n = Synchro.activate('sync_server.sync_rule', [('model_id','in',self.models)]) |
|
80 |
#self.assertTrue(n >= len(self.models), "Cannot enable sync rules!")
|
|
81 |
# Create & Synchronize
|
|
82 |
cur = dict(self.currency_data) |
|
83 |
rate = dict(self.rate_data) |
|
84 |
cur['currency_table_id'] = HQ.get('res.currency.table').create(self.hq_data) |
|
85 |
self.assertTrue(cur['currency_table_id'], "Cannot create currency table!") |
|
86 |
rate['currency_id'] = HQ.get('res.currency').create(cur) |
|
87 |
self.assertTrue(rate['currency_id'], "Cannot create currency!") |
|
88 |
rate_id = HQ.get('res.currency.rate').create(rate) |
|
89 |
self.assertTrue(rate_id, "Cannot create currency rate!") |
|
90 |
HQ.get('res.currency').write(rate['currency_id'], {'active':1}) |
|
91 |
for db in (HQ, Coordo, Project,): |
|
92 |
self.sync(db) |
|
93 |
# Check
|
|
94 |
for db in (HQ, Coordo, Project,): |
|
95 |
self.assertTrue(db.test('res.currency.table', self.hq_data), |
|
96 |
"The currency table created in HQ is not present in database %s! data=%s" % (db.db_name,self.hq_data)) |
|
97 |
self.assertTrue(db.test('res.currency', self.currency_data, active='both', domain=['|','!',('currency_table_id','=',False),('currency_table_id','=',False)]), |
|
98 |
"The currency created in HQ is not present in database %s! data=%s" % (db.db_name,self.currency_data,)) |
|
99 |
self.assertTrue(db.test('res.currency.rate', self.rate_data), |
|
100 |
"The currency rate created in HQ is not present in database %s! data=%s" % (db.db_name,self.rate_data)) |
|
101 |
# Modify & Synchronize
|
|
102 |
n = Coordo.write('res.currency.table', self.hq_data, self.coordo_data) |
|
103 |
self.assertTrue(n == 1, |
|
104 |
"Cannot write coordo data! hq_data=%s, coordo_data=%s" % (self.hq_data, self.coordo_data)) |
|
105 |
for db in (Coordo, HQ, Project,): |
|
106 |
self.sync(db) |
|
107 |
# Check
|
|
108 |
self.assertFalse(HQ.test('res.currency.table', self.coordo_data), |
|
109 |
"The currency table created in Coordo has been modified in database HQ!") |
|
110 |
self.assertTrue(Project.test('res.currency.table', self.coordo_data), |
|
111 |
"The currency table created in Coordo has not been properly modified in database Project!") |
|
112 |
||
113 |
test_cases = (finance,) |
|
114 |
||
115 |
def load_tests(loader, tests, pattern): |
|
116 |
suite = unittest.TestSuite() |
|
117 |
for test_class in test_cases: |
|
118 |
tests = loader.loadTestsFromTestCase(test_class) |
|
119 |
suite.addTests(tests) |
|
120 |
return suite |
|
121 |
||
122 |
if __name__ == '__main__': |
|
123 |
unittest.main(failfast=True, verbosity=2) |
|
124 |