Example #1
0
 def test_happy(self) -> None:
     """Tests the happy path."""
     ctx = test_context.make_test_context()
     relations = areas.Relations(ctx)
     relation = relations.get_relation("gazdagret")
     cache.get_missing_housenumbers_html(ctx, relation)
     self.assertTrue(
         cache.is_missing_housenumbers_html_cached(ctx, relation))
Example #2
0
    def test_no_cache(self) -> None:
        """Tests the case when there is no cache."""
        ctx = test_context.make_test_context()
        relations = areas.Relations(ctx)
        relation = relations.get_relation("gazdagret")
        cache.get_missing_housenumbers_html(ctx, relation)
        cache_path = relation.get_files().get_housenumbers_htmlcache_path()

        file_system = test_context.TestFileSystem()
        file_system.set_hide_paths([cache_path])
        ctx.set_file_system(file_system)
        self.assertFalse(
            cache.is_missing_housenumbers_html_cached(ctx, relation))
Example #3
0
    def test_no_cache(self) -> None:
        """Tests the case when there is no cache."""
        relations = get_relations()
        relation = relations.get_relation("gazdagret")
        cache.get_missing_housenumbers_html(relation)
        cache_path = relation.get_files().get_housenumbers_htmlcache_path()
        orig_exists = os.path.exists

        def mock_exists(path: str) -> bool:
            if path == cache_path:
                return False
            return orig_exists(path)

        with unittest.mock.patch('os.path.exists', mock_exists):
            self.assertFalse(
                cache.is_missing_housenumbers_html_cached(relation))
Example #4
0
    def test_ref_housenumbers_new(self) -> None:
        """Tests the case when ref_housenumbers is new, so the cache entry is old."""
        relations = get_relations()
        relation = relations.get_relation("gazdagret")
        cache.get_missing_housenumbers_html(relation)
        cache_path = relation.get_files().get_housenumbers_htmlcache_path()
        ref_housenumbers_path = relation.get_files().get_ref_housenumbers_path(
        )
        orig_getmtime = os.path.getmtime

        def mock_getmtime(path: str) -> float:
            if path == ref_housenumbers_path:
                return orig_getmtime(cache_path) + 1
            return orig_getmtime(path)

        with unittest.mock.patch('os.path.getmtime', mock_getmtime):
            self.assertFalse(
                cache.is_missing_housenumbers_html_cached(relation))
Example #5
0
    def test_ref_housenumbers_new(self) -> None:
        """Tests the case when ref_housenumbers is new, so the cache entry is old."""
        ctx = test_context.make_test_context()
        relations = areas.Relations(ctx)
        relation = relations.get_relation("gazdagret")
        cache.get_missing_housenumbers_html(ctx, relation)
        cache_path = relation.get_files().get_housenumbers_htmlcache_path()
        ref_housenumbers_path = relation.get_files().get_ref_housenumbers_path(
        )

        file_system = test_context.TestFileSystem()
        mtimes = {
            ref_housenumbers_path: os.path.getmtime(cache_path) + 1,
        }
        file_system.set_mtimes(mtimes)
        ctx.set_file_system(file_system)
        self.assertFalse(
            cache.is_missing_housenumbers_html_cached(ctx, relation))
Example #6
0
    def test_relation_new(self) -> None:
        """Tests the case when relation is new, so the cache entry is old."""
        relations = get_relations()
        relation = relations.get_relation("gazdagret")
        cache.get_missing_housenumbers_html(relation)
        cache_path = relation.get_files().get_housenumbers_htmlcache_path()
        datadir = config.get_abspath("data")
        relation_path = os.path.join(datadir,
                                     "relation-%s.yaml" % relation.get_name())
        orig_getmtime = os.path.getmtime

        def mock_getmtime(path: str) -> float:
            if path == relation_path:
                return orig_getmtime(cache_path) + 1
            return orig_getmtime(path)

        with unittest.mock.patch('os.path.getmtime', mock_getmtime):
            self.assertFalse(
                cache.is_missing_housenumbers_html_cached(relation))
Example #7
0
 def test_happy(self) -> None:
     """Tests the happy path."""
     relations = get_relations()
     relation = relations.get_relation("gazdagret")
     cache.get_missing_housenumbers_html(relation)
     self.assertTrue(cache.is_missing_housenumbers_html_cached(relation))