Esempio n. 1
0
def test_fetch_avatar_does_not_overwrite_in_aws(mock_save, db, settings):
    responses.add(responses.GET,
                  re.compile(r'http://1x1px\.me/.+'),
                  body=open('tests/fixtures/1x1.png', 'rb').read())
    mock_save.side_effect = lambda name, *args, **kwargs: name  # identity save

    user1, user2 = UserFactory(), UserFactory()
    account1 = SocialAccount(
        provider='google',
        user=user1,
        uid='1',
        extra_data={'picture': 'http://1x1px.me/yszgHjRfq24/photo.jpg'})
    account2 = SocialAccount(
        provider='google',
        user=user1,
        uid='1',
        extra_data={'picture': 'http://1x1px.me/sLbe8rOXpaQ/photo.jpg'})

    fetch_avatar(request=None, user=user1, account=account1)
    fetch_avatar(request=None, user=user2, account=account2)

    user1.refresh_from_db()
    user2.refresh_from_db()
    assert user1.avatar
    assert user1.avatar != user2.avatar
Esempio n. 2
0
def test_user_disabled_visible_in_admin(db, client):
    disabled_user = UserFactory(is_active=False)
    client.force_login(user=UserFactory(is_superuser=True, is_staff=True))
    response = client.get(
        reverse('admin:users_user_change', args=[disabled_user.id]))
    assert response.status_code == 200
    assert response.context['original'] == disabled_user
Esempio n. 3
0
def test_manager_can_see_subordinate_summary_url(visitor_slug, can_see,
                                                 running_interval, client):
    user = UserFactory(with_manager=True)
    users = {
        'user': user,
        'manager': user.manager,
        'other_user': UserFactory(),
        'superuser': UserFactory(is_superuser=True)
    }
    client.force_login(user=users[visitor_slug])
    response = client.get(user.get_absolute_url())
    assert bool(response.context.get('summary_url')) == can_see
Esempio n. 4
0
def test_user_can_see_hers_goal(running_interval, client, login_as_user,
                                status_code):
    users = {
        'user': UserFactory(with_manager=True),
        'other_user': UserFactory(),
        'superuser': UserFactory(is_superuser=True),
    }
    current_goal = GoalFactory(target=users['user'],
                               text='456',
                               interval=running_interval)
    client.force_login(user=users[login_as_user])
    response = client.get(current_goal.get_absolute_url())
    assert response.status_code == status_code
Esempio n. 5
0
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
Esempio n. 6
0
def test_user_detail_subordinate_stats_not_visible_to_peers(
        running_interval, client):
    user = UserFactory(with_manager=True)
    colleague = UserFactory()
    client.force_login(user=colleague)
    response = client.get(user.manager.get_absolute_url())
    assert list(response.context['subordinates']) == [user]
    assert not hasattr(response.context['subordinates'][0], 'self_review')
    assert not hasattr(response.context['subordinates'][0], 'peers_approved')
    assert not hasattr(response.context['subordinates'][0],
                       'peers_require_approval')
    assert not hasattr(response.context['subordinates'][0], 'peers_draft')
    assert not hasattr(response.context['subordinates'][0],
                       'current_written_reviews')
    assert not hasattr(response.context['subordinates'][0], 'current_reviews')
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
    }
Esempio n. 8
0
def test_add_peers_success(running_interval, client):
    user = UserFactory(with_manager=True)
    client.force_login(user=user)
    peers = UserFactory.create_batch(4)
    url = reverse('users:choose-peers',
                  kwargs={
                      'interval': running_interval,
                      'email': user.email
                  })
    client.get(url)
    assert Review.requested.count() == 1  # manager review auto-created
    response = client.post(
        url, {'peers': [user.manager.id, peers[0].id, peers[1].id]})
    assert {r.reviewer
            for r in Review.requested.all()
            } == {user.manager, peers[0], peers[1]}
Esempio n. 9
0
def test_only_manager_can_update_goal(running_interval, client, login_as_user):
    users = {
        'user': UserFactory(with_manager=True),
        'other_user': UserFactory(),
        'superuser': UserFactory(is_superuser=True),
    }
    current_goal = GoalFactory(target=users['user'],
                               text='456',
                               interval=running_interval)
    client.force_login(user=users[login_as_user])
    response = client.post(current_goal.get_absolute_url(), {
        'text': '123',
        'interval': running_interval.id
    },
                           follow=True)
    assert response.status_code == 403
Esempio n. 10
0
def test_choose_peers_creates_defaults(running_interval, client):
    manager = UserFactory()
    user = UserFactory(manager=manager)
    subordinates = UserFactory.create_batch(2, manager=user)
    UserFactory(username='******')
    UserFactory(is_active=False, manager=user)
    client.force_login(user=user)
    response = client.get(
        reverse('users:choose-peers',
                kwargs={
                    'interval': running_interval,
                    'email': user.email
                }))
    assert response.status_code == 200
    assert {r.reviewer
            for r in Review.objects.all()
            } == {manager, subordinates[0], subordinates[1]}
Esempio n. 11
0
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
    }
Esempio n. 12
0
def test_boss_can_choose_peers(running_interval, client):
    boss = UserFactory(manager=None)
    client.force_login(user=boss)
    url = reverse('users:choose-peers',
                  kwargs={
                      'interval': running_interval,
                      'email': boss.email
                  })
    response = client.get(url)
    assert response.status_code == 200
Esempio n. 13
0
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]
Esempio n. 14
0
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]
Esempio n. 15
0
def test_user_detail_goal_is_visible(running_interval, next_interval, client,
                                     login_as_user, is_visible):
    users = {
        'user': UserFactory(with_manager=True),
        'other_user': UserFactory(),
        'superuser': UserFactory(is_superuser=True),
    }
    users['manager'] = users['user'].manager
    current_goal = GoalFactory(target=users['user'], interval=running_interval)
    next_goal = GoalFactory(target=users['user'], interval=next_interval)

    client.force_login(user=users[login_as_user])
    response = client.get(users['user'].get_absolute_url())
    if is_visible:
        assert response.context['current_goal'] == current_goal
        assert response.context['next_goal'] == next_goal
    else:
        assert not response.context.get('current_goal')
        assert not response.context.get('next_goal')
Esempio n. 16
0
def test_user_cant_see_own_summary(running_interval, client):
    user = UserFactory(with_manager=True)
    client.force_login(user=user)
    response = client.get(
        reverse('users:summary',
                kwargs={
                    'interval': running_interval,
                    'email': user.email
                }))
    assert response.status_code == 403
Esempio n. 17
0
def test_google_login_existing(running_interval, social_login, client):
    settings.SOCIALACCOUNT_DOMAINS_ALLOWED = []
    UserFactory(email='*****@*****.**')
    assert 'example.com' not in settings.SOCIALACCOUNT_DOMAINS_ALLOWED
    response = social_login(email='*****@*****.**')
    assert response.status_code == 200
    assert response.redirect_chain[-1] == ('/2018Q2/users/[email protected]/', 302)
    user = User.objects.get()
    assert user.email == '*****@*****.**'
    assert user.is_active
Esempio n. 18
0
def test_tree(db, capsys):
    boss = UserFactory(last_name='Boss', job__name='CEO')
    UserFactory(last_name='Dilbert', job__name='программист', manager=boss)
    boss2 = UserFactory(first_name='Jen',
                        last_name='Barber',
                        job__name='манагер')
    UserFactory(first_name='Moris',
                last_name='Moss',
                job__name='эникейщик',
                manager=boss2,
                is_reviewable=False)
    call_command('tree')
    captured = capsys.readouterr()
    assert captured.out.splitlines() == [
        'Barber Jen (манагер)',
        ' +-- [X] Moss Moris (эникейщик)',
        'Boss (CEO)',
        ' +-- Dilbert (программист)',
    ]
Esempio n. 19
0
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
    ]
Esempio n. 20
0
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]
Esempio n. 21
0
def test_send_welcome(running_interval, mailoutbox):
    UserFactory(is_active=False)
    UserFactory(is_reviewable=False)
    UserFactory(email='*****@*****.**', department__name='ACME')
    UserFactory(email='*****@*****.**', department__name='DC')
    call_command('send_email', template='welcome', suitable=True)
    assert len(mailoutbox) == 2

    mail = mailoutbox[0]
    assert 'Наступает супер-время' in mail.subject
    assert {m.to[0]
            for m in mailoutbox
            } == {'*****@*****.**', '*****@*****.**'}

    mailoutbox.clear()
    call_command('send_email',
                 template='welcome',
                 suitable=True,
                 department='ACME')
    assert len(mailoutbox) == 1
    assert {m.to[0] for m in mailoutbox} == {'*****@*****.**'}
Esempio n. 22
0
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
Esempio n. 23
0
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
Esempio n. 24
0
def test_only_manager_can_create_goals(running_interval, client,
                                       login_as_user):
    users = {
        'user': UserFactory(with_manager=True),
        'other_user': UserFactory(),
    }
    url = reverse('goals:create',
                  kwargs={
                      'interval': running_interval,
                      'email': users['user'].email
                  })
    client.force_login(user=users[login_as_user])
    response = client.get(url)
    assert response.status_code == 403
    assert not response.context

    response = client.post(url, {
        'text': '123',
        'interval': running_interval.id
    },
                           follow=True)
    assert response.status_code == 403
    assert Goal.objects.count() == 0
Esempio n. 25
0
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]
Esempio n. 26
0
def test_manager_can_get_goal_createform(running_interval, client):
    user = UserFactory(with_manager=True)
    old_goal = GoalFactory(target=user,
                           interval=IntervalFactory(finished=True,
                                                    name='2017Q4'))

    url = reverse('goals:create',
                  kwargs={
                      'interval': running_interval,
                      'email': user.email
                  })
    client.force_login(user=user.manager)
    response = client.get(url)
    assert response.context['goal_form']
    assert response.context['previous_goal'] == old_goal
Esempio n. 27
0
def test_manager_can_create_goal(running_interval, client):
    user = UserFactory(with_manager=True, email='*****@*****.**')
    client.force_login(user=user.manager)
    url = reverse('goals:create',
                  kwargs={
                      'interval': running_interval,
                      'email': user.email
                  })
    response = client.post(url, {
        'text': '123',
        'interval': running_interval.id
    },
                           follow=True)
    goal = Goal.objects.get(target=user)
    assert goal.text == '123'
    assert goal.interval == running_interval
    assert '/2018Q2/users/[email protected]/' in response.redirect_chain[-1][0]
Esempio n. 28
0
def test_manager_can_view_and_update_goal(running_interval, client):
    user = UserFactory(with_manager=True, email='*****@*****.**')
    current_goal = GoalFactory(target=user,
                               text='456',
                               interval=running_interval)
    client.force_login(user=user.manager)
    response = client.get(current_goal.get_absolute_url())
    assert response.context['goal_form']['text'].value() == '456'

    response = client.post(current_goal.get_absolute_url(), {
        'text': '123',
        'interval': running_interval.id
    },
                           follow=True)
    goal = Goal.objects.get(target=user)
    assert goal.text == '123'
    assert goal.interval == running_interval
    assert '/2018Q2/users/[email protected]/' in response.redirect_chain[-1][0]
Esempio n. 29
0
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
Esempio n. 30
0
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}