Пример #1
0
    def test_add_by_key(self):
        params = ("k1", 1), ("k2", ("k3", 2))
        obj = "object_example"

        h = CacheHandler._hash(params)
        CacheHandler.add_by_key(h, obj)
        filename = CacheHandler._build_filename(h, CacheObjectType.OTHER)
        with open(filename, "rb") as file:
            obj2 = pickle.load(file)

        self.assertEqual(obj, obj2)
        os.remove(filename)
Пример #2
0
    def test_get_by_key(self):
        params = (("k1", 1), ("k2", 2))
        obj = "object_example"

        h = CacheHandler._hash(params)
        filename = CacheHandler._build_filename(h, CacheObjectType.OTHER)
        with open(filename, "wb") as file:
            pickle.dump(obj, file)

        obj2 = CacheHandler.get_by_key(h, CacheObjectType.OTHER)
        self.assertEqual(obj, obj2)
        os.remove(filename)