def testBlankToday(self): result = self.loadTestJSON("emission/tests/data/test2_blank_today") collect.processResult(self.testUUID, [result[0]]) collect.processResult(self.testUUID, [result[1]]) SectionColl = get_section_db() self.assertTrue(SectionColl.find({'user_id': self.testUUID}).count() > 0)
def testPlaceLoad(self): result = self.loadTestJSON("emission/tests/data/test20140410") collect.processResult(self.testUUID, result) # Check that the trips are loaded correctly TripColl = get_trip_db() firstStoredTrip = TripColl.find_one({'$and': [{'user_id': self.testUUID, 'trip_id': '20140409T191531-0700'}]}) logging.debug("selected trip = %s" % firstStoredTrip) # For some reason, the place is always "unknown", at least for this set of test trips. # Maybe it is related to the fact that they haven't been tagged in FourSquare self.assertEqual(firstStoredTrip['type'], 'place') self.assertEqual(firstStoredTrip['trip_start_time'], '20140409T191531-0700') self.assertEqual(firstStoredTrip['trip_end_time'], "20140410T065227-0700") self.assertIn('place_location', firstStoredTrip['place']) self.assertEqual(firstStoredTrip['place']['place_location'], {'type': 'Point', 'coordinates': [-122.08632, 37.391]}) # Now, check that we have the sections as well. The previous trip did not # have any sections. This one does tripWithSections = TripColl.find_one({'$and': [{'user_id': self.testUUID, 'trip_id': '20140410T071320-0700'}]}) self.assertNotEqual(tripWithSections, None) self.assertEqual(tripWithSections['sections'], [0]) SectionColl = get_section_db() sectionForTrip = SectionColl.find_one({'$and': [{'user_id': self.testUUID, 'trip_id': '20140410T071320-0700', 'section_id': 0}]}) self.assertNotEqual(sectionForTrip, None)
def setUp(self): self.testUUID = "myuuidisverylongandcomplicated" #self.testUserEmails = ["*****@*****.**", "*****@*****.**", "*****@*****.**", # "*****@*****.**", "*****@*****.**"] self.serverName = 'localhost' self.testUsers = [] #for userEmail in self.testUserEmails: # User.register(userEmail) # self.testUsers += [User.fromEmail(section['user_id'])] # can access uuid with .uuid # Sometimes, we may have entries left behind in the database if one of the tests failed # or threw an exception, so let us start by cleaning up all entries self.ModesColl = get_mode_db() self.ModesColl.remove() self.assertEquals(self.ModesColl.find().count(), 0) dataJSON = json.load(open("emission/tests/data/modes.json")) for row in dataJSON: self.ModesColl.insert(row) #TODO: add many trip filter functions to play with self.trip_filters = None result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) self.pipeline = UtilityModelPipeline()
def testBlankToday(self): result = self.loadTestJSON("emission/tests/data/test2_blank_today") collect.processResult(self.testUUID, [result[0]]) collect.processResult(self.testUUID, [result[1]]) SectionColl = get_section_db() self.assertTrue( SectionColl.find({ 'user_id': self.testUUID }).count() > 0)
def testYesterdayForJustSignedUp(self): result = self.loadTestJSON( "emission/tests/data/yesterday_for_justsignedup") collect.processResult(self.testUUID, result) SectionColl = get_section_db() self.assertEquals( SectionColl.find({ "user_id": self.testUUID }).count(), 0)
def testMissingSections(self): result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) SectionColl = get_section_db() storedSections = SectionColl.find({'user_id': self.testUUID}) self.assertEquals(storedSections.count(), 21) tripToWorkSections = SectionColl.find({'$and' : [{'user_id': self.testUUID, 'trip_id': '20140407T085210-0700'}]}) self.assertEquals(tripToWorkSections.count(), 5)
def testPartialLoadUpdate(self): resultAll = self.loadTestJSON("emission/tests/data/missing_trip") resultSubset = self.loadTestJSON("emission/tests/data/missing_trip_subset") collect.processResult(self.testUUID, resultSubset) SectionColl = get_section_db() tripToWorkSections = SectionColl.find({'$and' : [{'user_id': self.testUUID, 'trip_id': '20140407T085210-0700'}]}) self.assertEquals(tripToWorkSections.count(), 3) collect.processResult(self.testUUID, resultAll) tripToWorkSections = SectionColl.find({'$and' : [{'user_id': self.testUUID, 'trip_id': '20140407T085210-0700'}]}) self.assertEquals(tripToWorkSections.count(), 5)
def testMissingSections(self): result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) SectionColl = get_section_db() storedSections = SectionColl.find({'user_id': self.testUUID}) self.assertEquals(storedSections.count(), 21) tripToWorkSections = SectionColl.find({ '$and': [{ 'user_id': self.testUUID, 'trip_id': '20140407T085210-0700' }] }) self.assertEquals(tripToWorkSections.count(), 5)
def testPlaceLoad(self): result = self.loadTestJSON("emission/tests/data/test20140410") collect.processResult(self.testUUID, result) # Check that the trips are loaded correctly TripColl = get_trip_db() firstStoredTrip = TripColl.find_one({ '$and': [{ 'user_id': self.testUUID, 'trip_id': '20140409T191531-0700' }] }) logging.debug("selected trip = %s" % firstStoredTrip) # For some reason, the place is always "unknown", at least for this set of test trips. # Maybe it is related to the fact that they haven't been tagged in FourSquare self.assertEqual(firstStoredTrip['type'], 'place') self.assertEqual(firstStoredTrip['trip_start_time'], '20140409T191531-0700') self.assertEqual(firstStoredTrip['trip_end_time'], "20140410T065227-0700") self.assertIn('place_location', firstStoredTrip['place']) self.assertEqual(firstStoredTrip['place']['place_location'], { 'type': 'Point', 'coordinates': [-122.08632, 37.391] }) # Now, check that we have the sections as well. The previous trip did not # have any sections. This one does tripWithSections = TripColl.find_one({ '$and': [{ 'user_id': self.testUUID, 'trip_id': '20140410T071320-0700' }] }) self.assertNotEqual(tripWithSections, None) self.assertEqual(tripWithSections['sections'], [0]) SectionColl = get_section_db() sectionForTrip = SectionColl.find_one({ '$and': [{ 'user_id': self.testUUID, 'trip_id': '20140410T071320-0700', 'section_id': 0 }] }) self.assertNotEqual(sectionForTrip, None)
def testUpdateSectionForExistingTrip(self): result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) SectionColl = get_section_db() storedSections = SectionColl.find({'user_id': self.testUUID}) self.assertEquals(storedSections.count(), 21) # Trip 20140407T175709-0700 has two sections storedTripSections = SectionColl.find({'$and': [{'user_id': self.testUUID}, {'trip_id': '20140407T175709-0700'}]}) self.assertEquals(storedTripSections.count(), 2) TripColl = get_trip_db() storedTrips = TripColl.find({'$and': [{'user_id': self.testUUID}, {'trip_id': '20140407T175709-0700'}]}) self.assertEquals(storedTrips.count(), 1) for trip in storedTrips: self.assertEquals(len(trip['sections']), 2) selTripFromMoves = None for i, seg in enumerate(result[0]['segments']): if seg['startTime'] == '20140407T175709-0700': selTripFromMoves = seg copiedTripSections = [] for i, act in enumerate(selTripFromMoves['activities']): act['startTime'] = '20140407T18%s039-0700' % (i + 2) copiedTripSections.append(act) self.assertEquals(len(copiedTripSections), 2) [selTripFromMoves['activities'].append(act) for act in copiedTripSections] self.assertEquals(len(selTripFromMoves['activities']), 4) collect.processResult(self.testUUID, result) storedTripSections = SectionColl.find({'$and': [{'user_id': self.testUUID}, {'trip_id': '20140407T175709-0700'}]}) self.assertEquals(storedTripSections.count(), 4) storedTrips = TripColl.find({'$and': [{'user_id': self.testUUID}, {'trip_id': '20140407T175709-0700'}]}) self.assertEquals(storedTrips.count(), 1) # This is actually a bug in the existing code. Need to fix it. for trip in storedTrips: self.assertEquals(len(trip['sections']), 2)
def setUp(self): self.testUUID = "myuuidisverylongandcomplicated" self.serverName = 'localhost' # Sometimes, we may have entries left behind in the database if one of the tests failed # or threw an exception, so let us start by cleaning up all entries self.ModesColl = get_mode_db() self.ModesColl.remove() self.assertEquals(self.ModesColl.find().count(), 0) dataJSON = json.load(open("emission/tests/data/modes.json")) for row in dataJSON: self.ModesColl.insert(row) get_section_db().remove({"user_id": self.testUUID}) result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) print(get_section_db().find().count()) self.pipeline = RecommendationPipeline()
def setUp(self): self.testUUID = "myuuidisverylongandcomplicated" self.serverName = 'localhost' # Sometimes, we may have entries left behind in the database if one of the tests failed # or threw an exception, so let us start by cleaning up all entries self.ModesColl = get_mode_db() self.ModesColl.remove() self.assertEquals(self.ModesColl.find().count(), 0) dataJSON = json.load(open("emission/tests/data/modes.json")) for row in dataJSON: self.ModesColl.insert(row) get_section_db().remove({"user_id": self.testUUID}) result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) print get_section_db().find().count() self.pipeline = RecommendationPipeline()
def setUp(self): self.testUUID = "myuuidisverylongandcomplicated" #self.testUserEmails = ["*****@*****.**", "*****@*****.**", "*****@*****.**", # "*****@*****.**", "*****@*****.**"] self.serverName = 'localhost' self.testUsers = [] #for userEmail in self.testUserEmails: # User.register(userEmail) # self.testUsers += [User.fromEmail(section['user_id'])] # can access uuid with .uuid # Sometimes, we may have entries left behind in the database if one of the tests failed # or threw an exception, so let us start by cleaning up all entries self.ModesColl = edb.get_mode_db() self.ModesColl.remove() edb.get_trip_db().remove() edb.get_section_db().remove() edb.get_alternatives_db().remove() self.assertEquals(self.ModesColl.find().count(), 0) dataJSON = json.load(open("emission/tests/data/modes.json")) for row in dataJSON: self.ModesColl.insert(row) # register each of the users and add sample trips to each user result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) for trip in edb.get_trip_db().find(): trip['trip_start_datetime'] = pydt.datetime.now() + pydt.timedelta( hours=-5) trip['trip_end_datetime'] = pydt.datetime.now() edb.get_trip_db().update({"_id": trip["_id"]}, trip) for section in edb.get_section_db().find(): section['section_start_datetime'] = pydt.datetime.now( ) + pydt.timedelta(hours=-5) section['section_end_datetime'] = pydt.datetime.now() edb.get_section_db().update({"_id": section["_id"]}, section) self.pipeline = AlternativeTripsPipeline()
def setUp(self): self.testUUID = "myuuidisverylongandcomplicated" #self.testUserEmails = ["*****@*****.**", "*****@*****.**", "*****@*****.**", # "*****@*****.**", "*****@*****.**"] self.serverName = 'localhost' self.testUsers = [] #for userEmail in self.testUserEmails: # User.register(userEmail) # self.testUsers += [User.fromEmail(section['user_id'])] # can access uuid with .uuid # Sometimes, we may have entries left behind in the database if one of the tests failed # or threw an exception, so let us start by cleaning up all entries self.ModesColl = edb.get_mode_db() self.ModesColl.remove() edb.get_trip_db().remove() edb.get_section_db().remove() edb.get_alternatives_db().remove() self.assertEquals(self.ModesColl.find().count(), 0) dataJSON = json.load(open("emission/tests/data/modes.json")) for row in dataJSON: self.ModesColl.insert(row) # register each of the users and add sample trips to each user result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) for trip in edb.get_trip_db().find(): trip['trip_start_datetime'] = pydt.datetime.now() + pydt.timedelta(hours=-5) trip['trip_end_datetime'] = pydt.datetime.now() edb.get_trip_db().update({"_id": trip["_id"]}, trip) for section in edb.get_section_db().find(): section['section_start_datetime'] = pydt.datetime.now() + pydt.timedelta(hours=-5) section['section_end_datetime'] = pydt.datetime.now() edb.get_section_db().update({"_id": section["_id"]}, section) self.pipeline = AlternativeTripsPipeline()
def testPartialLoadUpdate(self): resultAll = self.loadTestJSON("emission/tests/data/missing_trip") resultSubset = self.loadTestJSON( "emission/tests/data/missing_trip_subset") collect.processResult(self.testUUID, resultSubset) SectionColl = get_section_db() tripToWorkSections = SectionColl.find({ '$and': [{ 'user_id': self.testUUID, 'trip_id': '20140407T085210-0700' }] }) self.assertEquals(tripToWorkSections.count(), 3) collect.processResult(self.testUUID, resultAll) tripToWorkSections = SectionColl.find({ '$and': [{ 'user_id': self.testUUID, 'trip_id': '20140407T085210-0700' }] }) self.assertEquals(tripToWorkSections.count(), 5)
def testYesterdayForJustSignedUp(self): result = self.loadTestJSON("emission/tests/data/yesterday_for_justsignedup") collect.processResult(self.testUUID, result) SectionColl = get_section_db() self.assertEquals(SectionColl.find({"user_id": self.testUUID}).count(), 0)
def testUpdateSectionForExistingTrip(self): result = self.loadTestJSON("emission/tests/data/missing_trip") collect.processResult(self.testUUID, result) SectionColl = get_section_db() storedSections = SectionColl.find({'user_id': self.testUUID}) self.assertEquals(storedSections.count(), 21) # Trip 20140407T175709-0700 has two sections storedTripSections = SectionColl.find({ '$and': [{ 'user_id': self.testUUID }, { 'trip_id': '20140407T175709-0700' }] }) self.assertEquals(storedTripSections.count(), 2) TripColl = get_trip_db() storedTrips = TripColl.find({ '$and': [{ 'user_id': self.testUUID }, { 'trip_id': '20140407T175709-0700' }] }) self.assertEquals(storedTrips.count(), 1) for trip in storedTrips: self.assertEquals(len(trip['sections']), 2) selTripFromMoves = None for i, seg in enumerate(result[0]['segments']): if seg['startTime'] == '20140407T175709-0700': selTripFromMoves = seg copiedTripSections = [] for i, act in enumerate(selTripFromMoves['activities']): act['startTime'] = '20140407T18%s039-0700' % (i + 2) copiedTripSections.append(act) self.assertEquals(len(copiedTripSections), 2) [ selTripFromMoves['activities'].append(act) for act in copiedTripSections ] self.assertEquals(len(selTripFromMoves['activities']), 4) collect.processResult(self.testUUID, result) storedTripSections = SectionColl.find({ '$and': [{ 'user_id': self.testUUID }, { 'trip_id': '20140407T175709-0700' }] }) self.assertEquals(storedTripSections.count(), 4) storedTrips = TripColl.find({ '$and': [{ 'user_id': self.testUUID }, { 'trip_id': '20140407T175709-0700' }] }) self.assertEquals(storedTrips.count(), 1) # This is actually a bug in the existing code. Need to fix it. for trip in storedTrips: self.assertEquals(len(trip['sections']), 2)
def testWeirdLoadWithNoSections(self): result = self.loadTestJSON("emission/tests/data/test1_blank_today") collect.processResult(self.testUUID, result)