Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
    def test_basic(self):
        instance = FacebookBannerInstanceFactory.create(user=self.user)
        response = self.check(instance.id)
        eq_(json.loads(response.content)['is_processed'], False)

        instance = FacebookBannerInstanceFactory.create(user=self.user,
                                                        processed=True)
        response = self.check(instance.id)
        eq_(json.loads(response.content)['is_processed'], True)
Esempio n. 4
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())
Esempio n. 5
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())
Esempio n. 6
0
 def test_facebook_bot_no_click(self, add_click):
     """If the request is coming from a facebook bot, do not add a click."""
     instance = FacebookBannerInstanceFactory.create(
         banner__link='http://allizom.org')
     response = self.follow_link(instance.id,
                                 HTTP_USER_AGENT=FACEBOOK_USER_AGENT)
     self.assert_redirects(response, 'http://allizom.org')
     ok_(not add_click.delay.called)
Esempio n. 7
0
 def test_notify_not_passed(self):
     """
     If an instance is saved that hasn't passed review, no notification
     should be created.
     """
     instance = FacebookBannerInstanceFactory.create()
     instance.review_status = instance.UNREVIEWED
     instance.save()
     eq_(instance.user.appnotification_set.exists(), False)
 def test_notify_not_passed(self):
     """
     If an instance is saved that hasn't passed review, no notification
     should be created.
     """
     instance = FacebookBannerInstanceFactory.create()
     instance.review_status = instance.UNREVIEWED
     instance.save()
     eq_(instance.user.appnotification_set.exists(), False)
Esempio n. 9
0
 def test_banner_redirect(self, add_click):
     """
     If the requested banner instance exists, return a redirect to the
     parent banner's link.
     """
     instance = FacebookBannerInstanceFactory.create(
         banner__link='http://allizom.org')
     response = self.follow_link(instance.id)
     self.assert_redirects(response, 'http://allizom.org')
     add_click.delay.assert_called_with(unicode(instance.id))
Esempio n. 10
0
    def test_click_milestones(self):
        """If the new click count is a click milestone, send a notification."""
        instance = FacebookBannerInstanceFactory.create(total_clicks=3)
        add_click(instance.id)
        eq_(len(instance.user.appnotification_set.all()), 0)

        add_click(instance.id)
        eq_(len(instance.user.appnotification_set.all()), 1)
        notification = instance.user.appnotification_set.all()[0]
        eq_(notification.message, 'test')
        eq_(notification.format_argument, '5')
Esempio n. 11
0
    def test_admin_email(self):
        """
        If the banner instance has just reached the click goal, email the admin.
        """
        instance = FacebookBannerInstanceFactory.create(total_clicks=29)
        add_click(instance.id)

        eq_(len(mail.outbox), 1)
        eq_(mail.outbox[0].subject, ('[fb-affiliates-banner] Click Goal '
                                     'Reached!'))
        ok_(unicode(instance.id) in mail.outbox[0].body)
        ok_('*****@*****.**' in mail.outbox[0].to)
Esempio n. 12
0
    def test_admin_email(self):
        """
        If the banner instance has just reached the click goal, email the admin.
        """
        instance = FacebookBannerInstanceFactory.create(total_clicks=29)
        add_click(instance.id)

        eq_(len(mail.outbox), 1)
        eq_(mail.outbox[0].subject, ('[fb-affiliates-banner] Click Goal '
                                     'Reached!'))
        ok_(unicode(instance.id) in mail.outbox[0].body)
        ok_('*****@*****.**' in mail.outbox[0].to)
Esempio n. 13
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)
Esempio n. 14
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))
Esempio n. 15
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))
Esempio n. 16
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)
Esempio n. 17
0
    def test_notify_status_changed(self):
        """
        If the instance's review status changes to PASSED, create a
        notification.
        """
        instance = FacebookBannerInstanceFactory.create(
            review_status=FacebookBannerInstance.UNREVIEWED)
        instance.review_status = instance.PASSED
        instance.save()
        eq_(len(instance.user.appnotification_set.all()), 1)

        # Save again; now that the status is already PASSED, it shouldn't
        # generate a new notification.
        instance.save()
        eq_(len(instance.user.appnotification_set.all()), 1)
        eq_(instance.user.appnotification_set.all()[0].message,
            'banner_approved')
Esempio n. 18
0
    def test_notify_status_changed(self):
        """
        If the instance's review status changes to PASSED, create a
        notification.
        """
        instance = FacebookBannerInstanceFactory.create(
            review_status=FacebookBannerInstance.UNREVIEWED)
        instance.review_status = instance.PASSED
        instance.save()
        eq_(len(instance.user.appnotification_set.all()), 1)

        # Save again; now that the status is already PASSED, it shouldn't
        # generate a new notification.
        instance.save()
        eq_(len(instance.user.appnotification_set.all()), 1)
        eq_(instance.user.appnotification_set.all()[0].message,
            'banner_approved')
Esempio n. 19
0
 def instance(self, **kwargs):
     return FacebookBannerInstanceFactory.create(**kwargs)
Esempio n. 20
0
 def instance(self, **kwargs):
     return FacebookBannerInstanceFactory.create(**kwargs)
Esempio n. 21
0
 def test_delete_if_user_owns_banner(self):
     instance = FacebookBannerInstanceFactory.create(user=self.user)
     self._delete(banner_instance=instance.id)
     ok_(not FacebookBannerInstance.objects.filter(id=instance.id).exists())
Esempio n. 22
0
 def test_dont_delete_if_user_doesnt_own_banner(self):
     instance = FacebookBannerInstanceFactory.create()
     self._delete(banner_instance=instance.id)
     ok_(FacebookBannerInstance.objects.filter(id=instance.id).exists())
Esempio n. 23
0
 def setUp(self):
     self.user = FacebookUserFactory.create()
     self.client.fb_login(self.user)
     FacebookBannerInstanceFactory.create(user=self.user)