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_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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
    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_value_is_updated(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)
        self.assertIn(key, SUT.cached_values)
        self.assertEqual(SUT.cached_values[key]['value'], value)
        self.assertEqual(SUT.cached_values[key]['timestamp'], timestamp)
Esempio n. 8
0
    def test_value_is_updated(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)
        self.assertIn(key, SUT.cached_values)
        self.assertEqual(SUT.cached_values[key]['value'], value)
        self.assertEqual(SUT.cached_values[key]['timestamp'], timestamp)
Esempio n. 9
0
    def test_mismatch_unit_system(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache()

        key = random_string()

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

        value = round(random.uniform(1, 100), 2)
        timestamp = time.time()

        unit_system_mismatch = random.randint(11, 20)
        self.assertRaises(ValueError, SUT.update_value, key, value,
                          unit_system_mismatch, timestamp)
Esempio n. 10
0
    def test_mismatch_unit_system(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache()

        key = ''.join([
            random.choice(string.ascii_letters + string.digits)
            for n in range(32)
        ])

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

        value = round(random.uniform(1, 100), 2)
        timestamp = time.time()

        unit_system_mismatch = random.randint(11, 20)
        self.assertRaises(ValueError, SUT.update_value, key, value,
                          unit_system_mismatch, timestamp)
    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, time.time())

        SUT.remove_value(key)
        self.assertNotIn(key, SUT.cached_values)
Esempio n. 12
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, time.time())

        SUT.remove_value(key)
        self.assertNotIn(key, SUT.cached_values)
    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)
Esempio n. 14
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)
Esempio n. 15
0
    def test_cache_is_cleared(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)

        SUT.clear_cache()
        self.assertEqual(SUT.cached_values, {})
    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)
Esempio n. 17
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.remove_value(nonexisting_key)
        self.assertNotIn(nonexisting_key, SUT.cached_values)
Esempio n. 18
0
    def test_cache_is_cleared(self):
        unit_system = random.randint(1, 10)
        SUT = RecordCache()

        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)

        SUT.clear_cache()
        self.assertEqual(SUT.cached_values, {})
Esempio n. 19
0
    def test_key_not_in_cache(self):
        SUT = RecordCache()

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

        self.assertIsNone(value)
Esempio n. 20
0
    def test_key_not_in_cache(self):
        SUT = RecordCache()

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

        self.assertIsNone(value)