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_selfreview_written(running_interval, mailoutbox, status, subject, recipient): self_review = SelfReviewFactory( user__email='*****@*****.**', user__with_manager=True, user__with_manager__email='*****@*****.**', draft=True) assert len(mailoutbox) == 0 self_review.status = status self_review.save() assert len(mailoutbox) == 1 mail = mailoutbox[0] assert subject in mail.subject assert mail.to[0] == recipient
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_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_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_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_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_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_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_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]