def test_get_form_empty_query(postgres_connector): """It should give suggestions of the databases without changing the rest""" current_config = {} form = PostgresDataSource.get_form(postgres_connector, current_config) assert form['properties']['database'] == {'$ref': '#/definitions/database'} assert form['definitions']['database'] == { 'title': 'database', 'description': 'An enumeration.', 'type': 'string', 'enum': ['postgres', 'postgres_db'], }
def test_get_form_query_with_good_database(postgres_connector, mocker): """It should give suggestions of the collections""" current_config = {'database': 'postgres_db'} form = PostgresDataSource.get_form(postgres_connector, current_config) assert form['properties']['database'] == {'$ref': '#/definitions/database'} assert form['definitions']['database'] == { 'title': 'database', 'description': 'An enumeration.', 'type': 'string', 'enum': ['postgres', 'postgres_db'], } assert form['properties']['table'] == {'$ref': '#/definitions/table'} assert form['definitions']['table'] == { 'title': 'table', 'description': 'An enumeration.', 'type': 'string', 'enum': ['city', 'country', 'countrylanguage'], }
def test_get_form_connection_fails(mocker, postgres_connector): """It should return a form even if connect fails""" mocker.patch.object(pgsql, 'connect').side_effect = IOError form = PostgresDataSource.get_form(postgres_connector, current_config={}) assert 'table' in form['properties']