Skip to content

Commit

Permalink
Add more tests and increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
polsala committed Oct 8, 2024
1 parent cad993e commit cfc0aad
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class MongoModelTest(osv_mongodb.osv_mongodb):
'other_name': fields.char('Other name', size=64),
'boolean_field': fields.boolean('Boolean Field', size=64),
'integer_field_with_index': fields.integer('Integer Field', select=1),
'file_example': fields.binary('test'),
'file_example': fields.binary('test', gridfs=True),
'date_field': fields.date('Date Field'),
'datetime_field': fields.datetime('Datetime Field'),
'function_field': fields.function(
Expand Down Expand Up @@ -299,7 +299,8 @@ def test_orm_operation(self):
expected_content = {
'name': unique_ident, 'date_field': '2024-01-01',
'boolean_field': True, 'integer_field_with_index': 8,
'other_name': unique_ident, 'id': mmt_id, 'function_field': 'test', 'function_field_multi': 'test'
'other_name': unique_ident, 'id': mmt_id, 'function_field': 'test',
'function_field_multi': 'test'
}
self.assertEqual(all_content, expected_content)

Expand Down Expand Up @@ -331,8 +332,12 @@ def test_binary(self):
'name': unique_ident,
'other_name': 'Bar',
'boolean_field': True,
'integer_field_with_index': 8
'integer_field_with_index': 8,
'file_example': b64encode(fb)
})
res_file = mmt_obj.read(cursor, uid, mmt_id, ['file_example'])['file_example']
self.assertEqual(b64decode(res_file), fb)

mmt_obj.write(cursor, uid, [mmt_id], {'file_example': b64encode(fb)})
res_file = mmt_obj.read(cursor, uid, mmt_id, ['file_example'])['file_example']
self.assertEqual(b64decode(res_file), fb)
Expand All @@ -348,9 +353,6 @@ def test_gridfs(self):
)
mmt_obj = self.openerp.pool.get(NoMongoModelTestWithGridFs._name)
mmt_obj._auto_init(cursor)
mmt_id = mmt_obj.create(cursor, uid, {
'name': 'test'
})

image_path = get_module_resource(
'mongodb_backend', 'tests', 'fixtures', '15796004.png'
Expand All @@ -359,6 +361,11 @@ def test_gridfs(self):
with open(image_path, 'rb') as image_fd:
fb = image_fd.read()

mmt_id = mmt_obj.create(cursor, uid, {
'name': 'test',
'file_example': b64encode(fb)
})

mmt_obj.write(cursor, uid, [mmt_id], {'file_example': b64encode(fb)})
res_file = mmt_obj.read(cursor, uid, mmt_id, ['file_example'])['file_example']
self.assertEqual(b64decode(res_file), fb)
Expand Down

0 comments on commit cfc0aad

Please sign in to comment.