示例#1
0
 def test_happy(self) -> None:
     """Tests the happy path."""
     with unittest.mock.patch('util.get_abspath', get_abspath):
         relations = get_relations()
         for relation_name in relations.get_active_names():
             if relation_name not in ("gazdagret", "ujbuda"):
                 relations.get_relation(
                     relation_name).get_config().set_active(False)
         config = webframe.get_config()
         expected = util.get_content(
             relations.get_workdir(),
             "street-housenumbers-reference-gazdagret.lst")
         os.unlink(
             os.path.join(relations.get_workdir(),
                          "street-housenumbers-reference-gazdagret.lst"))
         cron.update_ref_housenumbers(relations, config)
         actual = util.get_content(
             relations.get_workdir(),
             "street-housenumbers-reference-gazdagret.lst")
         self.assertEqual(actual, expected)
         # Make sure housenumber ref is not created for the streets=only case.
         ujbuda_path = os.path.join(
             relations.get_workdir(),
             "street-housenumbers-reference-ujbuda.lst")
         self.assertFalse(os.path.exists(ujbuda_path))
示例#2
0
def missing_streets_update(relations: areas.Relations, relation_name: str) -> yattag.doc.Doc:
    """Expected request_uri: e.g. /osm/missing-streets/ujbuda/update-result."""
    reference = util.get_abspath(webframe.get_config().get('wsgi', 'reference_street').strip())
    relation = relations.get_relation(relation_name)
    relation.write_ref_streets(reference)
    doc = yattag.doc.Doc()
    with doc.tag("div", id="update-success"):
        doc.text(_("Update successful."))
    return doc
示例#3
0
def missing_housenumbers_update(relations: areas.Relations, relation_name: str) -> yattag.doc.Doc:
    """Expected request_uri: e.g. /osm/missing-housenumbers/ormezo/update-result."""
    reference = webframe.get_config().get('wsgi', 'reference_housenumbers').strip().split(' ')
    reference = [util.get_abspath(i) for i in reference]
    relation = relations.get_relation(relation_name)
    relation.write_ref_housenumbers(reference)
    doc = yattag.doc.Doc()
    doc.text(_("Update successful: "))
    link = "/osm/missing-housenumbers/" + relation_name + "/view-result"
    doc.asis(util.gen_link(link, _("View missing house numbers")).getvalue())
    return doc
示例#4
0
def our_application(
        environ: Dict[str, Any],
        start_response: 'StartResponse'
) -> Iterable[bytes]:
    """Dispatches the request based on its URI."""
    config = webframe.get_config()
    util.set_locale(config)

    language = util.setup_localization(environ)

    relations = areas.Relations(util.get_workdir(config))

    request_uri = get_request_uri(environ, relations)
    _, _, ext = request_uri.partition('.')

    if ext in ("txt", "chkl"):
        return our_application_txt(start_response, relations, request_uri)

    if request_uri.startswith("/osm/static/"):
        output, content_type = webframe.handle_static(request_uri)
        return webframe.send_response(start_response, content_type, "200 OK", output, [])

    doc = yattag.doc.Doc()
    util.write_html_header(doc)
    with doc.tag("html", lang=language):
        write_html_head(doc, get_html_title(request_uri))

        with doc.tag("body"):
            no_such_relation = check_existing_relation(relations, request_uri)
            handler = get_handler(request_uri)
            if no_such_relation.getvalue():
                doc.asis(no_such_relation.getvalue())
            elif handler:
                doc.asis(handler(relations, request_uri).getvalue())
            elif request_uri.startswith("/osm/webhooks/github"):
                doc.asis(handle_github_webhook(environ).getvalue())
            else:
                doc.asis(handle_main(request_uri, relations).getvalue())

    return webframe.send_response(start_response, "text/html", "200 OK", doc.getvalue(), [])
示例#5
0
    def test_happy(self) -> None:
        """Tests the happy path."""
        calls = 0

        def count_calls(
                _relations: areas.Relation,
                _config: Optional[configparser.ConfigParser] = None) -> None:
            nonlocal calls
            calls += 1

        with unittest.mock.patch('util.get_abspath', get_abspath):
            relations = get_relations()
            config = webframe.get_config()
            with unittest.mock.patch("cron.update_osm_streets", count_calls):
                with unittest.mock.patch("cron.update_osm_housenumbers",
                                         count_calls):
                    with unittest.mock.patch("cron.update_ref_streets",
                                             count_calls):
                        with unittest.mock.patch(
                                "cron.update_ref_housenumbers", count_calls):
                            with unittest.mock.patch(
                                    "cron.update_missing_streets",
                                    count_calls):
                                with unittest.mock.patch(
                                        "cron.update_missing_housenumbers",
                                        count_calls):
                                    cron.our_main(relations, config)

        expected = 0
        # Consider what to update automatically: the 2 sources and the diff between them.
        for _ in ("osm", "ref", "missing"):
            # What object types we have.
            for _ in ("streets", "housenumbers"):
                expected += 1

        self.assertEqual(calls, expected)