def test_key_not_in_cache(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache(unit_system)

        value = SUT.get_value('foo', 0, None)

        self.assertIsNone(value)
    def test_get_data_is_expired(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache(unit_system)
        key = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)])
        value = round(random.uniform(1, 100), 2)
        timestamp = time.time()
        SUT.update_value(key, value, unit_system, timestamp)

        cached_value = SUT.get_value(key, timestamp + 1, 0)
        self.assertIsNone(cached_value)
    def test_get_data_expiration_is_none(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache(unit_system)

        key = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)])
        value = round(random.uniform(1, 100), 2)
        SUT.update_value(key, value, unit_system, time.time())

        cached_value = SUT.get_value(key, None, None)
        self.assertEqual(cached_value, value)
Exemplo n.º 4
0
    def test_key_not_in_cache(self):
        SUT = RecordCache()

        value = SUT.get_value(
            ''.join([
                random.choice(string.ascii_letters + string.digits)
                for n in range(32)
            ]), 0, None)

        self.assertIsNone(value)
Exemplo n.º 5
0
    def test_get_data_is_expired(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache()
        key = random_string()
        value = round(random.uniform(1, 100), 2)
        timestamp = time.time()
        SUT.update_value(key, value, unit_system, timestamp)

        cached_value = SUT.get_value(key, timestamp + 1, 0)
        self.assertIsNone(cached_value)
Exemplo n.º 6
0
    def test_get_data_expiration_is_none(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache()

        key = random_string()
        value = round(random.uniform(1, 100), 2)
        SUT.update_value(key, value, unit_system, time.time())

        cached_value = SUT.get_value(key, None, None)
        self.assertEqual(cached_value, value)
Exemplo n.º 7
0
    def test_key_not_in_cache(self):
        SUT = RecordCache()

        value = SUT.get_value('foo', 0, None)

        self.assertIsNone(value)
Exemplo n.º 8
0
    def test_key_not_in_cache(self):
        SUT = RecordCache()

        value = SUT.get_value(random_string(), 0, None)

        self.assertIsNone(value)