Пример #1
0
def mock_user_objects_filter():
    usernames = ['test-super', 'test-moderator', 'test-new', 'test-banned',
                 'viagra-test-123']
    users = []
    for username in usernames:
        user = User(username=username)
        user.set_password('test-password')
        users.append(user)
    with mock.patch('kuma.health.views.User') as model:
        model.objects = mock.Mock(spec_set=['only'])
        model.objects.only.return_value = mock.Mock(spec_set=['filter'])
        filter_func = model.objects.only.return_value.filter
        filter_func.return_value = users
        yield filter_func
Пример #2
0
def mock_user_objects_filter():
    usernames = ['test-super', 'test-moderator', 'test-new', 'test-banned',
                 'viagra-test-123']
    users = []
    for username in usernames:
        user = User(username=username)
        user.set_password('test-password')
        users.append(user)
    with mock.patch('kuma.health.views.User') as model:
        model.objects = mock.Mock(spec_set=['only'])
        model.objects.only.return_value = mock.Mock(spec_set=['filter'])
        filter_func = model.objects.only.return_value.filter
        filter_func.return_value = users
        yield filter_func
Пример #3
0
def mock_user_objects_filter():
    usernames = [
        "test-super",
        "test-moderator",
        "test-new",
        "test-banned",
        "viagra-test-123",
    ]
    users = []
    for username in usernames:
        user = User(username=username)
        user.set_password("test-password")
        users.append(user)
    with mock.patch("kuma.health.views.User") as model:
        model.objects = mock.Mock(spec_set=["only"])
        model.objects.only.return_value = mock.Mock(spec_set=["filter"])
        filter_func = model.objects.only.return_value.filter
        filter_func.return_value = users
        yield filter_func
Пример #4
0
def test_ga_tracking_reuse_social_login(settings, client, wiki_user, rf,
                                        mock_track_event):
    """Specifically triggering the GA tracking when it reuses a social login.

    This test is a condensed and not commented version of
    test_user_reuse_on_social_login() above but with the specific case of
    a user with a verified Google account this time logged in using GitHub.

    The most important thing is to test that the track_event() function is
    called.
    """
    provider = "github"
    # When this is set, track_event() will do things.
    settings.GOOGLE_ANALYTICS_ACCOUNT = "UA-XXXX-1"
    # This unhides potential errors that should otherwise be swallowed
    # in regular production use.
    settings.GOOGLE_ANALYTICS_TRACKING_RAISE_ERRORS = True

    wiki_user_social_account = SocialAccount.objects.filter(user=wiki_user,
                                                            provider=provider)
    assert not wiki_user_social_account.exists()
    wiki_user.set_password("qwerty")
    wiki_user.save()

    # social_email_address = wiki_user.email
    user_email_verified = True
    primary_social_email = {
        "email": wiki_user.email,
        "primary": True,
        "verified": user_email_verified,
        "visibility": "public",
    }
    extra_social_email = {
        "email": "*****@*****.**",
        "primary": False,
        "verified": False,
        "visibility": None,
    }
    social_emails = [primary_social_email, extra_social_email]

    social_login = SocialLogin(
        user=User(username="******"),
        account=SocialAccount(
            uid=1234567,
            provider="github",
            extra_data={
                "email": None,
                "login": "******",
                "name": "Paul McCartney",
                "avatar_url": "https://yada/yada",
                "html_url": "https://github.com/new_user",
                "email_addresses": social_emails,
            },
        ),
        email_addresses=[
            EmailAddress(email=a["email"],
                         verified=a["verified"],
                         primary=a["primary"]) for a in social_emails
        ],
    )
    EmailAddress.objects.create(user=wiki_user,
                                email=wiki_user.email,
                                verified=user_email_verified)
    request = rf.get(f"/users/{provider}/login")
    request.user = AnonymousUser()
    request.session = client.session

    response = complete_social_login(request, social_login)
    assert response.status_code == 302
    assert response.url == "/en-US/"

    mock_track_event.assert_called_with(CATEGORY_SIGNUP_FLOW,
                                        ACTION_SOCIAL_AUTH_ADD, "github-added")
Пример #5
0
        "primary": True,
        "verified": social_email_verified,
        "visibility": "public",
    }
    extra_social_email = {
        "email": "*****@*****.**",
        "primary": False,
        "verified": False,
        "visibility": None,
    }
    social_emails = [primary_social_email, extra_social_email]

    if provider == "github":
        other_provider = "google"
        social_login = SocialLogin(
            user=User(username="******"),
            account=SocialAccount(
                uid=1234567,
                provider="github",
                extra_data={
                    "email": None,
                    "login": "******",
                    "name": "Paul McCartney",
                    "avatar_url": "https://yada/yada",
                    "html_url": "https://github.com/new_user",
                    "email_addresses": social_emails,
                },
            ),
            email_addresses=[
                EmailAddress(email=a["email"],
                             verified=a["verified"],
Пример #6
0
def index(request):
    highest_subscriber_number = User.get_highest_subscriber_number()
    context = {"next_subscriber_number": highest_subscriber_number + 1}
    return render(request, "payments/index.html", context)
Пример #7
0
def index(request):
    highest_subscriber_number = User.get_highest_subscriber_number()
    # TODO: This is never unit tested because our tests never test SSR rendering.
    # See https://github.com/mdn/kuma/issues/6797
    context = {"next_subscriber_number": highest_subscriber_number + 1}
    return render(request, "payments/index.html", context)
Пример #8
0
        'primary': True,
        'verified': social_email_verified,
        'visibility': 'public'
    }
    extra_social_email = {
        'email': '*****@*****.**',
        'primary': False,
        'verified': False,
        'visibility': None
    }
    social_emails = [primary_social_email, extra_social_email]

    if provider == 'github':
        other_provider = 'google'
        social_login = SocialLogin(
            user=User(username='******'),
            account=SocialAccount(uid=1234567,
                                  provider='github',
                                  extra_data={
                                      'email': None,
                                      'login': '******',
                                      'name': 'Paul McCartney',
                                      'avatar_url': 'https://yada/yada',
                                      'html_url':
                                      'https://github.com/new_user',
                                      'email_addresses': social_emails
                                  }),
            email_addresses=[
                EmailAddress(email=a['email'],
                             verified=a['verified'],
                             primary=a['primary']) for a in social_emails
Пример #9
0
def index(request):
    if not settings.ENABLE_SUBSCRIPTIONS:
        raise Http404("Not enabled")
    highest_subscriber_number = User.get_highest_subscriber_number()
    context = {"next_subscriber_number": highest_subscriber_number + 1}
    return render(request, "payments/index.html", context)