Beispiel #1
0
class TestMongoSearch(unittest.TestCase):
    def setUp(self):
        self.mongoSaveUtils = MongoSaveRetrievalUtils(HOST, PORT, USR, PWD, DB,
                                                      FC_N, FC_DN, MDN)
        retID = self.mongoSaveUtils.saveDict("testing name", "utf-8", 1234, {
            "the": 1,
            "test": 2
        }, "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["testing", "name", "other"],
                                         "testing name~")
        retID = self.mongoSaveUtils.saveDict("some doc", "utf-8", 1234, {
            "some": 20,
            "gg": 50
        }, "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc"], "some doc~")
        retID = self.mongoSaveUtils.saveDict("some doc 2", "utf-8", 1234, {
            "some": 20,
            "gg": 50,
            "n1": 80
        }, "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc", "2"],
                                         "some doc 2~")

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

    def testInitException(self):
        self.assertRaises(ParamError, MongoSearch, None)
        self.assertRaises(TypeError, MongoSearch, "string")
        self.assertRaises(TypeError, MongoSearch, MongoReadUtils, HOST, PORT,
                          USR, PWD, DB, FC_N, FC_DN)

    def testSearchNames(self):
        mongoSearchUtils = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB,
                                                     FC_N, FC_DN)
        cd = {"result_cn": "rcn"}  # customDict
        cdd = {"is_lazy": False}  # customDictData
        mdID = self.mongoSaveUtils.getMergeDictID()

        mongoSearch = MongoSearch(mongoSearchUtils)
        self.assertIsNotNone(
            mongoSearch.searchNames([TYPE_Q_LOGIC, [["doc"], ["doc"]]], cd,
                                    cdd, mdID))
        mongoSearch.removeFindObject()

    def testSearchData(self):
        mongoSearchUtils = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB,
                                                     FC_N, FC_DN)
        cd = {"result_cn": "rcd"}  # customDict
        cdd = {"is_lazy": False}  # customDictData
        mdID = self.mongoSaveUtils.getMergeDictID()

        mongoSearch = MongoSearch(mongoSearchUtils)
        self.assertIsNotNone(
            mongoSearch.searchData([None, ["the"]], cd, cdd, mdID))
        mongoSearch.removeFindObject()
Beispiel #2
0
class TestMongoSaveRetrievalUtils(unittest.TestCase):

    def setUp(self):
        self.__mongoUtils = MongoSaveRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN, MDN)

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

    def testSaveFilename(self):
        retID = self.__mongoUtils.saveDict("testing name", "utf-8", 1234, {"the": 1, "test": 2},
                                           "utf-8", datetime.datetime.now())
        self.__mongoUtils.saveFilename(retID, ["one", "test", "run"], "testing name")

    def testSaveFilenameException(self):
        self.assertRaises(ParamError, self.__mongoUtils.saveFilename, None, 2, 3)
        self.assertRaises(ParamError, self.__mongoUtils.saveFilename, 1, None, 3)
        self.assertRaises(ParamError, self.__mongoUtils.saveFilename, 1, 2, None)
        self.assertRaises(TypeError, self.__mongoUtils.saveFilename, 1, 2, 3)
        self.__mongoUtils.deleteMergeDict()
        self.assertRaises(DataNotFound, self.__mongoUtils.saveFilename, 1, ["one"], "one")
Beispiel #3
0
class TestMongoSearch(unittest.TestCase):

    def setUp(self):
        self.mongoSaveUtils = MongoSaveRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN, MDN)
        retID = self.mongoSaveUtils.saveDict("testing name", "utf-8", 1234, {"the": 1, "test": 2},
                                             "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["testing", "name", "other"], "testing name~")
        retID = self.mongoSaveUtils.saveDict("some doc", "utf-8", 1234, {"some": 20, "gg": 50},
                                             "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc"], "some doc~")
        retID = self.mongoSaveUtils.saveDict("some doc 2", "utf-8", 1234, {"some": 20, "gg": 50, "n1": 80},
                                             "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc", "2"], "some doc 2~")

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

    def testInitException(self):
        self.assertRaises(ParamError, MongoSearch, None)
        self.assertRaises(TypeError, MongoSearch, "string")
        self.assertRaises(TypeError, MongoSearch, MongoReadUtils, HOST, PORT, USR, PWD, DB, FC_N, FC_DN)

    def testSearchNames(self):
        mongoSearchUtils = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        cd = {"result_cn": "rcn"}  # customDict
        cdd = {"is_lazy": False}  # customDictData
        mdID = self.mongoSaveUtils.getMergeDictID()

        mongoSearch = MongoSearch(mongoSearchUtils)
        self.assertIsNotNone(mongoSearch.searchNames([TYPE_Q_LOGIC, [["doc"], ["doc"]]], cd, cdd, mdID))
        mongoSearch.removeFindObject()

    def testSearchData(self):
        mongoSearchUtils = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        cd = {"result_cn": "rcd"}  # customDict
        cdd = {"is_lazy": False}  # customDictData
        mdID = self.mongoSaveUtils.getMergeDictID()

        mongoSearch = MongoSearch(mongoSearchUtils)
        self.assertIsNotNone(mongoSearch.searchData([None, ["the"]], cd, cdd, mdID))
        mongoSearch.removeFindObject()
Beispiel #4
0
class TestMongoSearchRetrievalUtils(unittest.TestCase):

    def setUp(self):
        self.mongoSaveUtils = MongoSaveRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN, MDN)
        retID = self.mongoSaveUtils.saveDict("testing name", "utf-8", 1234, {"the": 1, "test": 2},
                                             "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["testing", "name", "other"], "testing name~")
        retID = self.mongoSaveUtils.saveDict("some doc", "utf-8", 1234, {"some": 20, "gg": 50},
                                             "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc"], "some doc~")
        retID = self.mongoSaveUtils.saveDict("some doc 2", "utf-8", 1234, {"some": 20, "gg": 50, "n1": 80},
                                             "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc", "2"], "some doc 2~")

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

    def testSearchFilename(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        customDict = {"result_cn": "rcn"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        findObject = mongoSearch.searchFilename([TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, mdID)
        self.assertIsNotNone(findObject, "findObject == None")
        mongoSearch.removeSearchData(findObject)

    def testSearchFilenameException(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        customDict = {"result_cn": "rcn"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        self.assertRaises(ParamError, mongoSearch.searchFilename, None, customDict, mdID)
        self.assertRaises(ParamError, mongoSearch.searchFilename, [TYPE_Q_LOGIC, [["doc"], ["doc"]]], None, mdID)
        self.assertRaises(ParamError, mongoSearch.searchFilename, [TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, None)
        self.assertRaises(TypeError, mongoSearch.searchFilename, "string", customDict, mdID)
        self.assertRaises(TypeError, mongoSearch.searchFilename, [TYPE_Q_LOGIC, [["doc"], ["doc"]]], "string", mdID)
        self.assertRaises(KeyError, mongoSearch.searchFilename, [TYPE_Q_LOGIC, [["doc"], ["doc"]]], {"aa": 10}, mdID)

    def testSearchData(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        customDict = {"result_cn": "rcd"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        findObject = mongoSearch.searchData([None, ["the"]], customDict, mdID)
        self.assertIsNotNone(findObject, "findObject == None")
        mongoSearch.removeSearchData(findObject)

    def testSearchDataException(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        customDict = {"result_cn": "rcd"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        self.assertRaises(ParamError, mongoSearch.searchData, None, customDict, mdID)
        self.assertRaises(ParamError, mongoSearch.searchData, [None, [["doc"], ["doc"]]], None, mdID)
        self.assertRaises(ParamError, mongoSearch.searchData, [None, [["doc"], ["doc"]]], customDict, None)
        self.assertRaises(TypeError, mongoSearch.searchData, "string", customDict, mdID)
        self.assertRaises(TypeError, mongoSearch.searchData, [None, [["doc"], ["doc"]]], "string", mdID)
        self.assertRaises(KeyError, mongoSearch.searchData, [None, [["doc"], ["doc"]]], {"aa": 10}, mdID)

    def testGetSearchData(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        customDict = {"result_cn": "rcn"}
        customDictData = {"is_lazy": False}
        mdID = self.mongoSaveUtils.getMergeDictID()

        # поиск по именам источников
        # логический запрос
        findObject = mongoSearch.searchFilename([TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, mdID)
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
        customDictData["is_lazy"] = True
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
            self.assertEqual(int(doc["value"]["count"]), 2, "count != 2")

        # запрос точного совпадения
        customDictData["is_lazy"] = False
        findObject = mongoSearch.searchFilename([TYPE_Q_EXACT, "some doc~"], customDict, mdID)
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
        customDictData["is_lazy"] = True
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")

        mongoSearch.removeSearchData(findObject)

        # поиск по данным из источника
        customDict["result_cn"] = "rcd"
        customDictData["is_lazy"] = False
        findObject = mongoSearch.searchData([None, ["the"]], customDict, mdID)
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
        customDictData["is_lazy"] = True
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
            self.assertEqual(int(doc["value"]["count"]), 1, "count != 1")

        mongoSearch.removeSearchData(findObject)


    def testGetSearchDataException(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N, FC_DN)
        customDict = {"result_cn": "rcn"}
        customDictData = {"is_lazy": False}
        mdID = self.mongoSaveUtils.getMergeDictID()
        findObject = mongoSearch.searchFilename([TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, mdID)

        self.assertRaises(ParamError, mongoSearch.getSearchData, None, customDictData)
        self.assertRaises(ParamError, mongoSearch.getSearchData, findObject, None)
        self.assertRaises(TypeError, mongoSearch.getSearchData, "string", customDictData)
        self.assertRaises(TypeError, mongoSearch.getSearchData, findObject, "string")
        self.assertRaises(KeyError, mongoSearch.getSearchData, findObject, {"bb": 40})

        mongoSearch.removeSearchData(findObject)
Beispiel #5
0
class TestMongoSearchRetrievalUtils(unittest.TestCase):
    def setUp(self):
        self.mongoSaveUtils = MongoSaveRetrievalUtils(HOST, PORT, USR, PWD, DB,
                                                      FC_N, FC_DN, MDN)
        retID = self.mongoSaveUtils.saveDict("testing name", "utf-8", 1234, {
            "the": 1,
            "test": 2
        }, "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["testing", "name", "other"],
                                         "testing name~")
        retID = self.mongoSaveUtils.saveDict("some doc", "utf-8", 1234, {
            "some": 20,
            "gg": 50
        }, "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc"], "some doc~")
        retID = self.mongoSaveUtils.saveDict("some doc 2", "utf-8", 1234, {
            "some": 20,
            "gg": 50,
            "n1": 80
        }, "utf-8", datetime.datetime.now())
        self.mongoSaveUtils.saveFilename(retID, ["some", "doc", "2"],
                                         "some doc 2~")

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

    def testSearchFilename(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                                FC_DN)
        customDict = {"result_cn": "rcn"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        findObject = mongoSearch.searchFilename(
            [TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, mdID)
        self.assertIsNotNone(findObject, "findObject == None")
        mongoSearch.removeSearchData(findObject)

    def testSearchFilenameException(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                                FC_DN)
        customDict = {"result_cn": "rcn"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        self.assertRaises(ParamError, mongoSearch.searchFilename, None,
                          customDict, mdID)
        self.assertRaises(ParamError, mongoSearch.searchFilename,
                          [TYPE_Q_LOGIC, [["doc"], ["doc"]]], None, mdID)
        self.assertRaises(ParamError, mongoSearch.searchFilename,
                          [TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, None)
        self.assertRaises(TypeError, mongoSearch.searchFilename, "string",
                          customDict, mdID)
        self.assertRaises(TypeError, mongoSearch.searchFilename,
                          [TYPE_Q_LOGIC, [["doc"], ["doc"]]], "string", mdID)
        self.assertRaises(KeyError, mongoSearch.searchFilename,
                          [TYPE_Q_LOGIC, [["doc"], ["doc"]]], {"aa": 10}, mdID)

    def testSearchData(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                                FC_DN)
        customDict = {"result_cn": "rcd"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        findObject = mongoSearch.searchData([None, ["the"]], customDict, mdID)
        self.assertIsNotNone(findObject, "findObject == None")
        mongoSearch.removeSearchData(findObject)

    def testSearchDataException(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                                FC_DN)
        customDict = {"result_cn": "rcd"}
        mdID = self.mongoSaveUtils.getMergeDictID()
        self.assertRaises(ParamError, mongoSearch.searchData, None, customDict,
                          mdID)
        self.assertRaises(ParamError, mongoSearch.searchData,
                          [None, [["doc"], ["doc"]]], None, mdID)
        self.assertRaises(ParamError, mongoSearch.searchData,
                          [None, [["doc"], ["doc"]]], customDict, None)
        self.assertRaises(TypeError, mongoSearch.searchData, "string",
                          customDict, mdID)
        self.assertRaises(TypeError, mongoSearch.searchData,
                          [None, [["doc"], ["doc"]]], "string", mdID)
        self.assertRaises(KeyError, mongoSearch.searchData,
                          [None, [["doc"], ["doc"]]], {"aa": 10}, mdID)

    def testGetSearchData(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                                FC_DN)
        customDict = {"result_cn": "rcn"}
        customDictData = {"is_lazy": False}
        mdID = self.mongoSaveUtils.getMergeDictID()

        # поиск по именам источников
        # логический запрос
        findObject = mongoSearch.searchFilename(
            [TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, mdID)
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
        customDictData["is_lazy"] = True
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
            self.assertEqual(int(doc["value"]["count"]), 2, "count != 2")

        # запрос точного совпадения
        customDictData["is_lazy"] = False
        findObject = mongoSearch.searchFilename([TYPE_Q_EXACT, "some doc~"],
                                                customDict, mdID)
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
        customDictData["is_lazy"] = True
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")

        mongoSearch.removeSearchData(findObject)

        # поиск по данным из источника
        customDict["result_cn"] = "rcd"
        customDictData["is_lazy"] = False
        findObject = mongoSearch.searchData([None, ["the"]], customDict, mdID)
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
        customDictData["is_lazy"] = True
        result = mongoSearch.getSearchData(findObject, customDictData)
        for doc in result:
            self.assertIsNotNone(doc, "map-reduce doc == None")
            self.assertEqual(int(doc["value"]["count"]), 1, "count != 1")

        mongoSearch.removeSearchData(findObject)

    def testGetSearchDataException(self):
        mongoSearch = MongoSearchRetrievalUtils(HOST, PORT, USR, PWD, DB, FC_N,
                                                FC_DN)
        customDict = {"result_cn": "rcn"}
        customDictData = {"is_lazy": False}
        mdID = self.mongoSaveUtils.getMergeDictID()
        findObject = mongoSearch.searchFilename(
            [TYPE_Q_LOGIC, [["doc"], ["doc"]]], customDict, mdID)

        self.assertRaises(ParamError, mongoSearch.getSearchData, None,
                          customDictData)
        self.assertRaises(ParamError, mongoSearch.getSearchData, findObject,
                          None)
        self.assertRaises(TypeError, mongoSearch.getSearchData, "string",
                          customDictData)
        self.assertRaises(TypeError, mongoSearch.getSearchData, findObject,
                          "string")
        self.assertRaises(KeyError, mongoSearch.getSearchData, findObject,
                          {"bb": 40})

        mongoSearch.removeSearchData(findObject)