Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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'])
Exemplo n.º 3
0
    def test_nodb_cache(self):
        nodb = NoDB('dummy')
        nodb.index = "Name"
        nodb.cache = True

        jeff = {"Name": "Jeff", "age": 19}
        serialized = nodb._serialize(jeff)

        real_index = nodb._format_index_value("Jeff")
        base_cache_path = os.path.join(tempfile.gettempdir(), '.nodb')
        if not os.path.isdir(base_cache_path):
            os.makedirs(base_cache_path)

        cache_path = os.path.join(base_cache_path, real_index)
        if not os.path.exists(cache_path):
            f = open(cache_path, 'a')
            f.close()

        with open(cache_path, "wb") as in_file:
            in_file.write(serialized.encode(NoDB.encoding))

        nodb.load("Jeff")
        loaded = nodb.load("Jeff", default={})
        self.assertEqual(loaded, jeff)
        loaded = nodb.load("Jeff", default="Booty")
        self.assertEqual(loaded, jeff)

        bcp = nodb._get_base_cache_path()
Exemplo n.º 4
0
    def test_nodb_cache(self):
        bucket_name = 'dummy'
        nodb = NoDB(bucket_name)
        self._create_mock_bucket(bucket_name)
        nodb.index = "Name"
        nodb.cache = True

        jeff = {"Name": "Jeff", "age": 19}
        serialized = nodb._serialize(jeff)

        real_index = nodb._format_index_value("Jeff")
        base_cache_path = os.path.join(tempfile.gettempdir(), '.nodb')
        if not os.path.isdir(base_cache_path):
            os.makedirs(base_cache_path)

        cache_path = os.path.join(base_cache_path, real_index)
        if not os.path.exists(cache_path):
            f = open(cache_path, 'a')
            f.close()

        with open(cache_path, "wb") as in_file:
            in_file.write(serialized.encode(NoDB.encoding))

        nodb.load("Jeff")
        loaded = nodb.load("Jeff", default={})
        self.assertEqual(loaded, jeff)
        loaded = nodb.load("Jeff", default="Booty")
        self.assertEqual(loaded, jeff)
        # test the cached item is deleted
        nodb.delete('Jeff')
        loaded = nodb.load("Jeff")
        self.assertIsNone(loaded)
        # test read from bucket when cache enabled
        # remove cached file
        nodb.save(jeff)
        if os.path.isfile(cache_path):
            os.remove(cache_path)
        nodb.load('Jeff')

        bcp = nodb._get_base_cache_path()