def setUp(self): self.commented_user = UserFactory() self.comment = CommentUserFactory(content_object=self.commented_user) self.endpoint = reverse('users:user-activities', kwargs={'pk': self.commented_user.pk}) self.reading_user = UserFactory() self.client.force_authenticate(user=self.reading_user) self.response = self.client.get(self.endpoint)
def setUp(self): self.commenter = UserFactory() self.commented_user = UserFactory() self.post_data = {"content": "This is a comment on a User."} self.endpoint = reverse('users:user-comments', kwargs={'pk': self.commented_user.pk}) self.client.force_authenticate(user=self.commenter) self.response = self.client.post(self.endpoint, self.post_data)
def setUp(self): self.login_path = reverse('rest_login') # Create user and verify him self.verified_user = UserFactory(password='******') VerifiedUserFactory(user=self.verified_user) # Create unverified user self.unverified_user = UserFactory(password='******') VerifiedUserFactory(user=self.unverified_user, verified=False)
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
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, # noqa: WPS437 'password2': proto_user._password, # noqa: WPS437 }, ) 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, # noqa: WPS437 'password2': proto_user._password, # noqa: WPS437 }, ) assert not form.is_valid() assert len(form.errors) == 1 assert 'username' in form.errors
def test_add_different_object_id_manually_should_be_ignored(self): different_commented_user = UserFactory() post_data = { "content": "This is a comment on a User.", "object_id": different_commented_user.pk } response = self.client.post(self.endpoint, post_data) assert response.data['object_id'] == str(self.commented_user.pk)
def test_add_different_author_manually_should_be_ignored(self): different_author = UserFactory() post_data = { "content": "This is a comment on a User.", "author": different_author.pk } response = self.client.post(self.endpoint, post_data) assert response.data['author'] == self.commenter.pk
def setUp(self): self.commented_user = UserFactory() self.comment1 = CommentUserFactory(content_object=self.commented_user) self.comment2 = CommentUserFactory(content_object=self.commented_user) self.comment3 = CommentUserFactory(content_object=self.commented_user) self.endpoint = reverse('users:user-comments', kwargs={'pk': self.commented_user.pk}) self.response = self.client.get(self.endpoint)
def setUp(self): self.login_path = reverse('rest_login') self.password_change_path = reverse('rest_password_change') self.verified_user = UserFactory(password='******') VerifiedUserFactory(user=self.verified_user) self.client.login( self.login_path, email=self.verified_user.email, password='******')
def setUp(self): self.user_pk = UserFactory().pk
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='******')
def setUp(self): self.commenter = UserFactory() self.commented_user = UserFactory() self.endpoint = reverse('users:user-comments', kwargs={'pk': self.commented_user.pk}) self.client.force_authenticate(user=self.commenter)
def user() -> User: return UserFactory()
def test_create_comment(self): author = UserFactory() commented_user = UserFactory() Comment.objects.create(author=author, content_object=commented_user, content="A comment.")
def setUp(self): self.password_reset_path = reverse('rest_password_reset') self.verified_user = UserFactory() VerifiedUserFactory(user=self.verified_user)
def setUp(self): self.login_path = reverse('rest_login') self.logout_path = reverse('rest_logout') self.some_user = UserFactory() self.verified_user = UserFactory(password='******') VerifiedUserFactory(user=self.verified_user)