Skip to content

Commit

Permalink
data: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagusiak committed Jan 2, 2024
1 parent 2ec9d05 commit 11e2a77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/mock_odoo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def field_get_user(allfields=[], attributes=[]):
}

@h.patch_execute_kw('res.users', 'search_read')
def read_search_partner(domain, fields=[], load=None):
def read_search_user(domain, fields=[], load=None):
print(domain)
data = [{'id': 1, 'name': 'test', 'login': 'admin', 'partner_id': 1}]
if not fields:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,35 @@ def test_export(odoo_cli):
print(data.schema)
assert len(data) > 0, "No data"
assert data.schema[0]['type'] == "char", "Invalid login type"
assert data.column_names == ['login']
assert data.get_sql_columns() == [('login', 'varchar')]


def test_batches():
b = list(odoo_data.make_batches([1, 2, 3]))
assert b == [[1, 2, 3]], "simple batch"
b = list(odoo_data.make_batches([1, 2, 3], batch_size=2))
assert b == [[1, 2], [3]], "small batches"
source = [*[{'a': 'ok', 'v': i} for i in range(5)], {'a': 'z', 'v': 0}]
b = list(odoo_data.make_batches(source, batch_size=2, group_by="a"))
assert b == [source[0:5], source[5:]], "group by"
source = [{'a': 'x'}, {'a': 'b'}]
b = list(odoo_data.make_batches(source, group_by="a"))
assert b == [sorted(source, key=lambda i: i['a'])], "group by should sort"


def test_batches_no_key():
with pytest.raises(KeyError):
list(odoo_data.make_batches([{}], batch_size=2, group_by="a"))


def test_load(odoo_cli, odoo_json_rpc_handler):
model = odoo_cli['res.users']
handler = odoo_json_rpc_handler

@handler.patch_execute_kw(model.model, 'load')
def load_model(fields, data):
return "loaded"

r = odoo_data.load_data(model, [{'login': 'x'}], fields=["login"])
assert r == "loaded"

0 comments on commit 11e2a77

Please sign in to comment.