Example #1
0
    def test_get_리턴한_유저정보_확인(self):
        force_authenticate(self.request, user=self.user)
        today = timezone.now()
        for i in range(10):
            if i == 0:
                first_user = UserFactory(date_joined=today - timedelta(days=i))
            else:
                UserFactory(date_joined=today - timedelta(days=i))
        response = self.view(self.request)

        self.assertEqual(len(response.data), 5)
        self.assertEqual(response.data[0]["name"], first_user.name)
Example #2
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
Example #3
0
def user() -> User:
    return UserFactory()
Example #4
0
def user() -> settings.AUTH_USER_MODEL:
    return UserFactory()
Example #5
0
 def setUp(self):
     factory = APIRequestFactory()
     self.request = factory.get(reverse('users:explore_users'))
     self.view = ExploreUsersView.as_view()
     self.user = UserFactory()