def test_conn_errors(mocker): mocker.patch('ldap2pg.script.dictConfig', autospec=True) mocker.patch('ldap2pg.script.Configuration', autospec=True) mocker.patch('ldap2pg.script.SyncManager', autospec=True) clc = mocker.patch('ldap2pg.script.ldap.connect') PSQL = mocker.patch('ldap2pg.script.PSQL', autospec=True) from ldap2pg.script import ( wrapped_main, ConfigurationError, ldap, psycopg2, ) clc.side_effect = ldap.LDAPError("pouet") with pytest.raises(ConfigurationError): wrapped_main() clc.side_effect = None psql = PSQL.return_value psql.return_value = mocker.MagicMock() psql_ = psql.return_value.__enter__.return_value psql_.side_effect = psycopg2.OperationalError() with pytest.raises(ConfigurationError): wrapped_main()
def test_synchronize_pgconn_error(mocker): from ldap2pg.script import synchronize, ConfigurationError, psycopg2 mod = 'ldap2pg.script' mocker.patch(mod + '.Configuration', new=mocker.MagicMock) mocker.patch(mod + '.ldap.connect') Pooler = mocker.patch(mod + '.Pooler', autospec=True) pool = Pooler.return_value conn = pool.getconn.return_value conn.scalar.side_effect = psycopg2.OperationalError() with pytest.raises(ConfigurationError): synchronize()
def test_conn_errors(mocker): mocker.patch('ldap2pg.script.logging.config.dictConfig', autospec=True) mocker.patch('ldap2pg.script.Configuration', autospec=True) clc = mocker.patch('ldap2pg.script.create_ldap_connection') cpc = mocker.patch('ldap2pg.script.create_pg_connection') from ldap2pg.script import ( wrapped_main, ConfigurationError, ldap3, psycopg2, ) clc.side_effect = ldap3.core.exceptions.LDAPExceptionError("pouet") with pytest.raises(ConfigurationError): wrapped_main() clc.side_effect = None cpc.side_effect = psycopg2.OperationalError() with pytest.raises(ConfigurationError): wrapped_main()
def test_conn_errors(mocker): mocker.patch('ldap2pg.script.dictConfig', autospec=True) mocker.patch('ldap2pg.script.Configuration', autospec=True) SyncManager = mocker.patch('ldap2pg.script.SyncManager', autospec=True) SyncManager.return_value.inspect.return_value = [mocker.Mock()] * 3 clc = mocker.patch('ldap2pg.script.ldap.connect') from ldap2pg.script import ( wrapped_main, ConfigurationError, ldap, psycopg2, ) clc.side_effect = ldap.LDAPError("pouet") with pytest.raises(ConfigurationError): wrapped_main() clc.side_effect = None manager = SyncManager.return_value manager.inspect.side_effect = psycopg2.OperationalError() with pytest.raises(ConfigurationError): wrapped_main()