def test_approve_reviews_context(running_interval, client): target_user = UserFactory(with_manager=True) review_published = ReviewFactory(target=target_user, interval=running_interval, published=True) review_hidden = ReviewFactory(target=target_user, interval=running_interval, hidden=True) review_pending = ReviewFactory(target=target_user, interval=running_interval, pending=True) review_draft = ReviewFactory(target=target_user, interval=running_interval, draft=True) SelfReviewFactory(user=target_user, interval=running_interval, published=True) client.force_login(user=target_user.manager) response = client.get( reverse('reviews:approve-reviews', kwargs={'interval': running_interval})) assert set( response.context['reviews_require_approval']) == {review_pending} assert set(response.context['reviews_approved']) == { review_published, review_hidden }
def test_cant_view_review_if_no_self_review(running_interval, client): review = ReviewFactory(interval=running_interval, target__with_manager=True) client.force_login(user=review.target.manager) assert not SelfReview.objects.exists() response = client.get(review.get_absolute_url()) assert response.status_code == 403
def _create_reviews(self): self.review1 = ReviewFactory.create( author=self.user, ride=self.ride, subject=self.passenger1, author_type=ReviewAuthorType.DRIVER, rating=3, comment='Always crying and smells like ....') self.review2 = ReviewFactory.create( author=self.user, ride=self.ride, subject=self.passenger2, author_type=ReviewAuthorType.DRIVER, rating=5, comment='Nice passenger!') self.review3 = ReviewFactory.create( author=self.passenger1, ride=self.ride, subject=self.user, author_type=ReviewAuthorType.PASSENGER, rating=2, comment='Always screaming on me!') self.review4 = ReviewFactory.create( author=self.passenger2, ride=self.ride, subject=self.user, author_type=ReviewAuthorType.PASSENGER, rating=5, comment='Nice driver!')
def test_can_review_if_self_review_is_published(running_interval, client): review = ReviewFactory(interval=running_interval, target__with_manager=True) SelfReviewFactory(user=review.target, interval=running_interval, published=True) client.force_login(user=review.target.manager) response = client.get(review.get_absolute_url()) assert response.status_code == 200
def test_user_detail_inactive_peers(running_interval, client): user = UserFactory(with_manager=True) client.force_login(user=user) active_review = ReviewFactory(interval=running_interval, target=user, reviewer__is_active=True) inactive_review = ReviewFactory(interval=running_interval, target=user, reviewer__is_active=False) response = client.get(user.manager.get_absolute_url()) assert list(response.context['current_peers']) == [active_review.reviewer]
def test_approve_review_by_manager_success(running_interval, client): self_review = SelfReviewFactory(user__with_manager=True, interval=running_interval, published=True) review = ReviewFactory(target=self_review.user, interval=running_interval, pending=True) client.force_login(user=review.target.manager) client.post(review.get_absolute_url(), {'action': 'hidden'}) review.refresh_from_db() assert review.status == review.STATUS.hidden
def test_cant_approve_own_review(running_interval, client): self_review = SelfReviewFactory(user__with_manager=True, interval=running_interval, published=True) review = ReviewFactory(target=self_review.user, interval=running_interval, pending=True) client.force_login(user=review.reviewer) response = client.post(review.get_absolute_url(), {'action': 'hidden'}) assert response.context['approve_form'].errors['__all__'].as_data( )[0].code == 'not_manager' review.refresh_from_db() assert review.status == review.STATUS.pending
def test_user_detail_subordinate_stats_visible_to_superuser( running_interval, admin_client): user = UserFactory(with_manager=True) self_review = SelfReviewFactory(interval=running_interval, user=user, published=True) user_to_manager_review = ReviewFactory(interval=running_interval, target=user.manager, reviewer=user, draft=True) manager_to_user_review = ReviewFactory(interval=running_interval, target=user, reviewer=user.manager, draft=True) finished_to_user_review = ReviewFactory(interval=running_interval, target=user, hidden=True) rejected_to_user_review = ReviewFactory(interval=running_interval, target=user, rejected=True) pending_subordinate_review = ReviewFactory(interval=running_interval, reviewer=user, pending=True) requested_subordinate_review = ReviewFactory(interval=running_interval, reviewer=user, requested=True) hidden_subordinate_review = ReviewFactory(interval=running_interval, reviewer=user, hidden=True) published_subordinate_review = ReviewFactory(interval=running_interval, reviewer=user, published=True) response = admin_client.get(user.manager.get_absolute_url()) assert list(response.context['subordinates']) == [user] assert response.context['subordinates'][0].self_review == self_review assert list(response.context['subordinates'][0].peers_approved) == [ finished_to_user_review.reviewer ] assert list( response.context['subordinates'][0].peers_require_approval) == [ rejected_to_user_review.reviewer ] assert list(response.context['subordinates'][0].peers_draft) == [ manager_to_user_review.reviewer ] assert set( response.context['subordinates'][0].current_written_reviews) == { pending_subordinate_review, hidden_subordinate_review, published_subordinate_review } assert set(response.context['subordinates'][0].current_reviews) == { user_to_manager_review, pending_subordinate_review, requested_subordinate_review, hidden_subordinate_review, published_subordinate_review }
def test_review_previous_review_visibility(running_interval, client): ancient_interval = IntervalFactory(name='2018Q3') old_interval = IntervalFactory(name='2018Q4') previous_interval = IntervalFactory(name='2019Q1') review = ReviewFactory(interval=running_interval, target__with_manager=True, draft=True) SelfReviewFactory(user=review.target, interval=running_interval, published=True) client.force_login(user=review.reviewer) response = client.get(review.get_absolute_url()) assert not response.context['previous_review'] honeypot_not_mine_review = ReviewFactory(interval=previous_interval, target=review.target, published=True) previous_review = ReviewFactory(interval=old_interval, target=review.target, reviewer=review.reviewer, published=True) ancient_review = ReviewFactory(interval=ancient_interval, target=review.target, reviewer=review.reviewer, published=True) response = client.get(review.get_absolute_url()) assert response.context['previous_review'] == previous_review
def test_remove_peers_success(running_interval, client): user = UserFactory(with_manager=True) client.force_login(user=user) ReviewFactory.create_batch(4, target=user, requested=True, interval=running_interval) url = reverse('users:choose-peers', kwargs={ 'interval': running_interval, 'email': user.email }) client.get(url) assert Review.objects.filter(target=user, interval=running_interval).count() == 4 client.post(url, {'peers': [user.manager.id]}) assert Review.objects.filter(target=user, interval=running_interval).count() == 1
def test_review_written(running_interval, mailoutbox, status, subject, recipient): selfreview = SelfReviewFactory( user__with_manager=True, user__with_manager__email='*****@*****.**', interval=running_interval) review = ReviewFactory(reviewer__email='*****@*****.**', target=selfreview.user, requested=True, interval=running_interval) assert len(mailoutbox) == 0 review.status = status review.save() assert len(mailoutbox) == 1 mail = mailoutbox[0] assert subject in mail.subject assert mail.to[0] == recipient
def test_manager_review_is_first_one(running_interval, client): user = UserFactory(with_manager=True) client.force_login(user=user.manager) review_by_manager = ReviewFactory(interval=running_interval, target=user, reviewer=user.manager, published=True) review_by_peer = ReviewFactory(interval=running_interval, target=user, reviewer=UserFactory(), published=True) response = client.get( reverse('users:summary', kwargs={ 'interval': running_interval, 'email': user.email })) assert list( response.context['reviews']) == [review_by_manager, review_by_peer]
def test_manager_can_see_subordinate_summary(running_interval, client): user = UserFactory(with_manager=True) client.force_login(user=user.manager) review = ReviewFactory(interval=running_interval, target=user, reviewer=UserFactory(), published=True) other_review = ReviewFactory(interval=running_interval, target=UserFactory(), reviewer=user.manager, published=True) response = client.get( reverse('users:summary', kwargs={ 'interval': running_interval, 'email': user.email })) assert response.status_code == 200 assert list(response.context['reviews']) == [review]
def test_shown_only_reviews_with_published_selfreview(running_interval, client): reviewer = UserFactory() review_with_approved_selfreview = ReviewFactory(interval=running_interval, reviewer=reviewer) review_with_draft_selfreview = ReviewFactory(interval=running_interval, reviewer=reviewer) # not shown published_review = ReviewFactory(interval=running_interval, reviewer=reviewer, published=True) hidden_review = ReviewFactory(interval=running_interval, reviewer=reviewer, hidden=True) SelfReviewFactory(user=published_review.target, interval=running_interval, published=True) SelfReviewFactory(user=hidden_review.target, interval=running_interval, published=True) SelfReviewFactory(user=review_with_approved_selfreview.target, interval=running_interval, published=True) SelfReviewFactory(user=review_with_draft_selfreview.target, interval=running_interval, draft=True) client.force_login(user=reviewer) response = client.get( reverse('reviews:add-reviews', kwargs={'interval': running_interval})) assert response.status_code == 200 assert list(response.context['current_reviews']) == [ review_with_approved_selfreview ] response = client.get(reviewer.get_absolute_url(interval=running_interval)) assert response.status_code == 200 assert list(response.context['draft_reviews']) == [ review_with_approved_selfreview ]
def test_cant_remove_manager_as_peer(running_interval, client): user = UserFactory(with_manager=True) client.force_login(user=user) manager_review = ReviewFactory(target=user, reviewer=user.manager, requested=True, interval=running_interval) ReviewFactory(target=user, requested=True, interval=running_interval) other_review = ReviewFactory(target=user, requested=True, interval=running_interval) assert Review.objects.filter(target=user, interval=running_interval).count() == 3 url = reverse('users:choose-peers', kwargs={ 'interval': running_interval, 'email': user.email }) client.post(url, {'peers': [other_review.reviewer.id]}) assert set(Review.objects.filter( target=user, interval=running_interval)) == {manager_review, other_review}
def test_review_detail_visibility(running_interval, client, status, visitor_slug, can_see): review = ReviewFactory(interval=running_interval, target__with_manager=True, status=status) SelfReviewFactory(user=review.target, interval=running_interval, published=True) users = { 'target': review.target, 'manager': review.target.manager, 'reviewer': review.reviewer, 'other_user': UserFactory(), 'superuser': UserFactory(is_superuser=True) } client.force_login(user=users[visitor_slug]) response = client.get(review.get_absolute_url()) if can_see: assert response.status_code == 200 assert response.context['object'] == review else: assert response.status_code == 403
def test_submit_review(running_interval, client, action, visitor_slug, expected_status): user = UserFactory(with_manager=True) users = { 'manager': user.manager, 'other_user': UserFactory(), } review = ReviewFactory(interval=running_interval, target=user, reviewer=users[visitor_slug], draft=True) SelfReviewFactory(user=user, interval=running_interval, published=True) client.force_login(user=users[visitor_slug]) response = client.post(review.get_absolute_url(), { 'score': 1, 'text': 'some text', 'interval': running_interval.id, 'action': action }, follow=True) assert response.status_code == 200 review.refresh_from_db() assert review.status == expected_status
def test_reviewer_cant_see_other_guy_summary(running_interval, client): user = UserFactory(with_manager=True) other = UserFactory() ReviewFactory(interval=running_interval, target=user, reviewer=other, published=True) client.force_login(user=other) response = client.get( reverse('users:summary', kwargs={ 'interval': running_interval, 'email': user.email })) assert response.status_code == 403
def test_user_detail_reviews_context(running_interval, client): user = UserFactory(with_manager=True) draft = ReviewFactory(interval=running_interval, reviewer=user, draft=True) pending = ReviewFactory(interval=running_interval, reviewer=user, pending=True) approved = ReviewFactory(interval=running_interval, reviewer=user, hidden=True) rejected = ReviewFactory(interval=running_interval, reviewer=user, rejected=True) # make sure everyone has selfreview [ SelfReviewFactory(interval=running_interval, user=u, published=True) for u in User.objects.all() ] client.force_login(user=user) response = client.get(user.get_absolute_url()) assert list(response.context['draft_reviews']) == [draft] assert list(response.context['pending_reviews']) == [pending] assert list(response.context['approved_reviews']) == [approved] assert list(response.context['rejected_reviews']) == [rejected]