Example #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)
Example #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)
Example #3
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)
Example #4
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)
 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)
Example #6
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())
Example #7
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())
Example #8
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)
Example #9
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)
Example #11
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))
Example #12
0
    def test_valid_id(self):
        """If the given banner id is valid, increment the click count."""
        banner = FacebookBannerInstanceFactory(total_clicks=0)
        add_click(banner.id)

        banner_instance = FacebookBannerInstance.objects.get(id=banner.id)
        eq_(banner_instance.total_clicks, 1)

        stats = FacebookClickStats.objects.get(banner_instance=banner_instance)
        eq_(stats.clicks, 1)
Example #13
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')
Example #14
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)
Example #15
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)
Example #16
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))
Example #17
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))
Example #18
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)
Example #19
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)
    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')
Example #21
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')
Example #22
0
 def instance(self, **kwargs):
     return FacebookBannerInstanceFactory.create(**kwargs)
Example #23
0
 def instance(self, **kwargs):
     return FacebookBannerInstanceFactory.create(**kwargs)
Example #24
0
 def setUp(self):
     self.user = FacebookUserFactory.create()
     self.client.fb_login(self.user)
     FacebookBannerInstanceFactory.create(user=self.user)
Example #25
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())
Example #26
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())