'Test to add a new email in an authenticated user.'

def test_add_a_new_email(self):

    user = UserFactory.create(email='foo@example.com')
    request_mock = Mock(spec=HttpRequest)
    request_mock.user = user
    request_mock.user.is_authenticated = Mock()
    request_mock.user.is_authenticated.return_value = True
    self.backend.request = request_mock
    claims = {'email': 'bar@example.com'}
    email_q = ExternalAccount.objects.filter(type=ExternalAccount.TYPE_EMAIL, user=user.userprofile, identifier='bar@example.com')
    ok_((not email_q.exists()))
    returned_user = self.backend.filter_users_by_claims(claims)
    email_q = ExternalAccount.objects.filter(type=ExternalAccount.TYPE_EMAIL, user=user.userprofile, identifier='bar@example.com')
    ok_(email_q.exists())
    eq_(len(returned_user), 1)
    eq_(returned_user[0], user)
