예제 #1
0
    def test_caching_plaintext(self, plaintext_cache):
        """Test the caching of an XML containing strange characters.

        Test whether the data is saved in the cache.

        Parameters
        ----------
        plaintext_cache : pytest.fixture providing
                pydov.util.caching.PlainTextFileCache
            PlainTextFileCache using a temporary directory and a maximum age
            of 1 second.

        """
        cached_file = os.path.join(plaintext_cache.cachedir, 'boring',
                                   '1995-056089.xml')

        plaintext_cache.clean()
        assert not os.path.exists(cached_file)

        plaintext_cache.get(build_dov_url('data/boring/1995-056089.xml')),
        assert os.path.exists(cached_file)

        with open(cached_file, 'r', encoding='utf-8') as cf:
            cached_data = cf.read()
            assert cached_data != ""

        first_download_time = os.path.getmtime(cached_file)

        time.sleep(0.5)
        plaintext_cache.get(build_dov_url('data/boring/1995-056089.xml'))
        # assure we didn't redownload the file:
        assert os.path.getmtime(cached_file) == first_download_time
예제 #2
0
    def test_reuse_content_plaintext(self, plaintext_cache):
        """Test the caching of an XML containing strange characters.

        Test if the contents returned by the cache are the same as the
        original data.

        Parameters
        ----------
        plaintext_cache : pytest.fixture providing
                pydov.util.caching.PlainTextFileCache
            PlainTextFileCache using a temporary directory and a maximum age
            of 1 second.

        """
        cached_file = os.path.join(plaintext_cache.cachedir, 'boring',
                                   '1995-056089.xml')

        plaintext_cache.remove()
        assert not os.path.exists(cached_file)

        ref_data = plaintext_cache.get(
            build_dov_url('data/boring/1995-056089.xml'))
        assert os.path.exists(cached_file)

        cached_data = plaintext_cache.get(
            build_dov_url('data/boring/1995-056089.xml'))

        assert cached_data == ref_data
예제 #3
0
    def test_save_content_plaintext(self, plaintext_cache):
        """Test the caching of an XML containing strange characters.

        Test if the contents of the saved document are the same as the
        original data.

        Parameters
        ----------
        plaintext_cache : pytest.fixture providing
                pydov.util.caching.PlainTextFileCache
            PlainTextFileCache using a temporary directory and a maximum age
            of 1 second.

        """
        cached_file = os.path.join(plaintext_cache.cachedir, 'boring',
                                   '1995-056089.xml')

        plaintext_cache.remove()
        assert not os.path.exists(cached_file)

        ref_data = plaintext_cache.get(
            'https://www.dov.vlaanderen.be/data/boring/1995-056089.xml')
        assert os.path.exists(cached_file)

        with open(cached_file, 'r', encoding='utf-8') as cached:
            cached_data = cached.read().encode('utf-8')

        assert cached_data == ref_data