예제 #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))
예제 #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))
예제 #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))
예제 #4
0
def missing_housenumbers_view_res(ctx: context.Context,
                                  relations: areas.Relations,
                                  request_uri: str) -> yattag.doc.Doc:
    """Expected request_uri: e.g. /osm/missing-housenumbers/ormezo/view-result."""
    tokens = request_uri.split("/")
    relation_name = tokens[-2]

    doc = yattag.doc.Doc()
    relation = relations.get_relation(relation_name)
    prefix = ctx.get_ini().get_uri_prefix()
    if not ctx.get_file_system().path_exists(
            relation.get_files().get_osm_streets_path()):
        doc.asis(
            webframe.handle_no_osm_streets(prefix, relation_name).getvalue())
    elif not ctx.get_file_system().path_exists(
            relation.get_files().get_osm_housenumbers_path()):
        doc.asis(
            webframe.handle_no_osm_housenumbers(prefix,
                                                relation_name).getvalue())
    elif not ctx.get_file_system().path_exists(
            relation.get_files().get_ref_housenumbers_path()):
        doc.asis(
            webframe.handle_no_ref_housenumbers(prefix,
                                                relation_name).getvalue())
    else:
        doc = cache.get_missing_housenumbers_html(ctx, relation)
    return doc
예제 #5
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))
예제 #6
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))
예제 #7
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))
예제 #8
0
def update_missing_housenumbers(relations: areas.Relations,
                                update: bool) -> None:
    """Update the relation's house number coverage stats."""
    info("update_missing_housenumbers: start")
    for relation_name in relations.get_active_names():
        relation = relations.get_relation(relation_name)
        if not update and os.path.exists(
                relation.get_files().get_housenumbers_percent_path()):
            continue
        streets = relation.get_config().should_check_missing_streets()
        if streets == "only":
            continue

        orig_language = i18n.get_language()
        relation.write_missing_housenumbers()
        for language in ["en", "hu"]:
            i18n.set_language(language)
            cache.get_missing_housenumbers_html(relation)
        i18n.set_language(orig_language)
    info("update_missing_housenumbers: end")
예제 #9
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))