Example #1
0
def test_create_project_handles_400(requests_mock):
    rest_client = RestClient('http://testing-es-url')
    requests_mock.post('http://testing-es-url/api/v1/projects',
                       json={
                           'title': 'not ok',
                           'status': 400
                       },
                       status_code=400)

    with pytest.raises(ServiceError):
        rest_client.project_create({'id': 'schema'}, 'restype', 'myname',
                                   'mynote')
Example #2
0
def test_create_project_default_data(requests_mock):
    rest_client = RestClient('http://testing-es-url')
    requests_mock.post('http://testing-es-url/api/v1/projects',
                       json={'status': 'ok'},
                       status_code=201)
    rest_client.project_create({'id': 'schema'}, 'restype', 'myname')
    posted_data = requests_mock.last_request.json()
    assert all(expected_field in posted_data for expected_field in
               {'schema', 'result_type', 'number_parties', 'name', 'notes'})

    assert 'created by clkhash' in posted_data['notes']
    assert posted_data['number_parties'] == 2
Example #3
0
def test_create_project_handles_503(requests_mock):
    rest_client = RestClient(
        'http://testing-es-url',
        ClientWaitingConfiguration(wait_exponential_max_ms=10,
                                   wait_exponential_multiplier_ms=1,
                                   stop_max_delay_ms=10))
    requests_mock.post('http://testing-es-url/api/v1/projects',
                       text='',
                       status_code=503)

    with pytest.raises(ServiceError):
        rest_client.project_create({'id': 'schema'}, 'restype', 'myname',
                                   'mynote')