示例#1
0
    def run(args):
        if args.query:
            params = dict(q=args.query)
        else:
            params = {
                k: getattr(args, k)
                for k, _ in STRUCTURED_QUERY if getattr(args, k)
            }

        for param, _ in EXTRADATA_PARAMS:
            if getattr(args, param):
                params[param] = '1'
        for param in ('format', 'countrycodes', 'exclude_place_ids', 'limit',
                      'viewbox'):
            if getattr(args, param):
                params[param] = getattr(args, param)
        if args.lang:
            params['accept-language'] = args.lang
        if args.polygon_output:
            params['polygon_' + args.polygon_output] = '1'
        if args.polygon_threshold:
            params['polygon_threshold'] = args.polygon_threshold
        if args.bounded:
            params['bounded'] = '1'
        if not args.dedupe:
            params['dedupe'] = '0'

        return run_api_script('search',
                              args.project_dir,
                              phpcgi_bin=args.phpcgi_path,
                              params=params)
示例#2
0
    def test_custom_phpcgi(tmp_path, capfd):
        assert exec_utils.run_api_script('test',
                                         tmp_path,
                                         phpcgi_bin='env',
                                         params={'q': 'Berlin'}) == 0
        captured = capfd.readouterr()

        assert '?q=Berlin' in captured.out
示例#3
0
def _run_api(endpoint, args, params):
    script_file = args.project_dir / 'website' / (endpoint + '.php')

    if not script_file.exists():
        LOG.error("Cannot find API script file.\n\n"
                  "Make sure to run 'nominatim' from the project directory \n"
                  "or use the option --project-dir.")
        raise UsageError("API script not found.")

    return run_api_script(endpoint,
                          args.project_dir,
                          phpcgi_bin=args.phpcgi_path,
                          params=params)
示例#4
0
    def run(args):
        if args.node:
            params = dict(osmtype='N', osmid=args.node)
        elif args.way:
            params = dict(osmtype='W', osmid=args.node)
        elif args.relation:
            params = dict(osmtype='R', osmid=args.node)
        else:
            params = dict(place_id=args.place_id)
        if args.object_class:
            params['class'] = args.object_class
        for name, _ in DETAILS_SWITCHES:
            params[name] = '1' if getattr(args, name) else '0'

        return run_api_script('details',
                              args.project_dir,
                              phpcgi_bin=args.phpcgi_path,
                              params=params)
示例#5
0
    def run(args):
        params = dict(osm_ids=','.join(args.ids))

        for param, _ in EXTRADATA_PARAMS:
            if getattr(args, param):
                params[param] = '1'
        if args.format:
            params['format'] = args.format
        if args.lang:
            params['accept-language'] = args.lang
        if args.polygon_output:
            params['polygon_' + args.polygon_output] = '1'
        if args.polygon_threshold:
            params['polygon_threshold'] = args.polygon_threshold

        return run_api_script('lookup',
                              args.project_dir,
                              phpcgi_bin=args.phpcgi_path,
                              params=params)
示例#6
0
    def run(args):
        params = dict(lat=args.lat, lon=args.lon)
        if args.zoom is not None:
            params['zoom'] = args.zoom

        for param, _ in EXTRADATA_PARAMS:
            if getattr(args, param):
                params[param] = '1'
        if args.format:
            params['format'] = args.format
        if args.lang:
            params['accept-language'] = args.lang
        if args.polygon_output:
            params['polygon_' + args.polygon_output] = '1'
        if args.polygon_threshold:
            params['polygon_threshold'] = args.polygon_threshold

        return run_api_script('reverse',
                              args.project_dir,
                              phpcgi_bin=args.phpcgi_path,
                              params=params)
def test_run_api_with_extra_env(tmp_project_dir):
    extra_env = dict(SCRIPT_FILENAME=str(tmp_project_dir / 'website' /
                                         'test.php'))
    assert 0 == exec_utils.run_api_script('badname',
                                          tmp_project_dir,
                                          extra_env=extra_env)
def test_run_api_execution_error(tmp_project_dir):
    assert 0 != exec_utils.run_api_script('badname', tmp_project_dir)
def test_run_api(tmp_project_dir):
    assert 0 == exec_utils.run_api_script('test', tmp_project_dir)
示例#10
0
    def test_fail_on_error_output(tmp_path):
        (tmp_path / 'website' /
         'bad.php').write_text("<?php\nfwrite(STDERR, 'WARNING'.PHP_EOL);")

        assert exec_utils.run_api_script('bad', tmp_path) == 1
示例#11
0
 def test_run_api_with_extra_env(tmp_path):
     extra_env = dict(SCRIPT_FILENAME=str(tmp_path / 'website' /
                                          'test.php'))
     assert exec_utils.run_api_script('badname',
                                      tmp_path,
                                      extra_env=extra_env) == 0
示例#12
0
 def test_run_api_execution_error(tmp_path):
     assert exec_utils.run_api_script('badname', tmp_path) != 0
示例#13
0
 def test_run_api(tmp_path):
     assert exec_utils.run_api_script('test', tmp_path) == 0
示例#14
0
 def run(args):
     return run_api_script('status',
                           args.project_dir,
                           phpcgi_bin=args.phpcgi_path,
                           params=dict(format=args.format))