Exemple #1
0
    def setup_api_db(self):
        """ Setup a test against the API test database.
        """
        self.write_nominatim_config(self.api_test_db)

        if self.api_db_done:
            return

        self.api_db_done = True

        if self._reuse_or_drop_db(self.api_test_db):
            return

        testdata = Path('__file__') / '..' / '..' / 'testdb'
        self.test_env['NOMINATIM_TIGER_DATA_PATH'] = str(
            (testdata / 'tiger').resolve())
        self.test_env['NOMINATIM_WIKIPEDIA_DATA_PATH'] = str(
            testdata.resolve())

        try:
            self.run_setup_script('all', osm_file=self.api_test_file)
            self.run_setup_script('import-tiger-data')
            self.run_setup_script('drop')

            phrase_file = str(
                (testdata / 'specialphrases_testdb.sql').resolve())
            run_script(['psql', '-d', self.api_test_db, '-f', phrase_file])
        except:
            self.db_drop_database(self.api_test_db)
            raise
    def setup_api_db(self):
        """ Setup a test against the API test database.
        """
        self.write_nominatim_config(self.api_test_db)

        if not self.api_db_done:
            self.api_db_done = True

            if not self._reuse_or_drop_db(self.api_test_db):
                testdata = Path('__file__') / '..' / '..' / 'testdb'
                self.test_env['NOMINATIM_WIKIPEDIA_DATA_PATH'] = str(testdata.resolve())

                try:
                    self.run_nominatim('import', '--osm-file', str(self.api_test_file))
                    self.run_nominatim('add-data', '--tiger-data', str((testdata / 'tiger').resolve()))
                    self.run_nominatim('freeze')

                    if self.tokenizer != 'icu':
                        phrase_file = str((testdata / 'specialphrases_testdb.sql').resolve())
                        run_script(['psql', '-d', self.api_test_db, '-f', phrase_file])
                    else:
                        csv_path = str((testdata / 'full_en_phrases_test.csv').resolve())
                        self.run_nominatim('special-phrases', '--import-from-csv', csv_path)
                except:
                    self.db_drop_database(self.api_test_db)
                    raise

        tokenizer_factory.create_tokenizer(self.get_test_config(), init_db=False)
Exemple #3
0
    def setup_api_db(self):
        """ Setup a test against the API test database.
        """
        self.write_nominatim_config(self.api_test_db)

        if not self.api_db_done:
            self.api_db_done = True

            if not self._reuse_or_drop_db(self.api_test_db):
                testdata = Path('__file__') / '..' / '..' / 'testdb'
                self.test_env['NOMINATIM_WIKIPEDIA_DATA_PATH'] = str(testdata.resolve())

                try:
                    self.run_nominatim('import', '--osm-file', str(self.api_test_file))
                    if self.tokenizer != 'legacy_icu':
                        self.run_nominatim('add-data', '--tiger-data', str((testdata / 'tiger').resolve()))
                    self.run_nominatim('freeze')

                    if self.tokenizer != 'legacy_icu':
                        phrase_file = str((testdata / 'specialphrases_testdb.sql').resolve())
                        run_script(['psql', '-d', self.api_test_db, '-f', phrase_file])
                    else:
                        # XXX Temporary use the wiki while there is no CSV import
                        # available.
                        self.test_env['NOMINATIM_LANGUAGES'] = 'en'
                        self.run_nominatim('special-phrases', '--import-from-wiki')
                        del self.test_env['NOMINATIM_LANGUAGES']
                except:
                    self.db_drop_database(self.api_test_db)
                    raise

        tokenizer_factory.create_tokenizer(self.get_test_config(), init_db=False)
Exemple #4
0
    def run_nominatim_script(self, script, *args, **kwargs):
        """ Run one of the Nominatim utility scripts with the given arguments.
        """
        cmd = ['/usr/bin/env', 'php', '-Cq']
        cmd.append((Path(self.src_dir) / 'lib' / 'admin' / '{}.php'.format(script)).resolve())
        cmd.extend(['--' + x for x in args])
        for k, v in kwargs.items():
            cmd.extend(('--' + k.replace('_', '-'), str(v)))

        if self.website_dir is not None:
            cwd = self.website_dir.name
        else:
            cwd = None

        run_script(cmd, cwd=cwd, env=self.test_env)