示例#1
0
    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))
示例#2
0
    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))
示例#3
0
    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))
示例#4
0
    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))
示例#5
0
    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))
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
    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)
示例#9
0
    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")
示例#10
0
    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")
示例#11
0
    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)
示例#12
0
    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"))
示例#13
0
    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)
示例#14
0
    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)
示例#15
0
    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))
示例#16
0
    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))
示例#17
0
    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))
示例#18
0
    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))
示例#19
0
    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"))
示例#20
0
    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"))
示例#21
0
    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"))
示例#22
0
    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))
示例#23
0
    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"))
示例#24
0
    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))
示例#25
0
    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)
示例#26
0
    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)
示例#27
0
    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))
示例#28
0
    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))
示例#29
0
    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)
示例#30
0
    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)