def testSocketMissing(): conn_params = { 'unix_sock': "/file-does-not-exist", 'user': "******"} with pytest.raises(nzpy.InterfaceError): nzpy.connect(**conn_params)
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)
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()
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()
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()
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
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()
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
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)
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)
def testSsl(db_kwargs): db_kwargs["ssl"] = True with nzpy.connect(**db_kwargs): pass
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)
def testDatabaseMissing(db_kwargs): db_kwargs["database"] = "missing-db" with pytest.raises(nzpy.ProgrammingError): nzpy.connect(**db_kwargs)