From a9f3eb86b26d47393db02ab9ba24166473144172 Mon Sep 17 00:00:00 2001 From: Abdurrahmaan Iqbal Date: Mon, 8 Jul 2019 18:10:00 +0100 Subject: [PATCH] Add tests for new functions --- test/test_dataset.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_dataset.py b/test/test_dataset.py index 99521ce..a40cef2 100644 --- a/test/test_dataset.py +++ b/test/test_dataset.py @@ -368,6 +368,29 @@ class TableTestCase(unittest.TestCase): self.tbl.insert_many(data, chunk_size=13) assert len(self.tbl) == len(data) + 6 + def test_update_many(self): + tbl = self.db['update_many_test'] + tbl.insert_many([ + dict(temp=10), dict(temp=20), dict(temp=30) + ]) + tbl.update_many( + [dict(id=1, temp=50), dict(id=3, temp=50)], 'id' + ) + + # Ensure data has been updated. + assert tbl.find_one(id=1)['temp'] == tbl.find_one(id=3)['temp'] + + def test_upsert_many(self): + # Also tests updating on records with different attributes + tbl = self.db['upsert_many_test'] + + W = 100 + tbl.upsert_many([dict(age=10), dict(weight=W)], 'id') + assert tbl.find_one(id=1)['age'] == 10 + + tbl.upsert_many([dict(id=1, age=70), dict(id=2, weight=W/2)], 'id') + assert tbl.find_one(id=2)['weight'] == W/2 + def test_drop_operations(self): assert self.tbl._table is not None, \ 'table shouldn\'t be dropped yet'