Example #1
0
    def test_key_exists(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, 0)

        new_time = time.time()
        SUT.update_timestamp(key, new_time)
        self.assertEqual(SUT.cached_values[key]['timestamp'], new_time)
    def test_key_exists(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, 0)

        new_time = time.time()
        SUT.update_timestamp(key, new_time)
        self.assertEqual(SUT.cached_values[key]['timestamp'], new_time)
    def test_key_does_not_exist(self):
        # somewhat silly test
        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())

        nonexisting_key = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)])
        SUT.update_timestamp(nonexisting_key, time.time())
        self.assertNotIn(nonexisting_key, SUT.cached_values)
Example #4
0
    def test_key_does_not_exist(self):
        # somewhat silly test
        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())

        nonexisting_key = random_string()
        SUT.update_timestamp(nonexisting_key, time.time())
        self.assertNotIn(nonexisting_key, SUT.cached_values)