Ejemplo 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
Ejemplo n.º 2
0
    def test_clean_email(self):
        """[summary]
        Test user create form
        """

        # A user with proto_user params does not exist yet.
        proto_user = UserFactory.build()

        form = UserCreationForm({
            "email": proto_user.email,
            "password1": proto_user.password,
            "password2": proto_user.password,
        })

        assert form.is_valid()

        # Creating a user.
        form.save()

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

        assert not form.is_valid()
        assert len(form.errors) == 1
        assert "email" in form.errors
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def test_event_creation():
    """[summary]
    Test event model, object create
    """

    owner = UserFactory(email="*****@*****.**")
    event = EventFactory(owner=owner)

    assert event.owner == owner
    assert event.owner.email == "*****@*****.**"
Ejemplo n.º 6
0
    def test_authenticated(self, user: User, rf: RequestFactory):
        """[summary]
        Test Login user can see /users/{user.id}/ (user detail)
        """

        request = rf.get("/fake-url/")
        request.user = UserFactory()

        response = user_detail_view(request, pk=user.id)

        assert response.status_code == 200
Ejemplo n.º 7
0
    def test_create_event(self):
        """[summary]
        Test event create form
        """

        event = EventFactory.build()
        user = UserFactory.build()

        form = EventForm(
            {
                "owner": user,
                "title": event.title,
                "description": event.description,
                "date": event.date,
            }
        )

        assert form.is_valid()
Ejemplo n.º 8
0
def user() -> User:
    return UserFactory()
Ejemplo n.º 9
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="******")
Ejemplo n.º 10
0
def user() -> settings.AUTH_USER_MODEL:
    return UserFactory()