def test_fb_place_insertion(self): """ Tests that all fields from a Facebook page to place are inserted correctly. """ voluto_page = load_test_json("fb_page_square_cafe.json") page_count_before = Place.objects.count() # ensure no FBPageRecord already exists for the given id with self.assertRaises(ExternalPlaceSource.DoesNotExist): ExternalPlaceSource.facebook.get(uid=voluto_page["id"]) with self.assertRaises(Place.DoesNotExist): Place.objects.get(name=u"Square Cafe") with self.assertRaises(Organization.DoesNotExist): Organization.objects.get(name=u"Square Cafe") # add voluto's place page store_fbpage_place(voluto_page) # ensure the place got added as well as the FB record linking it self.assertEquals(Place.objects.count(), page_count_before + 1) try: place = Place.objects.get(name=u"Square Cafe") except Place.DoesNotExist: self.fail("Place not inserted") try: # make sure the stored FBPageRecord has the correct place set record = ExternalPlaceSource.facebook.get(uid=voluto_page["id"]) self.assertEquals(record.place, place) except ExternalPlaceSource.DoesNotExist: self.fail("ExternalPlaceSource not found!") # ensure the Voluto org entry also got created and linked up with FB try: org = Organization.objects.get(name=u"Square Cafe") self.assertEquals(place.owner, org) except Organization.DoesNotExist: self.fail("Organization not created with new Place.") # test various place meta properties are set correctly self.assertEquals("http://www.square-cafe.com", PlaceMeta.objects.get(place=place, meta_key="url").meta_value) self.assertEquals("412.244.8002", PlaceMeta.objects.get(place=place, meta_key="phone").meta_value) self.assertEquals( "http://profile.ak.fbcdn.net/hprofile-ak-snc4/261082_84714961156_1722971382_s.jpg", PlaceMeta.objects.get(place=place, meta_key="image_url").meta_value, ) # now try adding a new place but disallowing the owner to be created bigdog_page = load_test_json("fb_page_library.json") org_count_before = Organization.objects.count() store_fbpage_place(bigdog_page, create_owner=False) try: place = Place.objects.get(name=u"The Library") except Place.DoesNotExist: self.fail("Place not inserted") self.assertIsNone(place.owner) self.assertEquals(org_count_before, Organization.objects.count())
def test_new_event(self): ''' Tests that all fields from a Facebook page to event are inserted correctly. ''' event_fbid = '286153888063194' # Oxford 5k event_info = load_test_json('fb_event_oxford_5k.json') event_count_before = Event.objects.count() # ensure no FBPageRecord already exists for the given id with self.assertRaises(FacebookEventRecord.DoesNotExist): FacebookEventRecord.objects.get(fb_id=event_fbid) store_fbevent(event_info,create_owners=False) self.assertEquals(Event.objects.count(),event_count_before+1) try: event = Event.objects.get(name=u'Oxford Athletic Club Freaky 5K') except Event.DoesNotExist: self.fail('Event not inserted') try: # make ensure the stored FBEventRecord has the correct Event set record = FacebookEventRecord.objects.get(fb_id=event_fbid) self.assertEquals(record.event,event) # ensure the last updated time was set correctly on the event record self.assertEquals(record.last_updated,datetime(2011,9,23,18,27,48)) except Event.DoesNotExist: self.fail('FacebookEventRecord not found!') # check properties of event were stored correctly (see http://graph.facebook.com/291107654260858) # event goes from 10/29/11 13:30 16:30 (UTC time) self.assertEquals(event.dtstart,datetime(2011,10,29,13,30)) self.assertEquals(event.dtend,datetime(2011,10,29,16,30)) self.assertTrue(event.description.startswith(u'Join the Steel City Road Runners Club'))
def test_fb_org_insertion(self): """ Tests that all fields from a Facebook page to org are inserted correctly. (uses predefined page both to test cache functionality and to ensure data is as expected) """ page_info = load_test_json("fb_page_pgh_marathon.json") # pgh marathon page page_id = page_info["id"] org_count_before = Organization.objects.count() # ensure no FBPageRecord already exists for the given id with self.assertRaises(FacebookOrgRecord.DoesNotExist): FacebookOrgRecord.objects.get(fb_id=page_id) with self.assertRaises(Organization.DoesNotExist): Organization.objects.get(name=u"Dick's Sporting Goods Pittsburgh Marathon") store_fbpage_organization(page_info) self.assertEquals(Organization.objects.count(), org_count_before + 1) try: org = Organization.objects.get(name=u"Dick's Sporting Goods Pittsburgh Marathon") except Organization.DoesNotExist: self.fail("Organization not inserted") try: # make sure the stored FBPageRecord has the correct organization set org_on_record = FacebookOrgRecord.objects.get(fb_id=page_id).organization self.assertEquals(org_on_record, org) except FacebookOrgRecord.DoesNotExist: self.fail("FacebookOrgRecord not found!") self.assertEquals(org.avatar, "http://profile.ak.fbcdn.net/hprofile-ak-snc4/41606_139288502700_4851430_s.jpg")
def test_existing_event(self): ''' Tests that an event is not created if an existing event already exists. ''' event_fbid = '291107654260858' # mr. smalls event (already exists via fixture) event_info = load_test_json('fb_event_mr_smalls.json') event_count_before = Event.objects.count() record_count_before = FacebookEventRecord.objects.count() store_fbevent(event_info,create_owners=False) self.assertEquals(event_count_before,Event.objects.count()) # ensure the Facebook record didn't get saved self.assertEquals(record_count_before,FacebookEventRecord.objects.count())
def test_fb_existing_org_insertion(self): """ Tests that an org is not created if an existing org already exists. """ page_info = load_test_json("fb_page_mr_smalls.json") org_count_before = Organization.objects.count() record_count_before = FacebookOrgRecord.objects.count() store_fbpage_organization(page_info) # ensure neither a new organization nor a new FB record was created self.assertEquals(org_count_before, Organization.objects.count()) self.assertEquals(record_count_before, FacebookOrgRecord.objects.count())
def test_fb_existing_place_insertion(self): """ Tests that an place is not created if an existing place already exists. """ existing_page = load_test_json("fb_page_big_dog.json") # (already exists via fixture) page_count_before = Place.objects.count() record_count_before = ExternalPlaceSource.objects.count() store_fbpage_place(existing_page) # ensure neither a new place nor a new FB record was created self.assertEquals(page_count_before, Place.objects.count()) self.assertEquals(record_count_before, ExternalPlaceSource.objects.count())
def test_fb_existing_org_insertion(self): ''' Tests that an org is not created if an existing org already exists. ''' page_info = load_test_json('fb_page_mr_smalls.json') org_count_before = Organization.objects.count() record_count_before = FacebookOrgRecord.objects.count() store_fbpage_organization(page_info) # ensure neither a new organization nor a new FB record was created self.assertEquals(org_count_before, Organization.objects.count()) self.assertEquals(record_count_before, FacebookOrgRecord.objects.count())
def test_fb_existing_place_insertion(self): ''' Tests that an place is not created if an existing place already exists. ''' existing_page = load_test_json( 'fb_page_big_dog.json') # (already exists via fixture) page_count_before = Place.objects.count() record_count_before = ExternalPlaceSource.objects.count() store_fbpage_place(existing_page) # ensure neither a new place nor a new FB record was created self.assertEquals(page_count_before, Place.objects.count()) self.assertEquals(record_count_before, ExternalPlaceSource.objects.count())
def test_fb_org_insertion(self): ''' Tests that all fields from a Facebook page to org are inserted correctly. (uses predefined page both to test cache functionality and to ensure data is as expected) ''' page_info = load_test_json( 'fb_page_pgh_marathon.json') # pgh marathon page page_id = page_info['id'] org_count_before = Organization.objects.count() # ensure no FBPageRecord already exists for the given id with self.assertRaises(FacebookOrgRecord.DoesNotExist): FacebookOrgRecord.objects.get(fb_id=page_id) with self.assertRaises(Organization.DoesNotExist): Organization.objects.get( name=u'Dick\'s Sporting Goods Pittsburgh Marathon') store_fbpage_organization(page_info) self.assertEquals(Organization.objects.count(), org_count_before + 1) try: org = Organization.objects.get( name=u'Dick\'s Sporting Goods Pittsburgh Marathon') except Organization.DoesNotExist: self.fail('Organization not inserted') try: # make sure the stored FBPageRecord has the correct organization set org_on_record = FacebookOrgRecord.objects.get( fb_id=page_id).organization self.assertEquals(org_on_record, org) except FacebookOrgRecord.DoesNotExist: self.fail('FacebookOrgRecord not found!') self.assertEquals( org.avatar, 'http://profile.ak.fbcdn.net/hprofile-ak-snc4/41606_139288502700_4851430_s.jpg' )
def test_fb_place_insertion(self): ''' Tests that all fields from a Facebook page to place are inserted correctly. ''' voluto_page = load_test_json('fb_page_square_cafe.json') page_count_before = Place.objects.count() # ensure no FBPageRecord already exists for the given id with self.assertRaises(ExternalPlaceSource.DoesNotExist): ExternalPlaceSource.facebook.get(uid=voluto_page['id']) with self.assertRaises(Place.DoesNotExist): Place.objects.get(name=u'Square Cafe') with self.assertRaises(Organization.DoesNotExist): Organization.objects.get(name=u'Square Cafe') # add voluto's place page store_fbpage_place(voluto_page) # ensure the place got added as well as the FB record linking it self.assertEquals(Place.objects.count(), page_count_before + 1) try: place = Place.objects.get(name=u'Square Cafe') except Place.DoesNotExist: self.fail('Place not inserted') try: # make sure the stored FBPageRecord has the correct place set record = ExternalPlaceSource.facebook.get(uid=voluto_page['id']) self.assertEquals(record.place, place) except ExternalPlaceSource.DoesNotExist: self.fail('ExternalPlaceSource not found!') # ensure the Voluto org entry also got created and linked up with FB try: org = Organization.objects.get(name=u'Square Cafe') self.assertEquals(place.owner, org) except Organization.DoesNotExist: self.fail('Organization not created with new Place.') # test various place meta properties are set correctly self.assertEquals( 'http://www.square-cafe.com', PlaceMeta.objects.get(place=place, meta_key='url').meta_value) self.assertEquals( '412.244.8002', PlaceMeta.objects.get(place=place, meta_key='phone').meta_value) self.assertEquals( 'http://profile.ak.fbcdn.net/hprofile-ak-snc4/261082_84714961156_1722971382_s.jpg', PlaceMeta.objects.get(place=place, meta_key='image_url').meta_value) # now try adding a new place but disallowing the owner to be created bigdog_page = load_test_json('fb_page_library.json') org_count_before = Organization.objects.count() store_fbpage_place(bigdog_page, create_owner=False) try: place = Place.objects.get(name=u'The Library') except Place.DoesNotExist: self.fail('Place not inserted') self.assertIsNone(place.owner) self.assertEquals(org_count_before, Organization.objects.count())