Example #1
0
    def test_send_activation_email(self):
        request = self.factory.get('/')
        link = FacebookAccountLinkFactory.create()

        with self.activate('en-US'):
            self.manager.send_activation_email(request, link)
            eq_(len(mail.outbox), 1)
            eq_(mail.outbox[0].subject, 'Link your Firefox Affiliates account')
            ok_(link.activation_link in mail.outbox[0].body)
Example #2
0
 def test_create_link_inactive_link(self):
     """
     If a link exists but is inactive, create_link should return the link.
     """
     link = FacebookAccountLinkFactory.create(is_active=False)
     result = self.manager.create_link(link.facebook_user,
                                       link.affiliates_user.email)
     eq_(result, link)
     eq_(link.is_active, False)
Example #3
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_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))
Example #5
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))
Example #6
0
    def test_create_link_active_link(self):
        """If an active link already exists, create_link should return False."""
        link = FacebookAccountLinkFactory.create(is_active=True)
        result = self.manager.create_link(link.facebook_user,
                                          link.affiliates_user.email)
        eq_(result, False)

        # Test an active link with a different email address.
        user = UserFactory.create()
        result = self.manager.create_link(link.facebook_user, user.email)
        eq_(result, False)
Example #7
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 #8
0
    def test_link_success(self, create_link, send_activation_email):
        """
        If creating a link succeeds, send an activation email and return a 200
        OK.
        """
        link = FacebookAccountLinkFactory.create()
        create_link.return_value = link
        self.client.fb_login(self.user)
        UserFactory.create(email='*****@*****.**')

        response = self.client.post(self.url,
                                    {'affiliates_email': '*****@*****.**'})
        eq_(response.status_code, 200)
        ok_(send_activation_email.called)
        eq_(send_activation_email.call_args[0][1], link)
Example #9
0
    def test_link_success(self, create_link, send_activation_email):
        """
        If creating a link succeeds, send an activation email and return a 200
        OK.
        """
        link = FacebookAccountLinkFactory.create()
        create_link.return_value = link
        self.client.fb_login(self.user)
        UserFactory.create(email='*****@*****.**')

        response = self.client.post(self.url,
                                    {'affiliates_email': '*****@*****.**'})
        eq_(response.status_code, 200)
        ok_(send_activation_email.called)
        eq_(send_activation_email.call_args[0][1], link)
Example #10
0
 def test_activate_link_success(self):
     """If the activation_code is valid, return the new, active link."""
     link = FacebookAccountLinkFactory.create(is_active=False)
     result = self.manager.activate_link(link.activation_code)
     eq_(result, link)
     eq_(result.is_active, True)
Example #11
0
 def test_activate_link_verify_failure(self):
     """If the activation_code fails to verify, return None."""
     link = FacebookAccountLinkFactory.create(activation_code='invalid')
     result = self.manager.activate_link(link.activation_code)
     eq_(result, None)
Example #12
0
 def test_activate_link_active_link(self):
     """If the code corresponds to an already-active link, return None."""
     link = FacebookAccountLinkFactory.create(is_active=True)
     result = self.manager.activate_link(link.activation_code)
     eq_(result, None)