Example #1
0
    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())
Example #2
0
    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())
Example #3
0
    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())
Example #4
0
    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())