From 74ab2a496808f4e1adb9d339dc0fb5fb66b4dbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 4 Mar 2010 14:10:41 +0100 Subject: [PATCH] New unittest design --- tests/test_party.py | 63 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/tests/test_party.py b/tests/test_party.py index f0db791c61..888cf38422 100644 --- a/tests/test_party.py +++ b/tests/test_party.py @@ -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 PartyTestCase(unittest.TestCase): @@ -20,10 +23,14 @@ class PartyTestCase(unittest.TestCase): def setUp(self): trytond.tests.test_tryton.install_module('party') - self.category = RPCProxy('party.category') - self.party = RPCProxy('party.party') - self.address = RPCProxy('party.address') - self.country = RPCProxy('country.country') + self.category = POOL.get('party.category') + self.party = POOL.get('party.party') + self.address = POOL.get('party.address') + self.cursor = DB.cursor() + + def tearDown(self): + self.cursor.commit() + self.cursor.close() def test0005views(self): ''' @@ -35,7 +42,7 @@ class PartyTestCase(unittest.TestCase): ''' Create category. ''' - category1_id = self.category.create({ + category1_id = self.category.create(self.cursor, USER, { 'name': 'Category 1', }, CONTEXT) self.assert_(category1_id) @@ -44,18 +51,18 @@ class PartyTestCase(unittest.TestCase): ''' Test category recursion. ''' - category1_id = self.category.search([ + category1_id = self.category.search(self.cursor, USER, [ ('name', '=', 'Category 1'), ], 0, 1, None, CONTEXT)[0] - category2_id = self.category.create({ + category2_id = self.category.create(self.cursor, USER, { 'name': 'Category 2', 'parent': category1_id, }, CONTEXT) self.assert_(category2_id) - self.failUnlessRaises(Exception, self.category.write, - category1_id, { + self.failUnlessRaises(Exception, self.category.write, self.cursor, + USER, category1_id, { 'parent': category2_id, }, CONTEXT) @@ -63,7 +70,7 @@ class PartyTestCase(unittest.TestCase): ''' Create party. ''' - party1_id = self.party.create({ + party1_id = self.party.create(self.cursor, USER, { 'name': 'Party 1', }, CONTEXT) self.assert_(party1_id) @@ -72,41 +79,39 @@ class PartyTestCase(unittest.TestCase): ''' Test party code constraint. ''' - party1_id = self.party.search([], 0, 1, None, CONTEXT)[0] + party1_id = self.party.search(self.cursor, USER, [], 0, 1, None, + CONTEXT)[0] - code = self.party.read(party1_id, ['code'], CONTEXT)['code'] + code = self.party.read(self.cursor, USER, party1_id, ['code'], + CONTEXT)['code'] - party2_id = self.party.create({ + party2_id = self.party.create(self.cursor, USER, { 'name': 'Party 2', }, CONTEXT) - self.failUnlessRaises(Exception, self.party.write, party2_id, { - 'code': code, - }, CONTEXT) + self.failUnlessRaises(Exception, self.party.write, self.cursor, USER, + party2_id, { + 'code': code, + }, CONTEXT) def test0050address(self): ''' Create address. ''' - party1_id = self.party.search([], 0, 1, None, CONTEXT)[0] - belgium_id = self.country.search([ - ('code', '=', 'BE'), - ], 0, 1, None, CONTEXT)[0] + party1_id = self.party.search(self.cursor, USER, [], 0, 1, None, + CONTEXT)[0] - address1_id = self.address.create({ + address1_id = self.address.create(self.cursor, USER, { 'party': party1_id, 'street': 'St sample, 15', 'city': 'City', - 'country': belgium_id, }, CONTEXT) self.assert_(party1_id) def suite(): - return unittest.TestLoader().loadTestsFromTestCase(PartyTestCase) + suite = trytond.tests.test_tryton.suite() + suite.addTests(unittest.TestLoader().loadTestsFromTestCase(PartyTestCase)) + return suite if __name__ == '__main__': - suiteTrytond = trytond.tests.test_tryton.suite() - suiteParty = suite() - alltests = unittest.TestSuite([suiteTrytond, suiteParty]) - unittest.TextTestRunner(verbosity=2).run(alltests) - SOCK.disconnect() + unittest.TextTestRunner(verbosity=2).run(suite())