From 0a03ae44fa27ca4cb151ff18382b13cf7cb6acc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 21 Aug 2008 19:42:55 +0200 Subject: [PATCH] Add tests script --- tests/__init__.py | 3 ++ tests/test_company.py | 85 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_company.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000..9d3ed87d7e --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. + +from test_company import * diff --git a/tests/test_company.py b/tests/test_company.py new file mode 100644 index 0000000000..8a2a7eb282 --- /dev/null +++ b/tests/test_company.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +#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 sys, os +DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, + '..', '..', '..', '..', '..', 'trytond'))) +if os.path.isdir(DIR): + sys.path.insert(0, os.path.dirname(DIR)) + +import unittest +import trytond.tests +from trytond.tests import RPCProxy, CONTEXT, SOCK + + +class CompanyTestCase(unittest.TestCase): + ''' + Test Company module. + ''' + + def setUp(self): + trytond.tests.install_module('company') + self.company = RPCProxy('company.company') + self.employee = RPCProxy('company.employee') + self.currency = RPCProxy('currency.currency') + + def test0010company(self): + ''' + Create company. + ''' + currency1_id = self.currency.search([ + ('code', '=', 'EUR'), + ], 0, 1, None, CONTEXT)[0] + + company1_id = self.company.create({ + 'name': 'B2CK', + 'currency': currency1_id, + }, CONTEXT) + self.assert_(company1_id) + + def test0020company_recursion(self): + ''' + Test company recursion. + ''' + currency1_id = self.currency.search([ + ('code', '=', 'EUR'), + ], 0, 1, None, CONTEXT)[0] + + company1_id = self.company.search([ + ('name', '=', 'B2CK'), + ], 0, 1, None, CONTEXT)[0] + + company2_id = self.company.create({ + 'name': 'B2CK Branch', + 'parent': company1_id, + 'currency': currency1_id, + }, CONTEXT) + self.assert_(company2_id) + + self.failUnlessRaises(Exception, self.company.write, + company1_id, { + 'parent': company2_id, + }, CONTEXT) + + def test0030employe(self): + ''' + Create employee. + ''' + company1_id = self.company.search([ + ('name', '=', 'B2CK'), + ], 0, 1, None, CONTEXT)[0] + + employee1_id = self.employee.create({ + 'name': 'Employee1', + 'company': company1_id, + }, CONTEXT) + +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(CompanyTestCase) + +if __name__ == '__main__': + suiteTrytond = trytond.tests.suite() + suiteCompany = suite() + alltests = unittest.TestSuite([suiteTrytond, suiteCompany]) + unittest.TextTestRunner(verbosity=2).run(alltests) + SOCK.disconnect()