New unittest design
This commit is contained in:
1 parent
c48c467a67
commit
05ee2c437f
1 file changed
+34
-20
+34
-20
@@ -2,6 +2,9 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.FATAL)
|
||||
|
||||
import sys, os
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', '..', '..', '..', 'trytond')))
|
||||
@@ -10,7 +13,7 @@ if os.path.isdir(DIR):
|
||||
|
||||
import unittest
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import RPCProxy, CONTEXT, SOCK, test_view
|
||||
from trytond.tests.test_tryton import POOL, DB, USER, CONTEXT, test_view
|
||||
|
||||
|
||||
class CompanyTestCase(unittest.TestCase):
|
||||
@@ -20,9 +23,9 @@ class CompanyTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
trytond.tests.test_tryton.install_module('company')
|
||||
self.company = RPCProxy('company.company')
|
||||
self.employee = RPCProxy('company.employee')
|
||||
self.currency = RPCProxy('currency.currency')
|
||||
self.company = POOL.get('company.company')
|
||||
self.employee = POOL.get('company.employee')
|
||||
self.currency = POOL.get('currency.currency')
|
||||
|
||||
def test0005views(self):
|
||||
'''
|
||||
@@ -34,29 +37,33 @@ class CompanyTestCase(unittest.TestCase):
|
||||
'''
|
||||
Create company.
|
||||
'''
|
||||
currency1_id = self.currency.search([
|
||||
('code', '=', 'EUR'),
|
||||
cursor = DB.cursor()
|
||||
currency1_id = self.currency.search(cursor, USER, [
|
||||
('code', '=', 'cu1'),
|
||||
], 0, 1, None, CONTEXT)[0]
|
||||
|
||||
company1_id = self.company.create({
|
||||
company1_id = self.company.create(cursor, USER, {
|
||||
'name': 'B2CK',
|
||||
'currency': currency1_id,
|
||||
}, CONTEXT)
|
||||
self.assert_(company1_id)
|
||||
cursor.commit()
|
||||
cursor.close()
|
||||
|
||||
def test0020company_recursion(self):
|
||||
'''
|
||||
Test company recursion.
|
||||
'''
|
||||
currency1_id = self.currency.search([
|
||||
('code', '=', 'EUR'),
|
||||
cursor = DB.cursor()
|
||||
currency1_id = self.currency.search(cursor, USER, [
|
||||
('code', '=', 'cu1'),
|
||||
], 0, 1, None, CONTEXT)[0]
|
||||
|
||||
company1_id = self.company.search([
|
||||
company1_id = self.company.search(cursor, USER, [
|
||||
('name', '=', 'B2CK'),
|
||||
], 0, 1, None, CONTEXT)[0]
|
||||
|
||||
company2_id = self.company.create({
|
||||
company2_id = self.company.create(cursor, USER, {
|
||||
'name': 'B2CK Branch',
|
||||
'parent': company1_id,
|
||||
'currency': currency1_id,
|
||||
@@ -64,29 +71,36 @@ class CompanyTestCase(unittest.TestCase):
|
||||
self.assert_(company2_id)
|
||||
|
||||
self.failUnlessRaises(Exception, self.company.write,
|
||||
company1_id, {
|
||||
cursor, USER, company1_id, {
|
||||
'parent': company2_id,
|
||||
}, CONTEXT)
|
||||
cursor.commit()
|
||||
cursor.close()
|
||||
|
||||
def test0030employe(self):
|
||||
'''
|
||||
Create employee.
|
||||
'''
|
||||
company1_id = self.company.search([
|
||||
cursor = DB.cursor()
|
||||
company1_id = self.company.search(cursor, USER, [
|
||||
('name', '=', 'B2CK'),
|
||||
], 0, 1, None, CONTEXT)[0]
|
||||
|
||||
employee1_id = self.employee.create({
|
||||
employee1_id = self.employee.create(cursor, USER, {
|
||||
'name': 'Employee1',
|
||||
'company': company1_id,
|
||||
}, CONTEXT)
|
||||
cursor.commit()
|
||||
cursor.close()
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(CompanyTestCase)
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
from trytond.modules.currency.tests import test_currency
|
||||
for test in test_currency.suite():
|
||||
if test not in suite:
|
||||
suite.addTest(test)
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CompanyTestCase))
|
||||
return suite
|
||||
|
||||
if __name__ == '__main__':
|
||||
suiteTrytond = trytond.tests.test_tryton.suite()
|
||||
suiteCompany = suite()
|
||||
alltests = unittest.TestSuite([suiteTrytond, suiteCompany])
|
||||
unittest.TextTestRunner(verbosity=2).run(alltests)
|
||||
SOCK.disconnect()
|
||||
unittest.TextTestRunner(verbosity=2).run(suite())
|
||||
Reference in new issue
Block a user