-
-def check_amenities_with_op(temp_db_conn):
- """
- Check that the test table for the SQL function getorcreate_amenityoperator()
- contains more than one value (so that the SQL function was call more than one time).
- """
- with temp_db_conn.cursor() as temp_db_cursor:
- temp_db_cursor.execute("SELECT * FROM temp_with_operator")
- return len(temp_db_cursor.fetchall()) > 1
-
-def check_amenities_without_op(temp_db_conn):
- """
- Check that the test table for the SQL function getorcreate_amenity()
- contains more than one value (so that the SQL function was call more than one time).
- """
- with temp_db_conn.cursor() as temp_db_cursor:
- temp_db_cursor.execute("SELECT * FROM temp_without_operator")
- return len(temp_db_cursor.fetchall()) > 1
-
-@pytest.fixture
-def special_phrases_importer(temp_db_conn, def_config, temp_phplib_dir_with_migration):
- """
- Return an instance of SpecialPhrasesImporter.
- """
- return SpecialPhrasesImporter(def_config, temp_phplib_dir_with_migration, temp_db_conn)
-
-@pytest.fixture
-def temp_phplib_dir_with_migration():
- """
- Return temporary phpdir with migration subdirectory and
- PhraseSettingsToJson.php script inside.
- """
- migration_file = (TEST_BASE_DIR / '..' / 'lib-php' / 'migration'
- / 'PhraseSettingsToJson.php').resolve()
- with tempfile.TemporaryDirectory() as phpdir:
- (Path(phpdir) / 'migration').mkdir()
- migration_dest_path = (Path(phpdir) / 'migration' / 'PhraseSettingsToJson.php').resolve()
- copyfile(migration_file, migration_dest_path)
-
- yield Path(phpdir)
-
-@pytest.fixture
-def default_phrases(word_table, temp_db_cursor):
- temp_db_cursor.execute("""
- INSERT INTO word VALUES(99999, 'lookup_token', 'normalized_word',
- 'class', 'type', null, 0, 'near');
-
- INSERT INTO word VALUES(99999, 'lookup_token', 'normalized_word_exists',
- 'class_exists', 'type_exists', null, 0, 'near');
-
- CREATE TABLE place_classtype_testclasstypetable_to_delete();
- CREATE TABLE place_classtype_testclasstypetable_to_keep();""")
-
-@pytest.fixture
-def make_strandard_name_func(temp_db_cursor):
- temp_db_cursor.execute("""
- CREATE OR REPLACE FUNCTION make_standard_name(name TEXT) RETURNS TEXT AS $$
- BEGIN
- RETURN trim(name); --Basically return only the trimed name for the tests
- END;
- $$ LANGUAGE plpgsql IMMUTABLE;""")
-
-@pytest.fixture
-def getorcreate_amenity_funcs(temp_db_cursor, make_strandard_name_func):
- temp_db_cursor.execute("""
- CREATE TABLE temp_without_operator(op TEXT);
-
- CREATE OR REPLACE FUNCTION getorcreate_amenity(lookup_word TEXT, normalized_word TEXT,
- lookup_class text, lookup_type text)
- RETURNS void as $$
- BEGIN
- INSERT INTO temp_without_operator VALUES('no_operator');
- END;
- $$ LANGUAGE plpgsql""")
-
-@pytest.fixture
-def getorcreate_amenityoperator_funcs(temp_db_cursor, make_strandard_name_func):
- temp_db_cursor.execute("""
- CREATE TABLE temp_with_operator(op TEXT);
-
- CREATE OR REPLACE FUNCTION getorcreate_amenityoperator(lookup_word TEXT, normalized_word TEXT,
- lookup_class text, lookup_type text, op text)
- RETURNS void as $$
- BEGIN
- INSERT INTO temp_with_operator VALUES(op);
- END;
- $$ LANGUAGE plpgsql""")
\ No newline at end of file