def test_nodb_all_subpath(self): # create dummy bucket and store some objects bucket_name = 'dummy_bucket_12345_qwerty' self._create_mock_bucket(bucket_name) nodb = NoDB(bucket_name) nodb.human_readable_indexes = True nodb.index = "path" jeff = { "Name": "Jeff", "age": 19, "path": "persons/jeff", "type": "person" } michael = { "Name": "Michael", "age": 19, "path": "persons/michael", "type": "person" } car = {"Name": "Acura TSX", "path": "vehicles/car", "type": "vehicle"} nodb.save(jeff) nodb.save(michael) nodb.save(car) persons = nodb.all(subpath="persons/") self.assertListEqual([jeff, michael], persons)
def get_db(bucket="olneyhymnbots", serializer="json", index="content"): db = NoDB() db.bucket = bucket db.human_readable_indexes = True db.serializer = serializer db.index = index return db
def test_nodb(self): self.assertTrue(True) nodb = NoDB() nodb.index = "Name" jeff = {"Name": "Jeff", "age": 19} serialized = nodb._serialize(jeff) nodb._deserialize(serialized) nodb.serializer = 'json' nodb.human_readable_indexes = True serialized = nodb._serialize(jeff) nodb._deserialize(serialized)
def test_nodb_serialize_deserialize(self): nodb = NoDB('dummy') nodb.index = "Name" jeff = {"Name": "Jeff", "age": 19} serialized = nodb._serialize(jeff) deserialized = nodb._deserialize(serialized) self.assertDictEqual(jeff, deserialized['obj']) nodb.serializer = 'json' nodb.human_readable_indexes = True serialized = nodb._serialize(jeff) deserialized = nodb._deserialize(serialized) self.assertDictEqual(jeff, deserialized['obj'])
def test_nodb_save_load_all_subpath(self): bucket_name = 'noahonnumbers-blog' nodb = NoDB(bucket_name) nodb.human_readable_indexes = True nodb.index = "path" jeff = {"Name": "Jeff", "age": 19, "path": "persons/jeff", "type": "person"} michael = {"Name": "Michael", "age": 19, "path": "persons/michael", "type": "person"} car = {"Name": "Acura TSX", "path": "vehicles/car", "type": "vehicle"} nodb.save(jeff) nodb.save(michael) nodb.save(car) persons = nodb.all(subpath="persons/") self.assertListEqual([jeff, michael], persons)