def test_mod_two_cant_see_rejected_responses(self): self.client.force_login(BypassStaffModerationUserFactory()) response = ResponseFactory(approved=False, author=UserFactory(username="******")) ModerationFactory( response=response, addressing_the_issue=False, personal=False, positive_in_tone=False, moderator=UserFactory(username="******"), ) ModerationFactory( response=response, addressing_the_issue=False, personal=False, positive_in_tone=False, moderator=UserFactory(username="******"), ) ModerationFactory( response=response, addressing_the_issue=False, personal=False, positive_in_tone=False, moderator=UserFactory(username="******"), ) result = self.client.get("/api/response/") self.assertEqual(result.status_code, 200) self.assertEqual(len(result.json()["results"]), 0)
def test_mod_one_cant_see_approved_responses(self): self.client.force_login(BypassCommunityModerationUserFactory()) ResponseFactory(approved=False, author=UserFactory(username="******")) ResponseFactory(approved=True, author=UserFactory(username="******")) result = self.client.get("/api/response/") self.assertEqual(result.status_code, 200) self.assertEqual(len(result.json()["results"]), 1)
def test_is_approved_after_moderation(self): response = ResponseFactory(approved=False, author=UserFactory(username="******")) result = self.client.post( reverse("create_moderation", kwargs={"response_pk": response.pk}), data=dict(positive_in_tone=True, addressing_the_issue=True, personal=True), ) self.assertEqual(result.status_code, 201) user = UserFactory(username="******") self.client.force_login(user) result = self.client.post( reverse("create_moderation", kwargs={"response_pk": response.pk}), data=dict(positive_in_tone=True, addressing_the_issue=True, personal=True), ) self.assertEqual(result.status_code, 201) user = UserFactory(username="******") self.client.force_login(user) result = self.client.post( reverse("create_moderation", kwargs={"response_pk": response.pk}), data=dict(positive_in_tone=True, addressing_the_issue=True, personal=True), ) self.assertEqual(result.status_code, 201) response.refresh_from_db() self.assertTrue(response.approved)
def test_mod_two_cant_see_staff_approved_responses(self): self.client.force_login(BypassStaffModerationUserFactory()) ResponseFactory(approved=False, author=UserFactory(username="******")) ResponseFactory(approved=True, author=UserFactory(username="******")) ResponseFactory(approved=True, staff_approved=True, author=UserFactory(username="******")) result = self.client.get('/api/response/') self.assertEqual(result.status_code, 200) self.assertEqual(len(result.json()['results']), 2)
def test_approve_base_user(self): user = UserFactory() self.client.force_login(user) response = ResponseFactory(approved=False, author=UserFactory(username="******")) result = self.client.post( reverse('approve', kwargs={"response_pk": response.pk})) self.assertEqual(result.status_code, 403)
def test_approve_base_user(self, mock_reply_to_review): user = UserFactory() self.client.force_login(user) response = ResponseFactory(approved=False, author=UserFactory(username="******")) result = self.client.post( reverse("approve", kwargs={"response_pk": response.pk}) ) self.assertEqual(result.status_code, 403) mock_reply_to_review.assert_not_called()
def test_cant_see_reject_responses(self): response = ResponseFactory(approved=False, author=UserFactory(username="******")) ModerationFactory(response=response, addressing_the_issue=False, personal=False, positive_in_tone=False, moderator=UserFactory(username="******")) ModerationFactory(response=response, addressing_the_issue=False, personal=False, positive_in_tone=False, moderator=UserFactory(username="******")) ModerationFactory(response=response, addressing_the_issue=False, personal=False, positive_in_tone=False, moderator=UserFactory(username="******")) result = self.client.get('/api/response/') self.assertEqual(result.status_code, 200) self.assertEqual(len(result.json()['results']), 0)
def setUp(self): self.user = UserFactory() self.user.set_password('password') self.user.save() response = ResponseFactory(author=self.user) ModerationFactory.create_batch(response=response, positive_in_tone=True, size=11) # Login self.client.login(username=self.user.username, password='******')
def test_required_moderations(self): user1 = UserFactory(username="******") user2 = UserFactory(username="******") ModerationFactory(response=ResponseFactory(), moderator=user1) ModerationFactory(response=ResponseFactory(), moderator=user1) ModerationFactory(response=ResponseFactory(), moderator=user2) result = Command().active_contributors(required_responses=0, required_moderations=2, period=timedelta(hours=1)) self.assertEqual(result, 1)
class TestUserApi(TestCase): def setUp(self): self.user = UserFactory() self.user.set_password("password") self.user.save() response = ResponseFactory(author=self.user) ModerationFactory.create_batch(response=response, positive_in_tone=True, size=11) # Login self.client.login(username=self.user.username, password="******") def test_user_profile_api(self): response = self.client.get(reverse("my_user")) self.assertCountEqual( response.data["profile"].keys(), [ "karma_points", "moderation_count", "response_count", "languages", "name", "avatar", "can_skip_community_response_moderation", "stats", "is_super_moderator", ], ) def test_user_api(self): response = self.client.get(reverse("my_user")) self.assertCountEqual(response.data.keys(), ["username", "email", "profile"]) def test_user_profile_stats_api(self): response = self.client.get(reverse("my_user")) self.assertCountEqual( response.data["profile"]["stats"].keys(), [ "positive_in_tone_count", "positive_in_tone_change", "addressing_the_issue_count", "addressing_the_issue_change", "personal_count", "personal_change", "previous_count", "current_count", ], )
def create(cls, **kwargs): obj = super().create(**kwargs) obj.is_valid() obj.save( review=ReviewFactory(), author=kwargs.get("author", UserFactory()), ) return obj
def test_user_non_moderator(self): user = UserFactory( profile=factory.RelatedFactory( "mresponse.users.tests.factories.UserProfileFactory", factory_related_name="user", permissions_in_locales=["en"], ) ) review = ReviewFactory(review_language="en") self.assertFalse(user_can_bypass_staff_approval_for_review(user, review))
def test_put_changes_to_response_as_moderator(self): user = UserFactory() self.client.force_login(user) response = ResponseFactory(approved=False, text="Bad response", author=self.author_user) good_text = "GooD Response." result = self.client.put('/api/response/{}/'.format(response.pk), dict(text=good_text)) self.assertEqual(result.status_code, 403)
def test_first_moderation(self): self.assertEqual(self.user.profile.karma_points, 0) response = ResponseFactory(approved=False, author=UserFactory(username="******")) self.assertEqual(response.moderation_count(), 0) result = self.client.post( reverse("create_moderation", kwargs={"response_pk": response.pk}), data=dict(positive_in_tone=True, addressing_the_issue=True, personal=True), ) self.assertEqual(result.status_code, 201) self.user.profile.refresh_from_db() self.assertEqual(self.user.profile.karma_points, 1)
def test_create_moderation(self, mock_reply_to_review): response = ResponseFactory(approved=False, author=UserFactory(username="******")) result = self.client.post( reverse("create_moderation", kwargs={"response_pk": response.pk}), data=dict(positive_in_tone=True, addressing_the_issue=True, personal=True), ) self.assertEqual(result.status_code, 201) mock_reply_to_review.assert_not_called() response.refresh_from_db() self.assertFalse(response.approved) self.assertFalse(response.staff_approved) self.assertFalse(response.submitted_to_play_store)
def test_approval_as_mod_two(self): user = BypassStaffModerationUserFactory() self.client.force_login(user) response = ResponseFactory(approved=False, author=UserFactory(username="******")) result = self.client.post( reverse('approve', kwargs={"response_pk": response.pk})) self.assertEqual(result.status_code, 200) response.refresh_from_db() self.assertTrue(response.approved) self.assertTrue(response.staff_approved)
class TestUserApi(TestCase): def setUp(self): self.user = UserFactory() self.user.set_password('password') self.user.save() response = ResponseFactory(author=self.user) ModerationFactory.create_batch(response=response, positive_in_tone=True, size=11) # Login self.client.login(username=self.user.username, password='******') def test_user_profile_api(self): response = self.client.get(reverse('my_user')) self.assertCountEqual(response.data['profile'].keys(), [ 'karma_points', 'moderation_count', 'response_count', 'languages', 'name', 'avatar', 'can_skip_community_response_moderation', 'stats', 'is_super_moderator' ]) def test_user_api(self): response = self.client.get(reverse('my_user')) self.assertCountEqual(response.data.keys(), ['username', 'email', 'profile']) def test_user_profile_stats_api(self): response = self.client.get(reverse('my_user')) self.assertCountEqual(response.data['profile']['stats'].keys(), [ 'positive_in_tone_count', 'positive_in_tone_change', 'addressing_the_issue_count', 'addressing_the_issue_change', 'personal_count', 'personal_change', 'previous_count', 'current_count', ])
def test_approval_as_mod_two(self, mock_reply_to_review): user = BypassStaffModerationUserFactory() self.client.force_login(user) response = ResponseFactory(approved=False, author=UserFactory(username="******")) result = self.client.post( reverse("approve", kwargs={"response_pk": response.pk}) ) self.assertEqual(result.status_code, 200) mock_reply_to_review.assert_called() response.refresh_from_db() self.assertTrue(response.approved) self.assertTrue(response.staff_approved) self.assertTrue(response.submitted_to_play_store)
def test_first_approval(self): user = BypassCommunityModerationUserFactory() self.client.force_login(user) author = UserFactory(username="******") response = ResponseFactory(approved=False, author=author) result = self.client.post( reverse('approve', kwargs={"response_pk": response.pk})) self.assertEqual(result.status_code, 200) user.profile.refresh_from_db() author.profile.refresh_from_db() self.assertEqual(user.profile.karma_points, 1) self.assertEqual(author.profile.karma_points, 1)
def test_is_staff_approved_after_moderation_by_mod_two(self): response = ResponseFactory(approved=False, author=UserFactory(username="******")) ModerationFactory(response=response, positive_in_tone=True) ModerationFactory(response=response, positive_in_tone=True) self.client.force_login(BypassStaffModerationUserFactory()) result = self.client.post(reverse('create_moderation', kwargs={"response_pk": response.pk}), data=dict( positive_in_tone=True, addressing_the_issue=True, personal=True )) self.assertEqual(result.status_code, 201) response.refresh_from_db() self.assertTrue(response.approved) self.assertTrue(response.staff_approved)
def test_isnt_staff_approved_after_moderation_by_mod_two_without_locale( self, mock_moderator_in_review_langauge, mock_reply_to_review ): mock_moderator_in_review_langauge.return_value = False response = ResponseFactory(approved=False, author=UserFactory(username="******")) self.client.force_login(BypassStaffModerationUserFactory()) result = self.client.post( reverse("create_moderation", kwargs={"response_pk": response.pk}), data=dict(positive_in_tone=True, addressing_the_issue=True, personal=True), ) self.assertEqual(result.status_code, 201) mock_reply_to_review.assert_not_called() response.refresh_from_db() self.assertTrue(response.approved) self.assertFalse(response.staff_approved) self.assertFalse(response.submitted_to_play_store)
def test_is_rejected_after_negative_moderations(self, mock_reply_to_review): response = ResponseFactory(approved=False, author=UserFactory(username="******")) # TODO: I don't think these ModerationFactories should be required - once a review has a moderation # failing on all three counts, it won't meet the approved criteria and should be immediately rejected, no? ModerationFactory(response=response) ModerationFactory(response=response) result = self.client.post( reverse("create_moderation", kwargs={"response_pk": response.pk}), data=dict(positive_in_tone=False, addressing_the_issue=False, personal=False), ) response.refresh_from_db() self.assertEqual(result.status_code, 201) self.assertTrue(response.rejected)
def test_mod_two_can_see_approved_responses(self): self.client.force_login(BypassStaffModerationUserFactory()) response = ResponseFactory(approved=False, author=UserFactory(username="******")) ModerationFactory(response=response, moderator=UserFactory(username="******")) ModerationFactory(response=response, moderator=UserFactory(username="******")) ModerationFactory(response=response, moderator=UserFactory(username="******")) response.refresh_from_db() self.assertTrue(response.is_community_approved()) ResponseFactory(approved=True, author=UserFactory(username="******")) ResponseFactory(approved=True, staff_approved=True, author=UserFactory(username="******")) result = self.client.get('/api/response/') self.assertEqual(result.status_code, 200) self.assertEqual(len(result.json()['results']), 2)
def test_approval_after_moderation_by_staff(self): user = BypassStaffModerationUserFactory() self.client.force_login(user) self.assertEqual(user.profile.karma_points, 0) author = UserFactory(username="******") response = ResponseFactory(approved=False, author=author) ModerationFactory(response=response) ModerationFactory(response=response) ModerationFactory(response=response) result = self.client.post( reverse("approve", kwargs={"response_pk": response.pk}) ) self.assertEqual(result.status_code, 200) user.profile.refresh_from_db() author.profile.refresh_from_db() self.assertEqual(user.profile.karma_points, 3) self.assertEqual(author.profile.karma_points, 1)
def setUp(self): self.user = UserFactory() self.client.force_login(self.user)
def setUp(self) -> None: self.user = UserFactory()
def test_superuser(self): user = UserFactory(is_superuser=True) review = ReviewFactory(review_language="de") self.assertTrue(user_can_bypass_staff_approval_for_review(user, review))
def setUp(self): self.user = UserFactory() self.author_user = UserFactory(username="******") self.client.force_login(self.user)
def test_get_responses(self): ResponseFactory(approved=False, author=UserFactory(username="******")) result = self.client.get("/api/response/") self.assertEqual(result.status_code, 200) self.assertEqual(len(result.json()["results"]), 1)
def test_cannot_skip_community_response_moderation(self): user = UserFactory() self.assertFalse(user.profile.can_skip_community_response_moderation)