コード例 #1
0
    def test_make_db(self):
        makedirs(TEST_CACHE_PATH, exist_ok=True)
        tdb_handle = crest_utils.setup_cache_file('dummy_handle')
        #assert tdb_handle
        assert path.isfile(path.join(TEST_CACHE_PATH, 'dummy_handle.json'))

        tdb_handle.close()

        rmtree(TEST_CACHE_PATH)
        tdb_handle = crest_utils.setup_cache_file('dummy_handle')
        #assert tdb_handle
        assert path.isfile(path.join(TEST_CACHE_PATH, 'dummy_handle.json'))

        tdb_handle.close()
コード例 #2
0
    def test_make_db(self):
        makedirs(TEST_CACHE_PATH, exist_ok=True)
        tdb_handle = crest_utils.setup_cache_file('dummy_handle')
        #assert tdb_handle
        assert path.isfile(path.join(TEST_CACHE_PATH, 'dummy_handle.json'))

        tdb_handle.close()

        helpers.clear_caches()
        #rmtree(TEST_CACHE_PATH)
        tdb_handle = crest_utils.setup_cache_file('dummy_handle')
        #assert tdb_handle
        assert path.isfile(path.join(TEST_CACHE_PATH, 'dummy_handle.json'))

        tdb_handle.close()
コード例 #3
0
    def test_write_cache(self):
        """validate write_cache behavior"""
        tdb_handle = crest_utils.setup_cache_file('dummy_handle')

        dummy_data = {'butts': 1, 'stuff': True}

        crest_utils.write_cache_entry(
            tdb_handle,
            999,
            dummy_data
        )

        cache_data = tdb_handle.search(Query().index_key == 999)[0]
        assert 'cache_datetime' in cache_data.keys()
        cache_datetime = cache_data['cache_datetime']
        assert cache_data['index_key'] == 999
        assert cache_data['payload'] == dummy_data


        crest_utils.write_cache_entry(
            tdb_handle,
            999,
            dummy_data
        )

        time.sleep(1)
        new_data = tdb_handle.search(Query().index_key == 999)
        assert len(new_data) == 1
        assert new_data[0]['cache_datetime'] >= cache_datetime
        assert new_data[0]['index_key'] == 999
        assert new_data[0]['payload'] == dummy_data

        tdb_handle.close()
コード例 #4
0
    def test_validate_region_cache(self):
        """make sure cachebuster and stash agree"""
        type_info = crest_utils.validate_id(
            'map_regions',
            self.region_id,
            config=ROOT_CONFIG,
            cache_buster=True,
        )
        tdb_handle = crest_utils.setup_cache_file('map_regions')
        type_cache = tdb_handle.search(Query().index_key == self.region_id)[0]

        assert type_info == type_cache['payload']
コード例 #5
0
    def test_validate_region_cache(self):
        """make sure cachebuster and stash agree"""
        type_info = crest_utils.validate_id(
            'map_regions',
            self.region_id,
            config=ROOT_CONFIG,
            cache_buster=True,
        )
        tdb_handle = crest_utils.setup_cache_file('map_regions')
        type_cache = tdb_handle.search(Query().index_key == self.region_id)[0]

        assert type_info == type_cache['payload']
コード例 #6
0
    def test_write_cache(self):
        """validate write_cache behavior"""
        tdb_handle = crest_utils.setup_cache_file('dummy_handle')

        dummy_data = {'butts': 1, 'stuff': True}

        crest_utils.write_cache_entry(tdb_handle, 999, dummy_data)

        cache_data = tdb_handle.search(Query().index_key == 999)[0]
        assert 'cache_datetime' in cache_data.keys()
        cache_datetime = cache_data['cache_datetime']
        assert cache_data['index_key'] == 999
        assert cache_data['payload'] == dummy_data

        crest_utils.write_cache_entry(tdb_handle, 999, dummy_data)

        time.sleep(1)
        new_data = tdb_handle.search(Query().index_key == 999)
        assert len(new_data) == 1
        assert new_data[0]['cache_datetime'] >= cache_datetime
        assert new_data[0]['index_key'] == 999
        assert new_data[0]['payload'] == dummy_data

        tdb_handle.close()