Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Xbus emitter
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
Xbus emitter
Commits
e62406b4
Commit
e62406b4
authored
7 years ago
by
Houzefa Abbasbhay
Browse files
Options
Downloads
Patches
Plain Diff
Test utilities
parent
3bc821da
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/util/__init__.py
+0
-0
0 additions, 0 deletions
tests/util/__init__.py
tests/util/odoo_tests.py
+86
-0
86 additions, 0 deletions
tests/util/odoo_tests.py
tests/util/uuidgen.py
+22
-0
22 additions, 0 deletions
tests/util/uuidgen.py
with
108 additions
and
0 deletions
tests/util/__init__.py
0 → 100644
+
0
−
0
View file @
e62406b4
This diff is collapsed.
Click to expand it.
tests/util/odoo_tests.py
0 → 100644
+
86
−
0
View file @
e62406b4
##############################################################################
#
# Xbus emitter for Odoo
# Copyright (C) 2015 XCG Consulting <http://odoo.consulting>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
"""
Utilities useful to Odoo tests.
"""
import
odoo.models
import
odoo.tests
class
TestBase
(
odoo
.
tests
.
SingleTransactionCase
):
"""
Provide some test helpers.
"""
def
createAndTest
(
self
,
model
,
value_list
,
custom_testers
=
None
):
"""
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.
:param custom_testers: Mapping of testing functions to use when
comparing the recorded value to the one asked for by the test.
:type custom_testers: {
'
field
'
: f(test_instance, asked_value, recorded_value),
}.
:return: The created records.
:rtype: List of odoo.models.BaseModel instances.
"""
if
custom_testers
is
None
:
custom_testers
=
{}
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
,
odoo
.
models
.
BaseModel
)
for
field
,
value
in
local_values
.
iteritems
():
tester
=
(
custom_testers
.
get
(
field
)
or
TestBase
.
defaultValueTester
)
tester
(
self
,
value
,
getattr
(
record
,
field
))
return
records
@staticmethod
def
defaultValueTester
(
test_instance
,
asked_value
,
recorded_value
):
"""
Ensure what has been recorded is the same as what has been asked
for.
"""
# Handle relational fields (Odoo record-sets).
if
isinstance
(
recorded_value
,
odoo
.
models
.
BaseModel
):
if
isinstance
(
recorded_value
,
(
tuple
,
list
)):
test_instance
.
assertEqual
(
recorded_value
.
ids
,
asked_value
)
else
:
test_instance
.
assertEqual
(
recorded_value
.
id
,
asked_value
)
else
:
test_instance
.
assertEqual
(
recorded_value
,
asked_value
)
This diff is collapsed.
Click to expand it.
tests/util/uuidgen.py
0 → 100644
+
22
−
0
View file @
e62406b4
"""
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment