示例#1
0
 def test_get_by_orderId_fail(self):
     param = {"orderId": "123456"}
     try:
         query = build_query(param)
         print("Query = {} ".format(query))
         self.assertTrue(query is not None and query != "")
     except Exception as e:
         self.assertTrue(isinstance(e, MissingParameterException))
     return
示例#2
0
    def find(self, criteria):
        try:
            print("DocDbRepo: Searching for Documents matching criteria: {}".
                  format(str(criteria)))
            search_result = None
            client = self.open()
            results = []
            db = client.get_database(self.appConfig.dbName)
            if self.appConfig.logging_level == self.appConfig.debug:
                print("DocDbRepo: DB = {}".format(db))

            collection = getattr(db, self.appConfig.collectionName)
            if self.appConfig.logging_level == self.appConfig.debug:
                print("DocDbRepo: Collection = {}".format(collection))

            # Build search criteria query string and issue the find() on repo
            query = build_query(criteria)
            print("DocDbRepo: Calling find() for search criteria: {}".format(
                query))
            cursor = collection.find(query)
            if self.appConfig.logging_level == self.appConfig.debug:
                print("DocDbRepo: Cursor: {}".format(str(cursor)))
                print("DocDbRepo: Cursor.count = {}".format(cursor.count()))

            # MAKE SURE we have data!!
            if cursor.count() != 0:
                for doc in cursor:
                    objId = str(doc["_id"])
                    doc["_id"] = objId
                    results.append(doc)
            else:
                print("DocDbRepo: Cursor had 0 elements.")

            #print("DocDbRepo: results = {} ".format(len(results)))
            self.close(client)

            if self.appConfig.logging_level == self.appConfig.debug:
                print("DocDbRepo: results[] count = {}".format(len(results)))

            # Return the first Document in the list of we only have a single
            # Document, otherwise return the entire List<Document>
            return results[0] if len(results) == 1 else results
        except Exception as ex:
            print("DocDbRepo: Exception: {}".format(ex))
            print(ex)
            raise ex
示例#3
0
 def test_invalid_startDate(self):
     param = {"startDate": "02-18-2020"}
     # self.assertRaises(ValueError, )
     with self.assertRaises(DateFormatException):
         build_query(param)
     return
示例#4
0
 def test_get_valid_startDate(self):
     param = {"startDate": "2020/02/18"}
     query = build_query(param)
     print("Query = {}".format(query))
     self.assertTrue("$gte" in str(query))
     return
示例#5
0
 def test_get_valid_request_parameters(self):
     param = {"PageId": "123464", "orderId": "123456"}
     query = build_query(param)
     print("Query = {} ".format(query))
     self.assertTrue(query is not None and query != "")
     return