def test_prevent_download(self): def download(): global CALL_COUNT CALL_COUNT += 1 return urllib.urlopen('https://github.com/ebertti/micro-cache').read() microCache = MicroCache() v = None for i in range(1000): v = microCache.get('key', download) self.assertEquals(CALL_COUNT, 1, 'call more then 1 time') self.assertEquals(microCache.get('key'), v, 'html download is not equal')
def test_prevent_download(self): def download(): global CALL_COUNT CALL_COUNT += 1 pwd = os.path.realpath(os.path.dirname(__file__)) html_file = os.path.join(pwd, 'html_test.html') return urllib.urlopen(html_file).read() microCache = MicroCache() v = None for i in range(1000): v = microCache.get('key', download) self.assertEquals(CALL_COUNT, 1, 'call more then 1 time') self.assertEquals(microCache.get('key'), v, 'html download is not equal')
def test_prevent_call(self): m = mock.Mock() m.return_value = 'value' microCache = MicroCache() v = None for i in range(1000): v = microCache.get('key', m) self.assertEquals(v, 'value', 'different value') self.assertEquals(m.call_count, 1, 'call more then 1 time')
def test_set(self): microCache = MicroCache() v = "value" microCache.set("key", v) self.assertEqual("value", microCache.get("key"))