Exemple #1
0
    def test_filter_country(self):
        """
        If the country field is set, only return users within that country.
        """
        user1 = FacebookUserFactory.create(leaderboard_position=1, country='us')
        FacebookUserFactory.create(leaderboard_position=2, country='fr')
        user3 = FacebookUserFactory.create(leaderboard_position=3, country='us')

        form = LeaderboardFilterForm({'country': 'us'})
        eq_([user1, user3], list(form.get_top_users()))
Exemple #2
0
    def test_exclude_unranked_users(self):
        """
        If a user has a leaderboard position of -1, do not include them in the
        top users list.
        """
        user1 = FacebookUserFactory.create(leaderboard_position=1)
        FacebookUserFactory.create(leaderboard_position=-1)
        user3 = FacebookUserFactory.create(leaderboard_position=2)

        form = LeaderboardFilterForm()
        eq_([user1, user3], list(form.get_top_users()))
Exemple #3
0
    def test_get_top_users(self):
        """
        Test that get_top_users, er, gets the top users ranked by
        leaderboard_position.
        """
        user1 = FacebookUserFactory.create(leaderboard_position=1)
        user2 = FacebookUserFactory.create(leaderboard_position=2)
        user3 = FacebookUserFactory.create(leaderboard_position=3)

        form = LeaderboardFilterForm()
        eq_([user1, user2, user3], list(form.get_top_users()))
Exemple #4
0
    def test_get_top_users(self):
        """
        Test that get_top_users, er, gets the top users ranked by
        leaderboard_position.
        """
        user1 = FacebookUserFactory.create(leaderboard_position=1)
        user2 = FacebookUserFactory.create(leaderboard_position=2)
        user3 = FacebookUserFactory.create(leaderboard_position=3)

        form = LeaderboardFilterForm()
        eq_([user1, user2, user3], list(form.get_top_users()))
Exemple #5
0
    def test_exclude_unranked_users(self):
        """
        If a user has a leaderboard position of -1, do not include them in the
        top users list.
        """
        user1 = FacebookUserFactory.create(leaderboard_position=1)
        FacebookUserFactory.create(leaderboard_position=-1)
        user3 = FacebookUserFactory.create(leaderboard_position=2)

        form = LeaderboardFilterForm()
        eq_([user1, user3], list(form.get_top_users()))
Exemple #6
0
    def test_filter_country(self):
        """
        If the country field is set, only return users within that country.
        """
        user1 = FacebookUserFactory.create(leaderboard_position=1,
                                           country='us')
        FacebookUserFactory.create(leaderboard_position=2, country='fr')
        user3 = FacebookUserFactory.create(leaderboard_position=3,
                                           country='us')

        form = LeaderboardFilterForm({'country': 'us'})
        eq_([user1, user3], list(form.get_top_users()))
Exemple #7
0
    def test_old_user_banner_list(self):
        """If the logged in user is not new, render the banner list page."""
        user = FacebookUserFactory.create()
        self.client.fb_login(user)

        response = self.banner_list()
        self.assertTemplateUsed(response, 'facebook/banner_list.html')
Exemple #8
0
    def test_new_user_first_run(self):
        """If the logged in user is new, redirect them to the first run page."""
        user = FacebookUserFactory.create()
        self.client.fb_login(user)

        response = self.banner_list()
        self.assertTemplateUsed(response, 'facebook/first_run.html')
Exemple #9
0
 def test_create_link_no_account(self):
     """
     If no user exists with the given email, create_link should return False.
     """
     fb_user = FacebookUserFactory.create()
     eq_(self.manager.create_link(fb_user, '*****@*****.**'),
         False)
Exemple #10
0
 def test_create_link_no_account(self):
     """
     If no user exists with the given email, create_link should return False.
     """
     fb_user = FacebookUserFactory.create()
     eq_(self.manager.create_link(fb_user, '*****@*****.**'),
         False)
Exemple #11
0
 def test_newsletter_en_only(self):
     """Only show the newsletter to English locales."""
     user = FacebookUserFactory()
     ok_('newsletter_form' in self._app_context(user=user, locale='en-US'))
     ok_('newsletter_form' in self._app_context(user=user, locale='en-AU'))
     ok_(not 'newsletter_form' in self._app_context(user=user, locale='fr'))
     ok_(not 'newsletter_form' in self._app_context(user=user, locale='de'))
Exemple #12
0
    def test_purge_email(self):
        """
        If a user is being purged and has banners that have passed ad review,
        send an email to the admin with info about the ads that need to be
        removed.
        """
        user = FacebookUserFactory.create()
        instance1 = FacebookBannerInstanceFactory.create(
            user=user, review_status=FacebookBannerInstance.PASSED)
        instance2 = FacebookBannerInstanceFactory.create(
            user=user, review_status=FacebookBannerInstance.PASSED)
        instance3 = FacebookBannerInstanceFactory.create(
            user=user, review_status=FacebookBannerInstance.FAILED)

        user_id = 'User ID: %s' % user.id
        instance1_id = 'Banner Instance ID: %s' % instance1.id
        instance2_id = 'Banner Instance ID: %s' % instance2.id
        instance3_id = 'Banner Instance ID: %s' % instance3.id
        self.manager.purge_user_data(user)

        eq_(len(mail.outbox), 1)
        msg = mail.outbox[0]
        ok_('*****@*****.**' in msg.to)
        ok_(user_id in msg.body)
        ok_(instance1_id in msg.body)
        ok_(instance2_id in msg.body)
        ok_(not instance3_id in msg.body)
Exemple #13
0
 def test_total_for_month(self):
     """Test that the click sum logic is correct."""
     user = FacebookUserFactory.create()
     self._mkstats(user, 2012, 5, 5)
     self._mkstats(user, 2012, 3, 7)
     self._mkstats(user, 2012, 5, 2)
     eq_(self.manager.total_for_month(user, 2012, 5), 7)
Exemple #14
0
    def test_purge_email(self):
        """
        If a user is being purged and has banners that have passed ad review,
        send an email to the admin with info about the ads that need to be
        removed.
        """
        user = FacebookUserFactory.create()
        instance1 = FacebookBannerInstanceFactory.create(
            user=user, review_status=FacebookBannerInstance.PASSED)
        instance2 = FacebookBannerInstanceFactory.create(
            user=user, review_status=FacebookBannerInstance.PASSED)
        instance3 = FacebookBannerInstanceFactory.create(
            user=user, review_status=FacebookBannerInstance.FAILED)

        user_id = 'User ID: %s' % user.id
        instance1_id = 'Banner Instance ID: %s' % instance1.id
        instance2_id = 'Banner Instance ID: %s' % instance2.id
        instance3_id = 'Banner Instance ID: %s' % instance3.id
        self.manager.purge_user_data(user)

        eq_(len(mail.outbox), 1)
        msg = mail.outbox[0]
        ok_('*****@*****.**' in msg.to)
        ok_(user_id in msg.body)
        ok_(instance1_id in msg.body)
        ok_(instance2_id in msg.body)
        ok_(not instance3_id in msg.body)
Exemple #15
0
 def test_total_for_month(self):
     """Test that the click sum logic is correct."""
     user = FacebookUserFactory.create()
     self._mkstats(user, 2012, 5, 5)
     self._mkstats(user, 2012, 3, 7)
     self._mkstats(user, 2012, 5, 2)
     eq_(self.manager.total_for_month(user, 2012, 5), 7)
Exemple #16
0
 def test_valid_user(self, purge_user_data):
     """
     If the supplied user id is valid, call purge_user_data with the user.
     """
     user = FacebookUserFactory.create()
     response = self.deauthorize({'user_id': user.id})
     eq_(response.status_code, 200)
     purge_user_data.assert_called_with(user)
Exemple #17
0
 def test_save_locale(self):
     """The form should save the current locale on the instance."""
     locale = FacebookBannerLocaleFactory.create(locale='es')
     with self.activate('es'):
         form = self.form('es', {'text': 'asdf', 'banner': locale.banner.id},
                          user=FacebookUserFactory.create())
         instance = form.save()
         eq_(instance.locale, 'es')
Exemple #18
0
 def test_create_link_affiliates_already_linked(self):
     """
     If the Affiliates user is already linked to another account, create_link
     should return False.
     """
     link = FacebookAccountLinkFactory.create(is_active=True)
     fb_user = FacebookUserFactory.create()
     result = self.manager.create_link(fb_user, link.affiliates_user.email)
     eq_(result, False)
Exemple #19
0
 def test_create_link_affiliates_already_linked(self):
     """
     If the Affiliates user is already linked to another account, create_link
     should return False.
     """
     link = FacebookAccountLinkFactory.create(is_active=True)
     fb_user = FacebookUserFactory.create()
     result = self.manager.create_link(fb_user, link.affiliates_user.email)
     eq_(result, False)
 def test_notify_new_instance(self):
     """
     If the instance being saved is new, no notification should be created.
     """
     user = FacebookUserFactory.create()
     banner = FacebookBannerFactory.create()
     instance = FacebookBannerInstanceFactory(user=user, banner=banner)
     instance.save()
     eq_(user.appnotification_set.exists(), False)
Exemple #21
0
 def test_notify_new_instance(self):
     """
     If the instance being saved is new, no notification should be created.
     """
     user = FacebookUserFactory.create()
     banner = FacebookBannerFactory.create()
     instance = FacebookBannerInstanceFactory(user=user, banner=banner)
     instance.save()
     eq_(user.appnotification_set.exists(), False)
 def test_user_found(self):
     """
     If there is an authenticated session with an existing user, the
     specified user should be available via the user attribute.
     """
     request = self.request()
     user = FacebookUserFactory.create()
     request.session[SESSION_KEY] = user.id
     self.auth_middleware.process_request(request)
     eq_(request.user, user)
Exemple #23
0
    def test_account_link_form(self):
        """
        If the user doesn't have a linked account, the account_link_form should
        be included in the context.
        """
        unlinked_account = FacebookUserFactory.create()
        ok_('account_link_form' in self._app_context(user=unlinked_account))

        account_link = FacebookAccountLinkFactory.create(is_active=True)
        linked_account = account_link.facebook_user
        ok_('account_link_form' not in self._app_context(user=linked_account))
Exemple #24
0
    def test_facebook_auth(self, update_user_info):
        """
        If the user has authed via the Facebook auth mechanism, execute the
        view.
        """
        request = self.request()
        user = FacebookUserFactory()
        fb_login(request, user)

        response = view(request)
        eq_(response, True)
Exemple #25
0
 def test_save_locale(self):
     """The form should save the current locale on the instance."""
     locale = FacebookBannerLocaleFactory.create(locale='es')
     with self.activate('es'):
         form = self.form('es', {
             'text': 'asdf',
             'banner': locale.banner.id
         },
                          user=FacebookUserFactory.create())
         instance = form.save()
         eq_(instance.locale, 'es')
 def test_user_non_fb_app(self):
     """
     If there is an authenticated session with an existing user outside of
     the app, the specified user should not be a FacebookUser.
     """
     request = self.request(url='/')
     user = FacebookUserFactory.create()
     request.session[SESSION_KEY] = user.id
     self.auth_middleware.process_request(request)
     ok_(not request.user == user)
     eq_(request.user.is_anonymous(), True)
    def test_account_link_form(self):
        """
        If the user doesn't have a linked account, the account_link_form should
        be included in the context.
        """
        unlinked_account = FacebookUserFactory.create()
        ok_("account_link_form" in self._app_context(user=unlinked_account))

        account_link = FacebookAccountLinkFactory.create(is_active=True)
        linked_account = account_link.facebook_user
        ok_("account_link_form" not in self._app_context(user=linked_account))
Exemple #28
0
 def test_create_link_success(self):
     """
     If no link exists, create_link should create one and save it to the
     database.
     """
     fb_user = FacebookUserFactory.create()
     user = UserFactory.create()
     link = self.manager.create_link(fb_user, user.email)
     eq_(link.affiliates_user, user)
     eq_(link.facebook_user, fb_user)
     eq_(link.is_active, False)
     ok_(self.manager.filter(pk=link.pk).exists())
Exemple #29
0
    def test_last_login_attribute(self, mock_datetime, update_user_info):
        """
        During the login process, the last_login attribute on the user must be
        set to the current datetime.
        """
        mock_datetime.now.return_value = datetime(2012, 1, 1)
        request = self.request()
        user = FacebookUserFactory.create(last_login=datetime(2000, 1, 1))
        login(request, user)

        user = refresh_model(user)
        eq_(user.last_login, datetime(2012, 1, 1))
Exemple #30
0
    def test_country_saved(self, login, update_user_info):
        """
        When a user enters the app, their country should be set and
        login should be called with the updated user object so that it will be
        saved to the database.
        """
        user = FacebookUserFactory.create(country='us')
        payload = create_payload(user_id=user.id, country='fr')
        self.load_app(payload)

        eq_(login.called, True)
        eq_(login.call_args[0][1].country, 'fr')
Exemple #31
0
    def test_country_missing(self, login, update_user_info):
        """
        If the user's country is not included in the signed_request, keep their
        old country value intact.
        """
        user = FacebookUserFactory.create(country='us')
        payload = create_payload(user_id=user.id)
        del payload['user']['country']
        self.load_app(payload)

        eq_(login.called, True)
        eq_(login.call_args[0][1].country, 'us')
Exemple #32
0
 def test_create_link_success(self):
     """
     If no link exists, create_link should create one and save it to the
     database.
     """
     fb_user = FacebookUserFactory.create()
     user = UserFactory.create()
     link = self.manager.create_link(fb_user, user.email)
     eq_(link.affiliates_user, user)
     eq_(link.facebook_user, fb_user)
     eq_(link.is_active, False)
     ok_(self.manager.filter(pk=link.pk).exists())
Exemple #33
0
    def test_purge_delete_images(self):
        """
        If there are any custom-generated images for a user's banner instances,
        they must be deleted.
        """
        user = FacebookUserFactory.create()
        instance = FacebookBannerInstanceFactory.create(user=user)
        with open(path('images', 'banner.png')) as banner:
            instance.custom_image.save('custom.png', File(banner))
        file_path = ''.join((settings.MEDIA_ROOT, instance.custom_image.name))

        self.manager.purge_user_data(user)
        ok_(not os.path.exists(file_path))
Exemple #34
0
    def test_user_found(self, activate_locale):
        """
        If there is an authenticated session with an existing user, the
        specified user should be available via the user attribute.
        """
        request = self.request()
        user = FacebookUserFactory.create(locale='fr')
        request.session[SESSION_KEY] = user.id
        self.auth_middleware.process_request(request)
        eq_(request.user, user)

        # Check that the locale from the user object was activated.
        activate_locale.assert_called_once_with(ANY, 'fr')
Exemple #35
0
    def test_purge_delete_images(self):
        """
        If there are any custom-generated images for a user's banner instances,
        they must be deleted.
        """
        user = FacebookUserFactory.create()
        instance = FacebookBannerInstanceFactory.create(user=user)
        with open(path('images', 'banner.png')) as banner:
            instance.custom_image.save('custom.png', File(banner))
        file_path = ''.join((settings.MEDIA_ROOT, instance.custom_image.name))

        self.manager.purge_user_data(user)
        ok_(not os.path.exists(file_path))
Exemple #36
0
    def test_purge_delete_everything(self):
        """Ensure that purge deletes all relevant database entries."""
        fb_user = FacebookUserFactory.create()
        user = UserFactory.create()
        link = FacebookAccountLinkFactory.create(affiliates_user=user,
                                                 facebook_user=fb_user)
        instance = FacebookBannerInstanceFactory.create(user=fb_user)
        personal_items = [(item.__class__, item.id)
                          for item in (fb_user, link, instance)]

        self.manager.purge_user_data(fb_user)
        for klass, id in personal_items:
            eq_(klass.objects.filter(id=id).exists(), False)
Exemple #37
0
    def test_purge_delete_everything(self):
        """Ensure that purge deletes all relevant database entries."""
        fb_user = FacebookUserFactory.create()
        user = UserFactory.create()
        link = FacebookAccountLinkFactory.create(affiliates_user=user,
                                                 facebook_user=fb_user)
        instance = FacebookBannerInstanceFactory.create(user=fb_user)
        personal_items = [(item.__class__, item.id) for item in
                          (fb_user, link, instance)]

        self.manager.purge_user_data(fb_user)
        for klass, id in personal_items:
            eq_(klass.objects.filter(id=id).exists(), False)
Exemple #38
0
    def test_validate_user_owns_banner(self):
        """
        The delete form must validate that the user passed in the constructor
        owns the banner instance.
        """
        user = FacebookUserFactory.create()
        instance1 = FacebookBannerInstanceFactory.create(user=user)
        instance2 = FacebookBannerInstanceFactory.create()

        form = BannerInstanceDeleteForm(user, {'banner_instance': instance1.id})
        ok_(form.is_valid())

        form = BannerInstanceDeleteForm(user, {'banner_instance': instance2.id})
        ok_(not form.is_valid())
Exemple #39
0
    def test_user_non_fb_app(self, activate_locale):
        """
        If there is an authenticated session with an existing user outside of
        the app, the specified user should not be a FacebookUser.
        """
        request = self.request(url='/', locale='pt-BR')
        user = FacebookUserFactory.create()
        request.session[SESSION_KEY] = user.id

        self.auth_middleware.process_request(request)
        ok_(not request.user == user)
        eq_(request.user.is_anonymous(), True)

        # Check that the FB locale stuff was never called.
        eq_(activate_locale.called, False)
    def test_notifications_cleared(self):
        """
        If a page is using the base Facebook template, any AppNotifications for
        the current user should be displayed and then removed from the database.
        """
        user = FacebookUserFactory.create()
        AppNotificationFactory.create(user=user)
        AppNotificationFactory.create(user=user)

        eq_(len(user.appnotification_set.all()), 2)

        with self.activate('en-US'):
            self.client.fb_login(user)
            self.client.get(reverse('facebook.base_test'))

        eq_(len(user.appnotification_set.all()), 0)
Exemple #41
0
    def test_validate_user_owns_banner(self):
        """
        The delete form must validate that the user passed in the constructor
        owns the banner instance.
        """
        user = FacebookUserFactory.create()
        instance1 = FacebookBannerInstanceFactory.create(user=user)
        instance2 = FacebookBannerInstanceFactory.create()

        form = BannerInstanceDeleteForm(user,
                                        {'banner_instance': instance1.id})
        ok_(form.is_valid())

        form = BannerInstanceDeleteForm(user,
                                        {'banner_instance': instance2.id})
        ok_(not form.is_valid())
Exemple #42
0
    def test_delayed_task_overwritten(self, update_user_info):
        """
        Regression test: If DEV is true, the delayed task will execute
        immediately. But because the task does not alter the user object, if the
        old user object is saved these changes will be overwritten.
        """
        request = self.request()
        user = FacebookUserFactory.create(first_name="Unchanged")

        def alter_user(user):
            user.first_name = "Changed"
            user.save()

        update_user_info.side_effect = alter_user

        login(request, user)
        user = refresh_model(user)
        eq_(user.first_name, "Changed")
Exemple #43
0
 def test_total_for_year_none(self):
     """If there are no clicks for the given user, return 0."""
     user = FacebookUserFactory.create()
     eq_(self.manager.total_for_user(user), 0)
Exemple #44
0
 def setUp(self):
     self.user = FacebookUserFactory.create()
     self.client.fb_login(self.user)
Exemple #45
0
 def setUp(self):
     self.user = FacebookUserFactory.create()
     self.client.fb_login(self.user)
     FacebookBannerInstanceFactory.create(user=self.user)
Exemple #46
0
 def user(self, **kwargs):
     user = FacebookUserFactory(**kwargs)
     user.save = Mock()
     return user
Exemple #47
0
 def setUp(self):
     self.user = FacebookUserFactory.create()
     with self.activate('en-US'):
         self.url = reverse('facebook.link_accounts')
Exemple #48
0
 def test_app_notifications(self):
     """If the user is logged in, include all of their app notifications."""
     user = FacebookUserFactory.create()
     notes = [AppNotificationFactory.create(user=user) for x in range(2)]
     eq_(list(self._app_context(user=user)['app_notifications']), notes)
 def test_app_notifications(self):
     """If the user is logged in, include all of their app notifications."""
     user = FacebookUserFactory.create()
     notes = [AppNotificationFactory.create(user=user) for x in range(2)]
     eq_(list(self._app_context(user=user)["app_notifications"]), notes)
Exemple #50
0
 def test_newsletter_form(self, NewsletterSubscriptionForm):
     """If the user is logged in, include the newsletter_form."""
     user = FacebookUserFactory()
     ok_('newsletter_form' in self._app_context(user=user, locale='en-US'))
     NewsletterSubscriptionForm.assert_called_with(user,
                                                   auto_id='newsletter_%s')