def test_update_rows(): clean_data() db = JSONDB(TEST_DATA_PATH) assert len(db.select(lambda x: x["two"] == 2)) == 2 swapped_row = db.select(lambda x: x["two"] == 3) swapped_row.update("two", 2) assert len(db.select(lambda x: x["two"] == 2)) == 3
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.db = JSONDB()
def test_dump_json(): clean_data() db = JSONDB(TEST_DATA_PATH) assert len(json.loads(str(db))) == 3 assert len(json.loads(str(db.select(lambda x: True)))) == 3
def test_insert_item(): clean_data() db = JSONDB(TEST_DATA_PATH) assert len(db.select(lambda x: x["three"] == 3)) == 1 db.insert(three=3) assert len(db.select(lambda x: x["three"] == 3)) == 2
def test_get_item(): clean_data() db = JSONDB(TEST_DATA_PATH) assert db[0]["one"] == 1
def test_chained_select(): clean_data() db = JSONDB(TEST_DATA_PATH) assert len( db.select(lambda x: x["one"] == 1).select( lambda x: x["two"] == 2)) == 1
def test_loading_file(): clean_data() db = JSONDB(TEST_DATA_PATH) assert len(db) == 3
def test_creating_missing_file(): missing_path = os.path.join(TEST_PATH, "missing.json") if os.path.isfile(missing_path): os.remove(missing_path) JSONDB(missing_path) assert os.path.isfile(missing_path)