Exemplo n.º 1
0
    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")
Exemplo n.º 2
0
    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())
Exemplo n.º 3
0
    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())
Exemplo n.º 4
0
    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'
        )