Exemplo n.º 1
0
def populate_db(count=50):
    """
    Populate DB from fixture data
    """
    UserFactory.create_batch(int(count))
    db.session.commit()
    return 0
Exemplo n.º 2
0
Arquivo: manage.py Projeto: tekd/noi2
def populate_db(count=50):
    """
    Populate DB with random data.
    """
    UserFactory.create_batch(int(count))
    db.session.commit()
    return 0
Exemplo n.º 3
0
def populate_db(count=50):
    """
    Populate DB with random data.
    """
    UserFactory.create_batch(int(count))
    db.session.commit()
    return 0
Exemplo n.º 4
0
def test_login():
    # Create a user
    password = factory.Faker("word")
    user = UserFactory(
        password=factory.PostGenerationMethodCall("set_password", password))

    # Create a client
    client = Client()

    # Login
    assert client.login(username=user.email, password=password)
Exemplo n.º 5
0
def non_staff_user_token():
    user = UserFactory(is_staff=False)
    token, _ = Token.objects.get_or_create(user=user)

    return token
Exemplo n.º 6
0
def test_verification():
    # Create a user
    password = factory.Faker("word")
    user = UserFactory(
        password=factory.PostGenerationMethodCall("set_password", password))

    # Create a client and login
    client = Client()
    client.login(username=user.email, password=password)

    # User is not verified by default
    assert not user.email_verified

    # User is required to be verified
    request = client.get(reverse("app_dashboard"))
    assert isinstance(request, HttpResponseRedirect)
    assert request.status_code == 302
    assert request.url == reverse("user_verify")
    request = client.get(reverse("app_dashboard"), follow=True)
    assert isinstance(request, HttpResponse)
    assert request.status_code == 200
    content = request.content.decode("utf-8")
    assert "<title>Verify your email | " + HACKATHON_APP_NAME + "</title>" in content
    assert user.email in content
    assert reverse("user_sendverification") in content

    # Profile page is available without verification
    request = client.get(reverse("user_profile"))
    assert isinstance(request, HttpResponse)
    assert request.status_code == 200
    content = request.content.decode("utf-8")
    assert "<title>Your profile | " + HACKATHON_APP_NAME + "</title>" in content
    assert user.name in content
    assert user.surname in content
    assert reverse("user_downloadpersonaldata") in content
    assert reverse("user_deactivate") in content

    # However, another user profile page is not available
    request = client.get(reverse("user_profileother", kwargs=dict(id=user.id)))
    assert isinstance(request, HttpResponseRedirect)
    assert request.status_code == 302
    assert request.url == reverse("user_verify")

    # Generate and set a verify key
    verify_key = generate_verify_key(user)
    user.update_verify(verify_key=verify_key)

    # Verify user
    user.verify(verify_key=verify_key)
    assert user.email_verified

    # User is not verified again
    user.disable_verify()
    assert not user.email_verified

    # Generate and set a new verify key
    verify_key = generate_verify_key(user)
    user.update_verify(verify_key=verify_key)

    with mock.patch(
            "django.utils.timezone.now",
            return_value=timezone.now() + timezone.timedelta(hours=2),
    ):
        # Can't verify user as the key has expired
        user.verify(verify_key=verify_key)
        assert not user.email_verified

    # Verify user again without expiration
    user.verify(verify_key=verify_key)
    assert user.email_verified

    # Dashboard is now available
    request = client.get(reverse("app_dashboard"))
    assert isinstance(request, HttpResponse)
    assert request.status_code == 200
    content = request.content.decode("utf-8")
    assert "<title>Dashboard | " + HACKATHON_APP_NAME + "</title>" in content