def test_auth_uri2(self): """Function: test_auth_uri2 Description: Test with auth and uri present. Arguments: """ mongo = mongo_class.DB(self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host, port=self.cfg.port, use_uri=self.cfg.use_uri, auth=self.cfg.auth, use_arg=False, auth_db=True, conf_file=self.cfg.conf_file, ssl_client_ca=self.cfg.ssl_client_ca, ssl_client_key=self.cfg.ssl_client_key, ssl_client_cert=self.cfg.ssl_client_cert, ssl_client_phrase=self.cfg.ssl_client_phrase) mongo.connect() self.assertEqual((mongo.name, mongo.user, mongo.japd, mongo.host, mongo.port, mongo.use_uri), (self.cfg.name, self.cfg.user, self.cfg.japd, self.cfg.host, self.cfg.port, self.cfg.use_uri))
def test_no_auth(self): """Function: test_no_auth Description: Test with no auth present. Arguments: """ mongo = mongo_class.DB(self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host, port=self.cfg.port, use_uri=self.cfg.use_uri, auth=False, use_arg=self.cfg.use_arg, auth_db=self.cfg.auth_db, conf_file=self.cfg.conf_file, ssl_client_ca=self.cfg.ssl_client_ca, ssl_client_key=self.cfg.ssl_client_key, ssl_client_cert=self.cfg.ssl_client_cert, ssl_client_phrase=self.cfg.ssl_client_phrase) self.assertEqual(mongo.connect(), (False, self.errmsg2))
def test_fail_connection(self): """Function: test_fail_connection Description: Test with failed connection. Arguments: """ msg = self.failure errmsg = self.ermsg % msg mongo = mongo_class.DB(self.cfg.name, self.cfg.user, "mytestpd", host=self.cfg.host, port=self.cfg.port, db=self.database, use_arg=self.cfg.use_arg, ssl_client_ca=self.cfg.ssl_client_ca, ssl_client_key=self.cfg.ssl_client_key, ssl_client_cert=self.cfg.ssl_client_cert, ssl_client_phrase=self.cfg.ssl_client_phrase) self.assertEqual(mongo.connect(), (False, errmsg))
def test_db_attr2(self): """Function: test_db_attr2 Description: Test db attribute. Arguments: """ mongo = mongo_class.DB(self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host, port=self.cfg.port, use_uri=self.cfg.use_uri, auth=self.cfg.auth, use_arg=self.cfg.use_arg, auth_db=self.cfg.auth_db, conf_file=self.cfg.conf_file, ssl_client_ca=self.cfg.ssl_client_ca, ssl_client_key=self.cfg.ssl_client_key, ssl_client_cert=self.cfg.ssl_client_cert, ssl_client_phrase=self.cfg.ssl_client_phrase) self.assertEqual(mongo.connect(), (True, None))
def test_fail_get_srv_attr(self): """Function: test_fail_get_srv_attr Description: Test with failed get_srv_attr call. Arguments: """ msg = self.failure errmsg = self.ermsg % msg mongo = mongo_class.DB(self.cfg.name, self.cfg.user, "mytestpd", host=self.cfg.host, port=self.cfg.port, use_uri=self.cfg.use_uri, auth=self.cfg.auth, use_arg=self.cfg.use_arg, auth_db=self.cfg.auth_db, conf_file=self.cfg.conf_file, ssl_client_ca=self.cfg.ssl_client_ca, ssl_client_key=self.cfg.ssl_client_key, ssl_client_cert=self.cfg.ssl_client_cert, ssl_client_phrase=self.cfg.ssl_client_phrase) self.assertEqual(mongo.connect(), (False, errmsg))
def setUp(self): """Function: setUp Description: Initialization for unit testing. Arguments: """ self.base_dir = "test/integration" self.config_dir = os.path.join(self.base_dir, "config") self.config_name = "mongo" self.cfg = gen_libs.load_module(self.config_name, self.config_dir) self.database = "admin" self.tbl_name = "system.users" self.mongo = mongo_class.DB( self.cfg.name, self.cfg.user, self.cfg.japd, host=self.cfg.host, port=self.cfg.port, db=self.database, use_arg=self.cfg.use_arg, ssl_client_ca=self.cfg.ssl_client_ca, ssl_client_key=self.cfg.ssl_client_key, ssl_client_cert=self.cfg.ssl_client_cert, ssl_client_phrase=self.cfg.ssl_client_phrase) self.mongo.connect() self.mongo.chg_db(self.database)
def test_no_auth_uri(self): """Function: test_no_auth_uri Description: Test with auth and no uri present. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertFalse(mongo.use_uri)
def test_no_using_arg(self): """Function: test_no_using_arg Description: Test with auth and no arg present. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertFalse(mongo.use_arg)
def test_using_no_auth_db(self): """Function: test_using_no_auth_db Description: Test using no auth_db attribute. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertEqual(mongo.auth_db, "admin")
def test_no_db_name_attr(self): """Function: test_no_db_name_attr Description: Test no db_name attribute passed. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertEqual(mongo.db_name, "test")
def test_config_attr(self): """Function: test_config_attr Description: Test setting the config attribute. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertEqual(mongo.config, self.config2)
def test_fail_connection(self): """Function: test_fail_connection Description: Test with failed connection. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertEqual(mongo.db_connect("testdb"), (False, "Error Message"))
def test_db_attr(self): """Function: test_db_attr Description: Test db attribute passed. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertFalse(mongo.db)
def test_no_conf_file_attr(self): """Function: test_no_conf_file_attr Description: Test no conf_file attribute passed. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertFalse(mongo.conf_file)
def test_fail_connection2(self): """Function: test_fail_connection2 Description: Test with failed connection. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertEqual((mongo.db), (None))
def test_none_database_passed(self): """Function: test_none_database_passed Description: Test with none database passed. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.conn = DBConn() self.assertEqual(mongo.db_connect(dbs=None), (True, None))
def test_default(self): """Function: test_default Description: Test get_tbl_list method with default arguments. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.db = DBValidate() self.assertTrue(mongo.get_tbl_list(True))
def test_no_database(self): """Function: test_no_database Description: Test with no database passed. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.conn = {"test": "testdb"} self.assertEqual(mongo.db_connect(), (True, None))
def test_object(self): """Function: test_object Description: Test with object passed to method. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.db = DBValidate() self.assertTrue(mongo.db_cmd("command", obj="object_name"))
def test_database_passed2(self): """Function: test_database_passed2 Description: Test with database passed. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.conn = {"testdb": "testdb"} mongo.db_connect("testdb") self.assertEqual((mongo.db), ("testdb"))
def test_default(self): """Function: test_default Description: Test db_cmd method with default arguments. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.db = DBValidate() self.assertTrue(mongo.db_cmd("command"))
def test_fail_connection(self, mock_client, mock_cmd): """Function: test_fail_connection Description: Test with failed connection. Arguments: """ mock_client.return_value = True mock_cmd.return_value = (False, self.errmsg) mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertEqual(mongo.connect(), (False, self.errmsg))
def test_no_database(self): """Function: test_no_database Description: Test with no database passed. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.conn = {"test": "testdb"} mongo.chg_db() self.assertEqual((mongo.db, mongo.db_name), ("testdb", "test"))
def test_no_auth(self): """Function: test_no_auth Description: Test with no auth present. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) self.assertEqual( (mongo.name, mongo.user, mongo.japd, mongo.host, mongo.port), (self.name, self.user, self.japd, self.host, self.port))
def test_ssl_client_ca(self): """Function: test_ssl_client_ca Description: Test with ssl_client_ca attribute. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, host=self.host, port=self.port) self.assertEqual(mongo.ssl_client_ca, None)
def test_name_attr(self): """Function: test_name_attr Description: Test name attribute. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, host=self.host, port=self.port) self.assertEqual(mongo.name, self.name)
def test_no_conn_list1(self, mock_client, mock_cmd): """Function: test_no_conn_list1 Description: Test with no connections passed. Arguments: """ mock_client.return_value = True mock_cmd.return_value = (True, None) mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.conn = {"test": "testdb"} self.assertEqual(mongo.connect(), (True, None))
def test_db_attr2(self, mock_client, mock_cmd): """Function: test_db_attr2 Description: Test db attribute. Arguments: """ mock_client.return_value = True mock_cmd.return_value = (True, None) mongo = mongo_class.DB(self.name, self.user, self.japd, self.host, self.port) mongo.conn = {"test": "testdb"} self.assertEqual(mongo.connect(), (True, None))
def test_conn_attr(self): """Function: test_conn_attr Description: Test conn attribute. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, host=self.host, port=self.port) self.assertFalse(mongo.conn)
def test_default_auth_mech(self): """Function: test_default_auth_mech Description: Test auth_mech default setting. Arguments: """ mongo = mongo_class.DB(self.name, self.user, self.japd, host=self.host, port=self.port) self.assertEqual(mongo.auth_mech, self.auth_mech2)