Пример #1
0
class TestMongoReadUtils(unittest.TestCase):
    def setUp(self):
        date_now = datetime.datetime.now()
        self.__mongoReadUtils = MongoReadUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                               FC_DN)
        self.__mongoUtils = MongoSaveUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                           FC_DN, MDN)
        self.__mongoUtils.saveDict("test_dict1", "utf-8", 1234, {
            "the": 1,
            "test": 2
        }, "utf-8", date_now)
        self.__mongoUtils.saveDict("test_dict2", "utf-8", 4321, {
            "the": 100,
            "object": 2
        }, 'utf-8', date_now)
        self.__mongoUtils.mergeDicts()

    def tearDown(self):
        self.__mongoUtils.deleteMergeDict()

    def testGetDict(self):
        self.assertIsNotNone(
            self.__mongoReadUtils.getDict(self.__mongoUtils.getMergeDictID()),
            "dict not found")

    def testGetSubDicts(self):
        for itemSubDicts in self.__mongoReadUtils.getSubDicts(
                self.__mongoUtils.getMergeDictID()):
            self.assertIsNotNone(itemSubDicts, "sub dict get exception")

    def testGetDictData(self):
        for itemDictData in self.__mongoReadUtils.getDictData(
                self.__mongoUtils.getMergeDictID()):
            self.assertIsNotNone(itemDictData, "dict data is not found")
Пример #2
0
class TestMongoSaveUtils(unittest.TestCase):

    def setUp(self):
        try:
            self.__mongoUtils = MongoSaveUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN, MDN)
            self.calcMongo = CalcMongo()
        except ConnectionFailure as e:
            pass

    def tearDown(self):
        try:
            self.__mongoUtils.deleteMergeDict()
        except DataNotFound:
            pass

    def testConnection(self):
        self.assertIsNotNone(self.__mongoUtils, "connection is fail")

    def testGetMergeDictID(self):
        self.assertIsNotNone(self.__mongoUtils.getMergeDictID(), "fail to get merge dict ID")

    def testSaveAddDict(self):
        insertID = self.__mongoUtils.saveDict("test_dict", "utf-8", 1234, {"the": 1, "test": 2},
                                              "utf-8", datetime.datetime.now())
        self.assertIsNotNone(insertID)
        self.__mongoUtils.add2Dict(insertID, {"plus": 1, "test": 2})
        self.__mongoUtils.deleteMergeDict()

    def testMergeDicts(self):
        self.assertIsNotNone(self.__mongoUtils, "connection is ok")
        insertID = self.__mongoUtils.saveDict("test_dict1", "utf-8", 1234, {"the": 1, "test": 2},
                                              "utf-8", datetime.datetime.now())
        self.assertIsNotNone(insertID)

        insertID = self.__mongoUtils.saveDict("test_dict2", "utf-8", 4321, {"the": 100, "object": 2},
                                              'utf-8', datetime.datetime.now())
        self.assertIsNotNone(insertID)
        self.__mongoUtils.mergeDicts()

    def testAddMoreStatistics(self):
        self.assertIsNotNone(self.__mongoUtils, "connection is ok")
        insertID = self.__mongoUtils.saveDict("test_dict3", "utf-8", 1234, {"the": 1, "test": 2},
                                              "utf-8", datetime.datetime.now())
        self.assertIsNotNone(insertID)

        insertID = self.__mongoUtils.saveDict("test_dict4", "utf-8", 4321, {"the": 100, "object": 1},
                                              'utf-8', datetime.datetime.now())
        self.assertIsNotNone(insertID)
        self.__mongoUtils.mergeDicts()
        self.__mongoUtils.addMoreStatistics(self.calcMongo)

    def testAddMoreStatisticsException(self):
        self.assertRaises(ParamError, self.__mongoUtils.addMoreStatistics, None)
        self.assertRaises(ParamError, self.__mongoUtils.addMoreStatistics, 1234)
        self.__mongoUtils.deleteMergeDict()
        self.assertRaises(DataNotFound, self.__mongoUtils.addMoreStatistics, self.calcMongo)
Пример #3
0
class TestMongoReadUtils(unittest.TestCase):

    def setUp(self):
        date_now = datetime.datetime.now()
        self.__mongoReadUtils = MongoReadUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        self.__mongoUtils = MongoSaveUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN, MDN)
        self.__mongoUtils.saveDict("test_dict1", "utf-8", 1234, {"the": 1, "test": 2}, "utf-8", date_now)
        self.__mongoUtils.saveDict("test_dict2", "utf-8", 4321, {"the": 100, "object": 2}, 'utf-8', date_now)
        self.__mongoUtils.mergeDicts()

    def tearDown(self):
        self.__mongoUtils.deleteMergeDict()

    def testGetDict(self):
        self.assertIsNotNone(self.__mongoReadUtils.getDict(self.__mongoUtils.getMergeDictID()), "dict not found")

    def testGetSubDicts(self):
        for itemSubDicts in self.__mongoReadUtils.getSubDicts(self.__mongoUtils.getMergeDictID()):
            self.assertIsNotNone(itemSubDicts, "sub dict get exception")

    def testGetDictData(self):
        for itemDictData in self.__mongoReadUtils.getDictData(self.__mongoUtils.getMergeDictID()):
            self.assertIsNotNone(itemDictData, "dict data is not found")
Пример #4
0
class TestMongoSaveUtils(unittest.TestCase):
    def setUp(self):
        try:
            self.__mongoUtils = MongoSaveUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                               FC_DN, MDN)
            self.calcMongo = CalcMongo()
        except ConnectionFailure as e:
            pass

    def tearDown(self):
        try:
            self.__mongoUtils.deleteMergeDict()
        except DataNotFound:
            pass

    def testConnection(self):
        self.assertIsNotNone(self.__mongoUtils, "connection is fail")

    def testGetMergeDictID(self):
        self.assertIsNotNone(self.__mongoUtils.getMergeDictID(),
                             "fail to get merge dict ID")

    def testSaveAddDict(self):
        insertID = self.__mongoUtils.saveDict("test_dict", "utf-8", 1234, {
            "the": 1,
            "test": 2
        }, "utf-8", datetime.datetime.now())
        self.assertIsNotNone(insertID)
        self.__mongoUtils.add2Dict(insertID, {"plus": 1, "test": 2})
        self.__mongoUtils.deleteMergeDict()

    def testMergeDicts(self):
        self.assertIsNotNone(self.__mongoUtils, "connection is ok")
        insertID = self.__mongoUtils.saveDict("test_dict1", "utf-8", 1234, {
            "the": 1,
            "test": 2
        }, "utf-8", datetime.datetime.now())
        self.assertIsNotNone(insertID)

        insertID = self.__mongoUtils.saveDict("test_dict2", "utf-8", 4321, {
            "the": 100,
            "object": 2
        }, 'utf-8', datetime.datetime.now())
        self.assertIsNotNone(insertID)
        self.__mongoUtils.mergeDicts()

    def testAddMoreStatistics(self):
        self.assertIsNotNone(self.__mongoUtils, "connection is ok")
        insertID = self.__mongoUtils.saveDict("test_dict3", "utf-8", 1234, {
            "the": 1,
            "test": 2
        }, "utf-8", datetime.datetime.now())
        self.assertIsNotNone(insertID)

        insertID = self.__mongoUtils.saveDict("test_dict4", "utf-8", 4321, {
            "the": 100,
            "object": 1
        }, 'utf-8', datetime.datetime.now())
        self.assertIsNotNone(insertID)
        self.__mongoUtils.mergeDicts()
        self.__mongoUtils.addMoreStatistics(self.calcMongo)

    def testAddMoreStatisticsException(self):
        self.assertRaises(ParamError, self.__mongoUtils.addMoreStatistics,
                          None)
        self.assertRaises(ParamError, self.__mongoUtils.addMoreStatistics,
                          1234)
        self.__mongoUtils.deleteMergeDict()
        self.assertRaises(DataNotFound, self.__mongoUtils.addMoreStatistics,
                          self.calcMongo)