Ejemplo n.º 1
0
    def test_pulling_from_pages(self):
        '''
        Tests pulling of a batch of FB events by pages -- not Event model saving
        '''
        page_ids = ['40796308305',      # coca-cola's UID
                    '121994841144517',  # place that will probably never have any events
                    '828371892334123']  # invalid fbid
        # add 100 random ids to the list to ensure batch code is working well
        page_ids.extend([str(random.randint(1e13,1e14)) for i in range(100)])
        random.shuffle(page_ids)

        mgr = EventImportManager()
        pid_infos_map = mgr.pull_event_info_from_pages(page_ids)
        self.assertEquals(set(pid_infos_map.keys()),set(page_ids))

        # can't really assert anything about some third party page's events. be content
        # with just testing that there's a few of them and the first one has some 
        # event-specific fields
        events = pid_infos_map['40796308305']
        self.assertGreater(len(events),4)       # should be more than 4? why not.

        # some of the queries will randomly fail. trim these out and ensure less 
        # than 25% of the respopnses are failures
        failures = [ev for ev in events if isinstance(ev,FacebookAPIError)]
        if len(failures) > .25*len(events):
            self.fail('Unexpected large number of failed event pulls (%d of %d).' % (len(failures),len(events)))
        
        for event in events:
            if event not in failures:
                self.assertIn('start_time',event.keys())
                self.assertIn('owner',event.keys())

        # this one should return an empty list
        self.assertEquals(pid_infos_map['121994841144517'],[])
        self.assertEquals(pid_infos_map['828371892334123'],[])
Ejemplo n.º 2
0
    def test_import_by_pages(self):
        '''Tests the importing of all events connected to a batch of pages'''
        pid_expected_pairs = [  ('244531268545',True),      # normal page - Altar Bar
                                ('45577318529',True),       # normal page - August Wilson Ctr
                                ('63893177312',True),       # normal page - Opus One
                                ('121994841144517',False),  # page that shouldn't have events
                                ('9423481220941280',False), # bogus fbid
                ]
        random.shuffle(pid_expected_pairs)

        start_filter = datetime(2012,1,1)
        # a lot of this will depend on live FB data. this test will be pretty 
        #  lightweight. Mostly just looking for unexpected failured.
        pids = [pid for pid,_ in pid_expected_pairs]
        mgr = EventImportManager()
        mgr.pull_event_info_from_pages(pids)
        result_lists = [mgr.import_events_from_page(pid,start_filter=start_filter,import_owners=True)
                            for pid in pids]
        self.assertEquals(len(result_lists),len(pids),
                            'unexpected number of EventImportReport groups returned')

        for pid_exp_pair,result_list in zip(pid_expected_pairs,result_lists):
            pid,expected = pid_exp_pair
            if expected:
                for result in result_list:
                    # basic sanity tests
                    self.assertIsNotNone(result.event_instance)
                    self.assertEquals(result.notices,[])
                    # assert each event starts after the filter time
                    self.assertGreaterEqual(result.event_instance.dtstart,start_filter)
                    # test to make sure the origin page's linked Org ends up as the event host
                    page_linked_org = FacebookOrgRecord.objects.get(fb_id=pid).organization
                    event_owner = result.event_instance.role_set.get(role_type='host').organization
                    self.assertEquals(page_linked_org,event_owner)
            else:
                self.assertEquals([],result_list)