Beispiel #1
0
    def test_find3(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        result = test.find("test", {"id": 124})

        self.assertEquals(len(result), 0)
Beispiel #2
0
 def test_init4(self):
     try:
         Mongo.Mongo(123, 456, 789)
     except InvalidArgumentsException as err:
         self.assertEquals(err.message, "Invalid Arguments!")
     else:
         raise AssertionError
Beispiel #3
0
 def test_init6(self):
     try:
         Mongo.Mongo(config.database_host, config.database_port, True,
                     config.database_username, config.database_password,
                     "asdasdasd")
     except NoDatabaseException as err:
         self.assertEquals(err.message, "No such Database!")
     else:
         raise AssertionError
Beispiel #4
0
 def test_init3(self):
     try:
         Mongo.Mongo("1.1.1.1", 27017, True, config.database_username,
                     config.database_password, "admin")
     except ConnectFailedException as err:
         self.assertEquals(err.message,
                           "Authentication Required or Connection Error!")
     else:
         raise AssertionError
Beispiel #5
0
    def test_find2(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        result = test.find("test", {"id": 123})

        self.assertEquals(len(result), 1)
        self.assertEquals(result[0]['id'], 123)
        self.assertEquals(result[0]['name'], "asd")
        self.assertEquals(result[0]['asd'], "asdasd")
Beispiel #6
0
 def test_init1(self):
     test = Mongo.Mongo(config.database_host, config.database_port, True,
                        config.database_username, config.database_password,
                        "admin")
     self.assertTrue(isinstance(test, Mongo.Mongo))
     self.assertEquals(
         test.url, "mongodb://{}:{}@{}:{}/".format(config.database_username,
                                                   config.database_password,
                                                   config.database_host,
                                                   config.database_port))
Beispiel #7
0
    def test_find6(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)

        try:
            test.find("test", "asd")
        except InvalidQueryObjectException as err:
            self.assertEquals(err.message, "Invalid Query Object!")
        else:
            raise AssertionError
Beispiel #8
0
    def test_find5(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)

        try:
            test.find(123, {"id": 124})
        except InvalidCollectionException as err:
            self.assertEquals(err.message, "Invalid Collection!")
        else:
            raise AssertionError
Beispiel #9
0
    def test_insert6(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)

        try:
            test.insert("test", [{'id': 124}, "sdf"])
        except InvalidInsertObjectException as err:
            self.assertEquals(err.message, "Invalid Insert Object!")
        else:
            raise AssertionError
Beispiel #10
0
    def test_insert1(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        result = test.insert("test", {"test": "test1", "test2": "test3"})

        self.assertEquals(len(result), 1)

        datas = self.getData()

        self.assertEquals(datas[0]['test'], "test1")
        self.assertEquals(datas[0]['test2'], "test3")
Beispiel #11
0
    def test_remove4(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        collection = 123
        removeQuery = {"test1": "asdf"}

        try:
            test.remove(collection, removeQuery)
        except InvalidCollectionException as err:
            self.assertEquals(err.message, "Invalid Collection!")
        else:
            raise AssertionError
Beispiel #12
0
    def test_remove8(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        collection = "test"
        removeQuery = {}

        try:
            test.remove(collection=collection, removeQuery=removeQuery)
        except RemoveAllNotConfirmedException as err:
            self.assertEquals(err.message, "Remove All not Confirmed!")
        else:
            raise AssertionError
Beispiel #13
0
    def test_remove5(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        collection = "test"
        removeQuery = "{'tet':'test'}"

        try:
            test.remove(collection, removeQuery)
        except InvalidRemoveQueryException as err:
            self.assertEquals(err.message, "Invalid Remove Query!")
        else:
            raise AssertionError
Beispiel #14
0
    def test_remove2(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        collection = "test"
        removeQuery = {"test1": "asdf"}
        result = test.remove(collection, removeQuery, removeMany=True)

        self.assertEquals(result, 2)

        datas = self.getData()

        self.assertEquals(len(datas), 1)
        self.assertEquals(datas[0]['test1'], "qwe")
        self.assertEquals(datas[0]['test2'], "qaq")
Beispiel #15
0
    def test_remove9(self):

        test = Mongo.Mongo(config.database_host, config.database_port, True,
                           config.database_username, config.database_password)
        collection = "test"
        removeQuery = {}

        result = test.remove(collection=collection,
                             removeQuery=removeQuery,
                             removeAllConfirm=True)

        self.assertEquals(result, 3)

        datas = self.getData()

        self.assertEquals(len(datas), 0)