Add route test case

This commit is contained in:
Cédric Krier
2023-09-12 18:52:14 +02:00
parent abfee0de15
commit ea98511139
3 changed files with 79 additions and 4 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add route test case
* Add on_scan_code method on Model
* Support add/update/remove/delete for on_change_with of xxx2Many
* Add decorator on RPC
+47
View File
@@ -42,10 +42,57 @@ ModuleTestCase
Name of the tested module.
.. attribute:: ModuleTestCase.extras
A list of extra modules to activate
.. attribute:: ModuleTestCase.language
The language to activate.
Default value is ``en``.
RouteTestCase
-------------
.. class:: RouteTestCase()
A subclass of `unittest.TestCase`_ to test Tryton routes.
It creates a temporary database with the module activated in setUpClass_ and
drops it in the tearDownClass_ method.
.. attribute:: RouteTestCase.module
Name of the tested module.
.. attribute:: RouteTestCase.extras
A list of extra modules to activate
.. attribute:: RouteTestCase.language
The language to activate.
Default value is ``en``.
.. attribute:: RouteTestCase.db_name
Returns the name of the database
.. classmethod:: RouteTestCase.setUpDatabase()
A method called by setUpClass_ after activating the modules in a
:class:`~trytond.transaction.Transaction`.
It is used to setup data in the database.
.. method:: RouteTestCase.client()
Return a client to simulate requests to the WSGI application.
.. _`unittest.TestCase`: https://docs.python.org/library/unittest.html#test-cases
.. _setUpClass: https://docs.python.org/library/unittest.html#unittest.TestCase.setUpClass
.. _tearDownClass: https://docs.python.org/library/unittest.html#unittest.TestCase.tearDownClass
Helpers
-------
+31 -4
View File
@@ -34,16 +34,19 @@ from trytond.model import (
ModelSingleton, ModelSQL, ModelStorage, ModelView, Workflow, fields)
from trytond.model.fields import Function
from trytond.pool import Pool, isregisteredby
from trytond.protocols.wrappers import Response
from trytond.pyson import PYSONDecoder, PYSONEncoder
from trytond.tools import file_open, find_dir, is_instance_method
from trytond.transaction import Transaction, TransactionError
from trytond.wizard import StateAction, StateView
from trytond.wsgi import app
__all__ = [
'CONTEXT',
'Client',
'DB_NAME',
'ModuleTestCase',
'RouteTestCase',
'USER',
'activate_module',
'doctest_checker',
@@ -239,8 +242,7 @@ def with_transaction(user=1, context=None):
return decorator
class ModuleTestCase(unittest.TestCase):
'Trytond Test Case'
class _DBTestCase(unittest.TestCase):
module = None
extras = None
language = 'en'
@@ -252,13 +254,17 @@ class ModuleTestCase(unittest.TestCase):
if cls.extras:
modules.extend(cls.extras)
activate_module(modules, lang=cls.language)
super(ModuleTestCase, cls).setUpClass()
super().setUpClass()
@classmethod
def tearDownClass(cls):
super(ModuleTestCase, cls).tearDownClass()
super().tearDownClass()
drop_db()
class ModuleTestCase(_DBTestCase):
"Tryton Module Test Case"
@with_transaction()
def test_rec_name(self):
for mname, model in Pool().iterobject():
@@ -923,6 +929,27 @@ class ModuleTestCase(unittest.TestCase):
validator.assertValid(tree)
class RouteTestCase(_DBTestCase):
"Tryton Route Test Case"
@classmethod
def setUpClass(cls):
super().setUpClass()
with Transaction().start(DB_NAME, 1):
cls.setUpDatabase()
@classmethod
def setUpDatabase(cls):
pass
@property
def db_name(self):
return DB_NAME
def client(self):
return Client(app, Response)
def db_exist(name=DB_NAME):
database = backend.Database().connect()
return name in database.list()