Example #1
0
def test_postgress_get_df(mocker):
    snock = mocker.patch('psycopg2.connect')
    reasq = mocker.patch('pandas.read_sql')

    postgres_connector = PostgresConnector(name='test',
                                           host='localhost',
                                           user='******',
                                           password='******',
                                           port=22)

    ds = PostgresDataSource(
        domain='test',
        name='test',
        database='postgres_db',
        query='SELECT Name, CountryCode, Population FROM City LIMIT 2;',
    )
    postgres_connector.get_df(ds)

    snock.assert_called_once_with(host='localhost',
                                  dbname='postgres_db',
                                  user='******',
                                  password='******',
                                  port=22)

    reasq.assert_called_once_with(
        'SELECT Name, CountryCode, Population FROM City LIMIT 2;',
        con=snock(),
        params={})
def postgres_connector(postgres_server):
    return PostgresConnector(name='test',
                             host='localhost',
                             db='postgres_db',
                             user='******',
                             password='******',
                             port=postgres_server['port'])
Example #3
0
def test_open_connection():
    """ It should not open a connection """
    with pytest.raises(psycopg2.OperationalError):
        ds = PostgresDataSource(domain='pika', name='pika', database='circle_test', query='q')
        PostgresConnector(name='test', host='lolcathost', user='******', connect_timeout=1).get_df(
            ds
        )
def test_open_connection():
    """ It should not open a connection """
    with pytest.raises(psycopg2.OperationalError):
        PostgresConnector(name='test',
                          host='lolcathost',
                          db='circle_test',
                          user='******',
                          connect_timeout=1).get_df({})
Example #5
0
def test_no_user():
    """ It should raise an error as no user is given """
    with pytest.raises(ValidationError):
        PostgresConnector(host='some_host', name='test')