Skip to content
Snippets Groups Projects
Commit 7a8a4236 authored by Dmytro Katyukha's avatar Dmytro Katyukha
Browse files

Added tests for batch create in Odoo

parent 91ae2234
Branches
Tags
1 merge request!6Release 1.1.0
Pipeline #164942789 failed
Last changes
============
Release 1.0.1
-------------
- Added support (tests) of Odoo 13.0 and python3.8
- Added tests for batch create in Odoo 12.0+
Release 1.0.0
-------------
......
......@@ -96,8 +96,8 @@ Supported Odoo server versions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tested with:
- Odoo versions: *7.0*, *8.0*, *9.0*, *10.0*, *11.0*, *12.0*
- Python versions: *2.7*, *3.3*, *3.4*, *3.5*, *3.6*, *3.7*
- Odoo versions: *7.0*, *8.0*, *9.0*, *10.0*, *11.0*, *12.0*, *13.0*
- Python versions: *2.7*, *3.3*, *3.4*, *3.5*, *3.6*, *3.7*, *3.8*
Install
......
......@@ -86,8 +86,8 @@ Supported Odoo server versions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tested with:
- Odoo versions: *7.0*, *8.0*, *9.0*, *10.0*, *11.0*, *12.0*
- Python versions: *2.7*, *3.3*, *3.4*, *3.5*, *3.6*, *3.7*
- Odoo versions: *7.0*, *8.0*, *9.0*, *10.0*, *11.0*, *12.0*, *13.0*
- Python versions: *2.7*, *3.3*, *3.4*, *3.5*, *3.6*, *3.7*, *3.8*
Install
......
......@@ -9,6 +9,15 @@
""" This module contains classes and logic to handle operations on records
"""
import six
import abc
import numbers
import functools
import collections
from extend_me import (ExtensibleType,
ExtensibleByHashType)
from six import collections_abc
from ..utils import (wpartial,
normalizeSField,
......@@ -20,15 +29,6 @@ from .cache import (empty_cache,
Cache)
import six
import abc
import numbers
import functools
import collections
from extend_me import (ExtensibleType,
ExtensibleByHashType)
__all__ = (
'Record',
'ObjectRecords',
......@@ -246,7 +246,7 @@ class Record(six.with_metaclass(RecordMeta, DirMixIn)):
if rel_data:
# Do not forged about relations in form [id, name]
rel_id = (rel_data[0]
if isinstance(rel_data, collections.Iterable)
if isinstance(rel_data, collections_abc.Iterable)
else rel_data)
rel_obj = self._service.get_obj(
......@@ -460,7 +460,7 @@ def get_record_list(obj, ids=None, fields=None, cache=None, context=None):
# list with diferent cache
@six.python_2_unicode_compatible
class RecordList(six.with_metaclass(RecordListMeta,
collections.MutableSequence,
collections_abc.MutableSequence,
DirMixIn)):
"""Class to hold list of records with some extra functionality
......@@ -644,7 +644,8 @@ class RecordList(six.with_metaclass(RecordListMeta,
return str(self)
def refresh(self):
""" Cleanup data caches. next try to get data will cause rereading of it
""" Cleanup data caches.
Next try to get data will cause rereading of it
:returns: self
:rtype: instance of RecordList
......@@ -1038,7 +1039,7 @@ class ObjectRecords(Object):
if fields is not None:
record.read(fields) # read specified fields
return record
if isinstance(ids, collections.Iterable):
if isinstance(ids, collections_abc.Iterable):
return get_record_list(self, ids, fields=fields,
cache=cache, context=context)
......@@ -1053,8 +1054,9 @@ class ObjectRecords(Object):
:param Cache cache: cache to add created record to.
if None is passed, then new cache
will be created.
:return: Record instance of created record
:return: Record or RecordList instance of created records
:rtype: odoo_rpc_client.orm.record.Record
:rtype: odoo_rpc_client.orm.record.RecordList
For example:
......
......@@ -10,6 +10,9 @@
import six
import numbers
import collections
import unittest
from pkg_resources import parse_version as V
from . import (BaseTestCase,
mock)
......@@ -215,6 +218,27 @@ class Test_20_Object(BaseTestCase):
count=True),
0)
def test_create_unlink_multi(self):
if self.client.server_version <= V('11.0'):
raise unittest.SkipTest(
'Batch create is not supported in Odoo versions '
'less than 11.0')
new_partner_ids = self.object.create([
{'name': 'New Partner'},
{'name': 'New Partner2'},
])
self.assertIsInstance(new_partner_ids, list)
self.assertEqual(len(new_partner_ids), 2)
self.assertEqual(
self.object.search([('id', 'in', new_partner_ids)], count=True),
2)
self.object.unlink(new_partner_ids)
self.assertEqual(
self.object.search([('id', 'in', new_partner_ids)], count=True),
0)
def test_create_record(self):
john = self.object.create_record({'name': 'John'})
......@@ -225,6 +249,23 @@ class Test_20_Object(BaseTestCase):
john.unlink()
self.assertFalse(john.exists())
def test_create_records(self):
if self.client.server_version <= V('11.0'):
raise unittest.SkipTest(
'Batch create is not supported in Odoo versions '
'less than 11.0')
contacts = self.object.create_record([
{'name': 'John'},
{'name': 'Peter'},
])
self.assertIsInstance(contacts, RecordList)
self.assertEqual(len(contacts), 2)
# remove john
contacts.unlink()
self.assertFalse(contacts.exists())
class Test_21_Record(BaseTestCase):
......
......@@ -7,4 +7,4 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. #
#######################################################################
version = "1.0.0" # pragma: no cover
version = "1.0.1" # pragma: no cover
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment