- def _db_get_one(self, table, q_filter=None, fail_on_empty=True, fail_on_more=True):
- if table not in self.db_content:
- self.assertTrue(False, "db.get_one called with table={}".format(table))
- for db_item in self.db_content[table]:
- if db_item["_id"] == q_filter["_id"]:
- return db_item
- else:
- self.assertTrue(False, "db.get_one, table={}, not found _id={}".format(table, q_filter["_id"]))
-
- def _db_get_list(self, table, q_filter=None):
- if table not in self.db_content:
- self.assertTrue(False, "db.get_list called with table={} not found".format(table))
- return self.db_content[table]
-
- def _db_set_one(self, table, q_filter, update_dict, fail_on_empty=True, unset=None, pull=None, push=None):
- db_item = self._db_get_one(table, q_filter, fail_on_empty=fail_on_empty)
- for k, v in update_dict.items():
- db_nested = db_item
- k_list = k.split(".")
- for k_nested in k_list[0:-1]:
- if isinstance(db_nested, list):
- db_nested = db_nested[int(k_nested)]
- else:
- if k_nested not in db_nested:
- db_nested[k_nested] = {}
- db_nested = db_nested[k_nested]
- k_nested = k_list[-1]
- if isinstance(db_nested, list):
- if int(k_nested) < len(db_nested):
- db_nested[int(k_nested)] = v
- else:
- db_nested.insert(int(k_nested), v)
- else:
- db_nested[k_nested] = v
-