Skip to content
Snippets Groups Projects
Commit 7114a9376967 authored by Houzefa Abbasbhay's avatar Houzefa Abbasbhay :slight_smile:
Browse files

Test scaffold (nothing yet)

parent 4945d5cd6098
No related branches found
No related tags found
No related merge requests found
# flake8: noqa
from . import test_auth_saml
import openerp.tests
from .util.odoo_tests import TestBase
from .util.singleton import Singleton
from .util.uuidgen import genUuid
class TestMemory(object):
"""Keep records in memory across tests."""
__metaclass__ = Singleton
@openerp.tests.common.at_install(False)
@openerp.tests.common.post_install(True)
class Test(TestBase):
def setUp(self):
super(Test, self).setUp()
self.memory = TestMemory()
# TODO Tests.
"""Utilities useful to Odoo tests.
"""
import openerp.models
import openerp.tests
class TestBase(openerp.tests.SingleTransactionCase):
"""Provide some test helpers.
"""
def createAndTest(self, model, value_list):
"""Create records of the specified Odoo model using the specified
values, and ensure afterwards that records have been succesfully
created and that their values are the same as expected.
:return: The created records.
:rtype: List of openerp.models.BaseModel instances.
"""
records = []
for values in value_list:
# Maintain a local copy as Odoo calls might modify it...
local_values = values.copy()
record = self.env[model].create(values)
records.append(record)
self.assertIsInstance(record, openerp.models.BaseModel)
for field, value in local_values.iteritems():
recorded_value = getattr(record, field)
# Handle relational fields (Odoo record-sets).
if isinstance(recorded_value, openerp.models.BaseModel):
if isinstance(recorded_value, (tuple, list)):
self.assertEqual(recorded_value.ids, value)
else:
self.assertEqual(recorded_value.id, value)
else:
self.assertEqual(recorded_value, value)
return records
class Singleton(type):
"""
This is a neat singleton pattern. This was found in a comment on this page:
http://www.garyrobinson.net/2004/03/python_singleto.html
to use this, example :
>>> class C(object):
... __metaclass__ = Singleton
... def __init__(self, foo):
... self.foo = foo
>>> C('bar').foo
'bar'
>>> C().foo
'bar'
and your class C is now a singleton, and it is safe to use
the __init__ method as you usually do...
"""
def __init__(cls, name, bases, dic):
super(Singleton, cls).__init__(name, bases, dic)
cls.instance = None
def __call__(mcs, *args, **kw):
if mcs.instance is None:
mcs.instance = super(Singleton, mcs).__call__(*args, **kw)
return mcs.instance
"""Utilities to handle unique ID generation.
"""
import uuid
def genUuid(max_chars=None):
"""Generate a unique ID and return its hex string representation.
:param max_chars: Maximum amount of characters to return (might not be a
true UUID then...).
:type max_chars: Integer.
:rtype: String.
"""
ret = uuid.uuid4().hex
if max_chars is not None:
ret = ret[:max_chars]
return ret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment