示例#1
0
def testSocketMissing():
    conn_params = {
        'unix_sock': "/file-does-not-exist",
        'user': "******"}

    with pytest.raises(nzpy.InterfaceError):
        nzpy.connect(**conn_params)
示例#2
0
def test_log_file(db, lf, base_log):
    db['logOptions'] = nzpy.LogOptions.Logfile
    nzpy.connect(**db)

    assert lf.exists()
    # parent should have its logs
    assert 'nzpy' not in base_log.getvalue()
    nzpy.connect(**db)
示例#3
0
def test_parent_logging(db, lf, base_log):
    db['logOptions'] = nzpy.LogOptions.Inherit
    nzpy.connect(**db)

    # log file shuoldn't be created
    assert not lf.exists()
    # parent should have its logs
    assert 'nzpy' in base_log.getvalue()
示例#4
0
def test_parent_logging_disabled(db, lf, base_log):
    #db['log_option'] = ~(nzpy.LogOptions.Inherit|nzpy.LogOptions.Logfile)
    db['logOptions'] = nzpy.LogOptions.Disabled
    db['logLevel'] = logging.INFO

    logging.basicConfig()
    logging.error("hello")
    nzpy.connect(**db)
    # log file shuoldn't be created
    assert not lf.exists()
    # parent shouldn't have its logs
    assert 'nzpy' not in base_log.getvalue()
示例#5
0
def test_parent_logging_negative(db, lf, base_log):
    db['logLevel'] = logging.INFO

    for i in [logging.getLogger()] + logging.getLogger().handlers:
        i.setLevel(logging.CRITICAL)

    logging.critical("hello")
    nzpy.connect(**db)
    # log file shuoldn't be created
    assert not lf.exists()
    # parent shouldn't have its logs
    assert 'nzpy' not in base_log.getvalue()
示例#6
0
文件: conftest.py 项目: mderoy/nzpy
def con(request, db_kwargs):
    try:
        sql = [
            '''nzsql -d "system" -Axc "drop database nzpy_test" ''',
        ]
        newProc = subprocess.Popen(sql, stdout=subprocess.PIPE)
        newProc.wait()
    except Exception as exp:
        pass  #consume exception is database does not exist
    try:
        sql = [
            '''nzsql -d "system" -Axc "create database nzpy_test" ''',
        ]
        newProc = subprocess.Popen(sql, stdout=subprocess.PIPE)
        newProc.wait()
    except Exception as exp:
        print(exp)

    conn = nzpy.connect(**db_kwargs)

    def fin():
        conn.rollback()
        try:
            conn.close()
        except nzpy.InterfaceError:
            pass

    request.addfinalizer(fin)
    return conn
示例#7
0
def testBytesPassword(con, db_kwargs):
    # Create user
    username = '******'
    password = '******'
    with con.cursor() as cur:
        cur.execute(
            "create user " + username + " with password '" + password + "';")
        con.commit()

        db_kwargs['user'] = username
        db_kwargs['password'] = password.encode('utf8')
        db_kwargs['database'] = 'nzpy_md5'
        with pytest.raises(nzpy.ProgrammingError, match='handshake'):
            nzpy.connect(**db_kwargs)

        cur.execute("drop user " + username)
        con.commit()
示例#8
0
文件: nz.py 项目: louis-xy/redash
 def connection(self):
     if self._conn is None:
         self._conn = nzpy.connect(
             host=self.configuration.get("host"),
             user=self.configuration.get("user"),
             password=self.configuration.get("password"),
             port=self.configuration.get("port"),
             database=self.configuration.get("database"))
     return self._conn
示例#9
0
 def __init__(self,
              target_url='https://acs-ibooster.telkom.co.id/index.php/',
              driver_loc='/Users/basnugroho/python-projects/chromedriver'):
     self.driver = webdriver.Chrome(driver_loc)
     self.target_url = target_url
     self.conn = nzpy.connect(user="******",
                              password="******",
                              host='10.62.187.9',
                              port=5480,
                              database="TELKOMSHARE5",
                              securityLevel=1,
                              logLevel=0)
示例#10
0
def testUnicodeDatabaseName(db_kwargs):
    db_kwargs["database"] = "nzpy_sn\uFF6Fw"

    # Should only raise an exception saying db doesn't exist
    with pytest.raises(nzpy.ProgrammingError, match='handshake'):
        nzpy.connect(**db_kwargs)
示例#11
0
def testSsl(db_kwargs):
    db_kwargs["ssl"] = True
    with nzpy.connect(**db_kwargs):
        pass
示例#12
0
def testMd5(db_kwargs):
    db_kwargs["database"] = "nzpy_md5"

    # Should only raise an exception saying db doesn't exist
    with pytest.raises(nzpy.ProgrammingError, match='handshake'):
        nzpy.connect(**db_kwargs)
示例#13
0
def testDatabaseMissing(db_kwargs):
    db_kwargs["database"] = "missing-db"
    with pytest.raises(nzpy.ProgrammingError):
        nzpy.connect(**db_kwargs)