Example #1
0
 def test_mongo_insert(self):
     mongo_client_instance = UnibrowserDAO()
     # unit test for insert
     # 1: success, 0: failure
     self.assertEqual(
         mongo_client_instance.insert(
             collection='events',
             documents=[{
                 "_id":
                 ObjectId("5be74773bb5c748668868409"),
                 "title":
                 "Nov 12, 2018: Contemplative Studies Mindfulness Practice Group at Westminster House",
                 "geo_lat":
                 "44.5688",
                 "geo_long":
                 "-123.277418",
                 "published_parsed": [2018, 11, 13, 2, 30, 0, 1, 317, 0],
                 "link":
                 "https://events.oregonstate.edu/event/contemplative_studies_mindfulness_practice_group",
                 "media_content": [{
                     "medium":
                     "image",
                     "url":
                     "https://d3e1o4bcbhmj8g.cloudfront.net/photos/679786/huge/b59ac8bae7d67da25022d5479f1b61ab2af926c9.jpg"
                 }],
                 "tags": [{
                     "term": "Gathering",
                     "scheme": None,
                     "label": None
                 }]
             }]), 1)
Example #2
0
class MongoClientTestCase(unittest.TestCase):
    def setUp(self):
        self.mongoClientInstance = UnibrowserDAO()

    def tearDown(self):
        self.mongoClientInstance = None

    def test_instance_working(self):
        sample_document = {'name': 'example 1', 'id': '1'}

        # test case for insert
        res = self.mongoClientInstance.insert(documents=[sample_document])
        self.assertEqual(1, res, "Error inserting documents")

        # test case for find
        document = self.mongoClientInstance.find(options={'id': '1'})
        self.assertEqual(
            1, len(document),
            "Got more than one document when only one document is expected")
        self.assertDictEqual(sample_document, document[0],
                             "Obtained document do not match the input")

        res = self.mongoClientInstance.delete(options={'id': '1'})
        self.assertEqual(1, res,
                         "Deleted %d documents instead of 1 document" % res)
Example #3
0
def clear() -> bool:
    """
    Completely removes all SportInfo information from persistent storage.
    :returns: true if the operation succeeds, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    results = mongodb.delete(collection=__collection)
    return results >= 0
Example #4
0
def insert_many(faqs: List[Faq]) -> bool:
    """
    Inserts multiple FAQ objects in Unibrowser's persistent storage.
    :param faqs: the list of FAQs to insert
    :returns: true if the insert succeeds, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection, documents=map(Faq.to_object, faqs))
    return result == 1
Example #5
0
def insert(faq: Faq) -> bool:
    """
    Inserts a single FAQ object in Unibrowser's persistent storage.
    :param faq: the FAQ to insert
    :returns: true if the insert succeeds, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection, documents=[faq.to_object()])
    return result == 1
Example #6
0
def insert_many(events) -> bool:
    """
    Inserts multiple SportInfo objects in Unibrowser's persistent storage.
    :param infos: the list of SportInfo objects to insert
    :returns: true if the insert succeeds, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection, documents=events)
    return result == 1
Example #7
0
def insert(info: FreeFoodInfo) -> bool:
    """
    Inserts a single FreeFoodInfo object in Unibrowser's persistent storage.
    :param info: the FreeFoodInfo to insert
    :returns: true if the insert succeeds, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection, documents=[info.to_object()])
    return result == 1
Example #8
0
def insert_many(events: List[Event]) -> bool:
    """
    Inserts multiple event objects into the Unibrowser's persistent storage.
    :param events: a list of event objects to insert into the storage
    :returns: true if the list of events was successfully inserted, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection,
                            documents=map(Event.to_object, events))
    return result == 1
Example #9
0
def insert(event: Event) -> bool:
    """
    Inserts a new event into the Unibrowser's persistent storage.
    :param event: the event to insert
    :returns: true if the event was successfully added, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection,
                            documents=[event.to_object()])
    return result == 1
Example #10
0
def insert_many(profs: List[Professor]) -> bool:
    """
    Inserts multiple professor objects in Unibrowser's persistent storage.
    :param p: the list of professors to insert
    :returns: true if the insert succeeds, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection,
                            documents=map(Professor.to_object, profs))
    return result == 1
Example #11
0
def insert(prof: Professor) -> bool:
    """
    Inserts a single professor object in Unibrowser's persistent storage.
    :param p: the professor to insert
    :returns: true if the insert succeeds, false otherwise
    """
    mongodb = UnibrowserDAO(host=__host, port=__port)
    result = mongodb.insert(collection=__collection,
                            documents=[prof.to_object()])
    return result == 1
Example #12
0
 def test_mongo_insert(self):
     mongo_client_instance = UnibrowserDAO(host=DATABASE_CONFIG['host'],
                                           port=DATABASE_CONFIG['port'],
                                           dbname=DATABASE_CONFIG['dbname'])
     # unit test for insert
     # 1: success, 0: failure
     self.assertEqual(
         mongo_client_instance.insert(
             collection='freefood',
             documents=[{
                 'id': '1059919297479405573',
                 'url': 'https://twitter.com/statuses/1059919297479405573',
                 'screen_name': 'eatfreeOSU',
                 'media_url': '',
                 'description':
                 'Watch the midterm elections, discuss politics, and eat some free Qdoba! 7:30-9:00pm tonight at the APPC.',
                 'location': 'OSU'
             }]), 1)
Example #13
0
 def setUp(self):
     self.mongoClientInstance = UnibrowserDAO()