def test_create_http_error(self, template, template_data, template_invoke, tempo_request):
        write_yaml(template, template_data)

        request = tempo_request.post('/worklogs', status_code=500)

        result = template_invoke()

        assert "Could not create ('foo', 'INT-8'," in result.output
        assert 'Traceback' in result.output
        assert result.exit_code == 1
        assert request.called_once
Exemple #2
0
def config(tmpdir):
    config = tmpdir.join('config.yml')

    write_yaml(
        config,
        {
            'token': 'foo',
        },
    )

    return config
    def test_create_author_override(self, template, template_data, template_invoke, tempo_request):
        template_data['issues'][0]['author_account_id'] = 'bar'

        write_yaml(template, template_data)

        request = tempo_request.post('/worklogs')

        result = template_invoke()

        assert result.exit_code == 0
        assert request.called_once
        assert request.last_request.json()['authorAccountId'] == template_data['issues'][0]['author_account_id']
    def test_create_future_date(self, template, template_data, template_invoke, tempo_request):
        template_data['issues'][0]['start_time'] = 'Monday at 11am'

        write_yaml(template, template_data)

        request = tempo_request.post('/worklogs')

        result = template_invoke()

        assert result.exit_code == 0
        assert request.called_once
        assert request.last_request.json()['startDate'] == '2018-08-06'
        assert request.last_request.json()['startTime'] == '11:00:00'
    def test_create_multiple(self, template, template_data, template_invoke, tempo_request):
        template_data['issues'].append({
            'issue': 'INT-10',
            'time_spent': '30m',
            'start_time': '09:30:00',
        })

        write_yaml(template, template_data)

        request = tempo_request.post('/worklogs')

        result = template_invoke()

        assert result.exit_code == 0
        assert request.call_count == 2
    def test_create_token_from_env(self, template, template_data, template_invoke, tempo_request):
        token = 'fromenv'  # noqa: S105

        write_yaml(template, template_data)

        request = tempo_request.post('/worklogs')

        result = template_invoke(
            env={
                '{}_TOKEN'.format(ENVVAR_PREFIX): token,
            },
        )

        assert result.exit_code == 0
        assert request.called_once
        assert request.last_request.headers['Authorization'] == 'Bearer {}'.format(token)
    def test_create_single(self, template, template_data, template_invoke, tempo_request):
        write_yaml(template, template_data)

        request = tempo_request.post('/worklogs')

        result = template_invoke()

        assert result.exit_code == 0
        assert request.called_once
        assert request.last_request.json() == {
            'authorAccountId': 'foo',
            'issueKey': self.data['issues'][0]['issue'],
            'timeSpentSeconds': 1800,
            'startDate': '2018-08-05',
            'startTime': self.data['issues'][0]['start_time'],
            'description': 'Working on issue {}'.format(self.data['issues'][0]['issue']),
        }