Exemplo n.º 1
0
    def test_post_create_new_retro(self, mock_service_validation,
                                   mock_service_view, mock_token):
        request_body = {'retroName': 'Sprint 26', 'adminName': 'halprin'}
        a_request = request.create_mock_request(request_body)
        new_retro_id = 'awesome_retro_id'
        new_admin_id = 'sweet_user_id'
        mock_new_retro = retro.create_mock_retro(
            id=new_retro_id,
            name=request_body['retroName'],
            participants=[
                retro.create_mock_participant(token=new_admin_id,
                                              name=request_body['adminName'],
                                              admin=True)
            ])
        mock_service_view.create_retro.return_value = mock_new_retro

        object_under_test = RetroView()
        response = object_under_test.post(a_request)

        assert response.status_code == 201
        assert response.headers[
            validators.content_type] == content_type_application_json
        assert json.loads(response.body) == {
            'retroId': new_retro_id,
            'token': new_admin_id
        }
Exemplo n.º 2
0
def test__sanitize_issue_list_doesnt_order_issues_when_not_results():
    your_token = 'a-token'
    the_issue_section = 'a-section'
    another_issue_section = 'another-section'

    first_issue = retro.create_mock_issue(id='1',
                                          section=the_issue_section,
                                          creator_token=your_token,
                                          votes=set())
    second_issue = retro.create_mock_issue(
        id='3',
        section=the_issue_section,
        creator_token='a-different-token',
        votes={your_token, 'another-different-token', 'yet-another-token'})
    third_issue = retro.create_mock_issue(id='2',
                                          section=another_issue_section,
                                          creator_token='a-different-token',
                                          votes={your_token})

    a_retro = retro.create_mock_retro(
        current_step=RetroStep.VOTING,
        issues=[first_issue, second_issue, third_issue])

    sanitized_issues = Service._sanitize_issue_list(a_retro, your_token)

    assert sanitized_issues[0]['id'] == first_issue.id
    assert sanitized_issues[1]['id'] == second_issue.id
    assert sanitized_issues[2]['id'] == third_issue.id
Exemplo n.º 3
0
def test__sanitize_issue_list_shows_my_issues_and_other_sections_during_adding_issues(
):
    user_token = 'a-token'
    your_issue = retro.create_mock_issue(section='your_section',
                                         creator_token=user_token,
                                         votes={user_token})
    another_issue = retro.create_mock_issue(section='special_section',
                                            creator_token='a-different-token')
    a_retro = retro.create_mock_retro(current_step=RetroStep.ADDING_ISSUES,
                                      issues=[your_issue, another_issue])

    sanitized_issues = Service._sanitize_issue_list(a_retro, user_token)

    assert len(sanitized_issues) == 2
    was_your_issue = sanitized_issues[0]
    assert was_your_issue['id'] == your_issue.id
    assert was_your_issue['title'] == your_issue.title
    assert was_your_issue['section'] == your_issue.section
    with pytest.raises(KeyError):
        was_your_issue['votes']
    was_another_issue = sanitized_issues[1]
    assert was_another_issue['section'] == another_issue.section
    with pytest.raises(KeyError):
        was_another_issue['title']
    with pytest.raises(KeyError):
        was_another_issue['id']
    with pytest.raises(KeyError):
        was_another_issue['votes']
Exemplo n.º 4
0
def test__sanitize_issue_list_shows_your_votes_during_voting():
    your_token = 'a-token'
    your_issue = retro.create_mock_issue(section='your_section',
                                         creator_token=your_token,
                                         votes={'another-different-token'})
    another_issue = retro.create_mock_issue(
        section='special_section',
        creator_token='a-different-token',
        votes={your_token, 'another-different-token'})
    a_retro = retro.create_mock_retro(current_step=RetroStep.VOTING,
                                      issues=[your_issue, another_issue])

    sanitized_issues = Service._sanitize_issue_list(a_retro, your_token)

    assert len(sanitized_issues) == 2
    was_your_issue = sanitized_issues[0]
    assert was_your_issue['id'] == your_issue.id
    assert was_your_issue['title'] == your_issue.title
    assert was_your_issue['section'] == your_issue.section
    assert was_your_issue['votes'] == 0
    was_another_issue = sanitized_issues[1]
    assert was_another_issue['id'] == another_issue.id
    assert was_another_issue['title'] == another_issue.title
    assert was_another_issue['section'] == another_issue.section
    assert was_another_issue['votes'] == 1
Exemplo n.º 5
0
def test__find_issue_negative():
    issue_one = retro.create_mock_issue(id='an_issue_id')
    issue_two = retro.create_mock_issue(id='another_issue_id')
    mock_retro = retro.create_mock_retro(issues=[issue_one, issue_two])

    issue = validation._find_issue('non-existing_issue_id', mock_retro)

    assert issue is None
Exemplo n.º 6
0
def test_move_retro_unknown_direction():
    step = RetroStep.VOTING
    a_retro = retro.create_mock_retro(current_step=step.value)

    with pytest.raises(ValueError):
        Service.move_retro(a_retro, 'lollerskates')

    assert a_retro.current_step == step.value
Exemplo n.º 7
0
def test__find_issue_positive():
    existing_issue_id = 'an_issue_id'
    issue_one = retro.create_mock_issue(id='some_issue_id')
    expected_issue = retro.create_mock_issue(id=existing_issue_id)
    mock_retro = retro.create_mock_retro(issues=[issue_one, expected_issue])

    actual_issue = validation._find_issue(existing_issue_id, mock_retro)

    assert expected_issue == actual_issue
Exemplo n.º 8
0
def test_user_is_valid_negative(mock_token):
    mock_token.token_is_valid.return_value = False

    object_under_test = validation.user_is_valid(original_function)
    response = object_under_test(None,
                                 request.create_mock_request(),
                                 retro=retro.create_mock_retro())

    validators.assert_user_not_valid(response)
Exemplo n.º 9
0
def test_get_retro(mock_retrospective_class):
    retro_id = 'an_awesome_retro_id'
    mock_retrospective_class.get.side_effect = lambda passed_in_retro_id: retro.create_mock_retro(
        id=passed_in_retro_id)

    returned_retro = Service.get_retro(retro_id)

    mock_retrospective_class.get.assert_called_with(retro_id)
    assert returned_retro.id == retro_id
Exemplo n.º 10
0
def test_token_is_valid_false():
    participant1 = retro.create_mock_participant(token='junk')
    participant2 = retro.create_mock_participant(token='whatever')
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2])

    result = token.token_is_valid('something_not_above', a_retro)

    assert result is False
Exemplo n.º 11
0
def test_retro_on_step_list_positive():
    retro_step = RetroStep.VOTING
    mock_retro = retro.create_mock_retro(current_step=retro_step.value)
    object_under_test = validation.retro_on_step(
        [RetroStep.RESULTS, retro_step], 'Some test {}')(original_function)

    passed_args = object_under_test(retro=mock_retro)

    assert mock_retro == passed_args['kwargs']['retro']
Exemplo n.º 12
0
def test_get_participant_none():
    participant1 = retro.create_mock_participant(token='junk')
    participant2 = retro.create_mock_participant(token='whatever')
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2])

    found_participant = token.get_participant('something_not_above', a_retro)

    assert found_participant is None
Exemplo n.º 13
0
 def test_put_not_voting_step(self, mock_service_function_validation,
                              mock_service_view, mock_token):
     object_under_test = RetroIssueView()
     mock_retro = retro.create_mock_retro(
         current_step=RetroStep.ADDING_ISSUES.value)
     validators.assert_function_returns_retro_not_on_step(
         object_under_test.put, mock_service_function_validation,
         mock_token, mock_retro,
         views.no_vote_issue_retro_wrong_step.format(
             mock_retro.current_step))
Exemplo n.º 14
0
def test_move_retro_next(mock_send_retro_update):
    step = RetroStep.ADDING_ISSUES
    a_retro = retro.create_mock_retro(current_step=step.value)

    new_step = Service.move_retro(a_retro, 'next')

    assert new_step == step.next().value
    assert a_retro.current_step == step.next().value
    a_retro.save.assert_called_with()
    mock_send_retro_update.assert_called_once()
Exemplo n.º 15
0
def test_user_is_valid_positive(mock_token):
    mock_token.token_is_valid.return_value = True
    mock_retro = retro.create_mock_retro()
    mock_request = request.create_mock_request()

    object_under_test = validation.user_is_valid(original_function)
    passed_args = object_under_test(None, mock_request, retro=mock_retro)

    assert mock_request == passed_args['args'][1]
    assert mock_retro == passed_args['kwargs']['retro']
Exemplo n.º 16
0
def test_unvote_for_issue_with_no_votes():
    issue_id_str = 'issue_id'
    user_token_str = 'voter_token'
    a_issue = retro.create_mock_issue(id=issue_id_str)
    a_retro = retro.create_mock_retro(issues=[a_issue])

    Service.unvote_for_issue(a_issue, user_token_str, a_retro)

    assert a_issue.votes is None or 0 == len(a_issue.votes)
    assert a_issue.votes is None or user_token_str not in a_issue.votes
Exemplo n.º 17
0
def test__find_participant_none():
    participant1 = retro.create_mock_participant(name='lame_name')
    participant2 = retro.create_mock_participant(name='whatever_name')
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2])

    found_participant = token._find_participant(
        lambda participant: participant.name == 'something_not_above', a_retro)

    assert found_participant is None
Exemplo n.º 18
0
def test_get_participant_found():
    test_token = 'asdf-jkl'
    participant1 = retro.create_mock_participant(token='junk')
    participant2 = retro.create_mock_participant(token=test_token)
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2])

    found_participant = token.get_participant(test_token, a_retro)

    assert found_participant is participant2
Exemplo n.º 19
0
def test_token_is_admin_false():
    test_token = 'asdf-jkl'
    participant1 = retro.create_mock_participant(token='junk', admin=False)
    participant2 = retro.create_mock_participant(token=test_token, admin=False)
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2])

    result = token.token_is_admin(test_token, a_retro)

    assert result is False
Exemplo n.º 20
0
def test_token_is_valid_true():
    test_token = 'asdf-jkl'
    participant1 = retro.create_mock_participant(token='junk')
    participant2 = retro.create_mock_participant(token=test_token)
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2])

    result = token.token_is_valid(test_token, a_retro)

    assert result is True
Exemplo n.º 21
0
def test_move_retro_previous(mock_send_retro_update):
    step = RetroStep.RESULTS
    a_retro = retro.create_mock_retro(current_step=step.value)

    new_step = Service.move_retro(a_retro, 'previous')

    assert new_step == step.previous().value
    assert a_retro.current_step == step.previous().value
    a_retro.save.assert_called_with()
    mock_send_retro_update.assert_called_once()
Exemplo n.º 22
0
def test_delete_issue(mock_send_retro_update):
    mock_issue = retro.create_mock_issue(id='some_issue')
    another_mock_issue = retro.create_mock_issue(id='another_issue')
    mock_retro = retro.create_mock_retro(
        issues=[another_mock_issue, mock_issue])

    Service.delete_issue(mock_issue, mock_retro)

    assert mock_issue not in mock_retro.issues
    mock_send_retro_update.assert_called_once()
Exemplo n.º 23
0
def test_unvote_for_issue(mock_send_retro_update):
    issue_id_str = 'issue_id'
    user_token_str = 'voter_token'
    a_issue = retro.create_mock_issue(id=issue_id_str, votes={user_token_str})
    a_retro = retro.create_mock_retro(issues=[a_issue])

    Service.unvote_for_issue(a_issue, user_token_str, a_retro)

    assert a_issue.votes is None or 0 == len(a_issue.votes)
    assert a_issue.votes is None or user_token_str not in a_issue.votes
    mock_send_retro_update.assert_called_once()
Exemplo n.º 24
0
def test__find_participant_found():
    test_name = 'DogCow'
    participant1 = retro.create_mock_participant(name='lame_name')
    participant2 = retro.create_mock_participant(name=test_name)
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2])

    found_participant = token._find_participant(
        lambda participant: participant.name == test_name, a_retro)

    assert found_participant is participant2
Exemplo n.º 25
0
def test_vote_for_issue(mock_send_retro_update):
    issue_id_str = 'issue_id'
    user_token_str = 'voter_token'
    a_issue = retro.create_mock_issue(id=issue_id_str)
    a_retro = retro.create_mock_retro(issues=[a_issue])

    Service.vote_for_issue(a_issue, user_token_str, a_retro)

    assert 1 == len(a_issue.votes)
    assert user_token_str in a_issue.votes
    mock_send_retro_update.assert_called_once()
Exemplo n.º 26
0
def test__reset_ready_statuses():
    participant1 = retro.create_mock_participant(ready=True)
    participant2 = retro.create_mock_participant(ready=False)
    participant3 = retro.create_mock_participant(ready=True)
    a_retro = retro.create_mock_retro(
        participants=[participant1, participant2, participant3])

    Service._reset_ready_statuses(a_retro)

    for participant in a_retro.participants:
        assert participant.ready is False
Exemplo n.º 27
0
def test_retro_on_step_negative():
    error_message = 'Some test {}'
    retro_step = RetroStep.ADDING_ISSUES.value
    object_under_test = validation.retro_on_step(
        RetroStep.VOTING, error_message)(original_function)

    response = object_under_test(retro=retro.create_mock_retro(
        current_step=retro_step))

    validators.assert_retro_not_on_step(response,
                                        error_message.format(retro_step))
Exemplo n.º 28
0
def test_issue_exists_positive():
    issue_id = 'some_issue_id'
    mock_request = request.create_mock_request(issue_id=issue_id)
    mock_issue = retro.create_mock_issue(id=issue_id)
    mock_retro = retro.create_mock_retro(issues=[mock_issue])
    object_under_test = validation.issue_exists(original_function)

    passed_args = object_under_test(mock_request, retro=mock_retro)

    assert mock_retro == passed_args['kwargs']['retro']
    assert mock_issue == passed_args['kwargs']['issue']
Exemplo n.º 29
0
 def test_delete_retro_step_not_valid(self,
                                      mock_service_function_validation,
                                      mock_service_view, mock_token):
     object_under_test = RetroIssueView()
     mock_retro = retro.create_mock_retro(
         current_step=RetroStep.VOTING.value)
     validators.assert_function_returns_retro_not_on_step(
         object_under_test.delete, mock_service_function_validation,
         mock_token, mock_retro,
         views.no_delete_issue_retro_wrong_step.format(
             mock_retro.current_step))
Exemplo n.º 30
0
def test_issue_exists_negative():
    issue_id = 'non-existent_issue_id'
    mock_request = request.create_mock_request(issue_id=issue_id)
    object_under_test = validation.issue_exists(original_function)

    response = object_under_test(
        mock_request,
        retro=retro.create_mock_retro(
            issues=[retro.create_mock_issue(id='some_other_id')]))

    validators.assert_issue_not_found(response, issue_id)