Esempio n. 1
0
def test_user_count(settings):
    """A basic test to execute the get_users_count Celery task."""
    UserFactory.create_batch(3)
    settings.CELERY_TASK_ALWAYS_EAGER = True
    task_result = get_users_count.delay()
    assert isinstance(task_result, EagerResult)
    assert task_result.result == 3
Esempio n. 2
0
    def test_authenticated(self, user: User, rf: RequestFactory):
        request = rf.get("/fake-url/")
        request.user = UserFactory()

        response = user_detail_view(request, username=user.username)

        assert response.status_code == 200
Esempio n. 3
0
    def test_clean_username(self):
        # A user with proto_user params does not exist yet.
        proto_user = UserFactory.build()

        form = UserCreationForm({
            "username": proto_user.username,
            "password1": proto_user._password,
            "password2": proto_user._password,
        })

        assert form.is_valid()
        assert form.clean_username() == proto_user.username

        # Creating a user.
        form.save()

        # The user with proto_user params already exists,
        # hence cannot be created.
        form = UserCreationForm({
            "username": proto_user.username,
            "password1": proto_user._password,
            "password2": proto_user._password,
        })

        assert not form.is_valid()
        assert len(form.errors) == 1
        assert "username" in form.errors
Esempio n. 4
0
    def test_case_sensitivity(self, rf: RequestFactory):
        request = rf.get("/fake-url/")
        request.user = UserFactory(username="******")

        with pytest.raises(Http404):
            user_detail_view(request, username="******")
Esempio n. 5
0
def user() -> User:
    return UserFactory()
Esempio n. 6
0
def user() -> settings.AUTH_USER_MODEL:
    return UserFactory()