Пример #1
0
class TestMongoStatistic(unittest.TestCase):
    def setUp(self):
        self.__mongoUtils = MongoSaveUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                           FC_DN, MDN)
        self.__simpleNormal = SimpleNormalization()
        self.__fileSourceCustom = FileSourceCustom()
        self.__fileBlockSource = FileBlockSource()
        self.__calcMongo = CalcMongo()
        self.__mongoStatistics = MongoStatistic(self.__mongoUtils)
        self.__dirPath = os.path.abspath(os.curdir)

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

    def testMakeDocStatisticCustomUtf8(self):
        filePath = os.path.join(self.__dirPath,
                                "resources/test_mongo_index_utf8")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource,
                                                      self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testMakeDocStatisticCustomWin1251(self):
        filePath = os.path.join(self.__dirPath,
                                "resources/test_mongo_index_win1251")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource,
                                                      self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testMakeDocStatisticCustomWin866(self):
        filePath = os.path.join(self.__dirPath,
                                "resources/test_mongo_index_win866")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource,
                                                      self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testMakeDocStatistic(self):
        data = "Проверка проверка сохранения индекса. Check save statistic"
        self.__mongoStatistics.makeDocStatistic("test_source_name", 1234, data,
                                                self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testAddMoreStatistics(self):
        filePath = os.path.join(self.__dirPath,
                                "resources/test_mongo_index_utf8")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource,
                                                      self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()
        self.__mongoUtils.addMoreStatistics(self.__calcMongo)
Пример #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 TestMongoStatistic(unittest.TestCase):

    def setUp(self):
        self.__mongoUtils = MongoSaveUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN, MDN)
        self.__simpleNormal = SimpleNormalization()
        self.__fileSourceCustom = FileSourceCustom()
        self.__fileBlockSource = FileBlockSource()
        self.__calcMongo = CalcMongo()
        self.__mongoStatistics = MongoStatistic(self.__mongoUtils)
        self.__dirPath = os.path.abspath(os.curdir)

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

    def testMakeDocStatisticCustomUtf8(self):
        filePath = os.path.join(self.__dirPath, "resources/test_mongo_index_utf8")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource, self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testMakeDocStatisticCustomWin1251(self):
        filePath = os.path.join(self.__dirPath, "resources/test_mongo_index_win1251")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource, self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testMakeDocStatisticCustomWin866(self):
        filePath = os.path.join(self.__dirPath, "resources/test_mongo_index_win866")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource, self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testMakeDocStatistic(self):
        data = "Проверка проверка сохранения индекса. Check save statistic"
        self.__mongoStatistics.makeDocStatistic("test_source_name", 1234, data, self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()

    def testAddMoreStatistics(self):
        filePath = os.path.join(self.__dirPath, "resources/test_mongo_index_utf8")
        self.__fileSourceCustom.custom = filePath
        self.__mongoStatistics.makeDocStatisticCustom(self.__fileBlockSource, self.__fileSourceCustom,
                                                      self.__simpleNormal)
        self.__mongoStatistics.makeTotalStatistic()
        self.__mongoUtils.addMoreStatistics(self.__calcMongo)
Пример #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)