def test_create_label_error_response(routemaster_api: RoutemasterAPI): httpretty.register_uri( httpretty.POST, 'http://localhost:2017/state-machines/testing-machine/labels/demo-label', content_type='application/json', status=502, ) label_ref = LabelRef( LabelName('demo-label'), StateMachine('testing-machine'), ) with pytest.raises(requests.HTTPError): routemaster_api.create_label(label_ref, metadata={})
def test_create_label_unknown_state_machine(routemaster_api: RoutemasterAPI): httpretty.register_uri( httpretty.POST, 'http://localhost:2017/state-machines/none/labels/demo-label', content_type='application/json', status=404, ) testing_machine = StateMachine('none') label_ref = LabelRef(LabelName('demo-label'), testing_machine) with pytest.raises(UnknownStateMachine) as e: routemaster_api.create_label(label_ref, metadata={}) assert e.value.state_machine == 'none'
def test_create_label(routemaster_api: RoutemasterAPI): expected_sent = {'foo': 'sent'} expected_returned = {'foo': 'returned'} httpretty.register_uri( httpretty.POST, 'http://localhost:2017/state-machines/testing-machine/labels/demo-label', body=json.dumps({ 'metadata': expected_returned, 'state': 'first-state', }), content_type='application/json', status=201, ) label_ref = LabelRef( LabelName('demo-label'), StateMachine('testing-machine'), ) returned_label = routemaster_api.create_label( label_ref, metadata=expected_sent, ) assert returned_label == Label( label_ref, expected_returned, State('first-state'), ) last_request = httpretty.last_request() sent_data = json.loads(last_request.body.decode('utf-8')) assert sent_data == {'metadata': expected_sent}
def test_create_label_already_exists(routemaster_api: RoutemasterAPI): httpretty.register_uri( httpretty.POST, 'http://localhost:2017/state-machines/testing-machine/labels/demo-label', content_type='application/json', status=409, ) label_ref = LabelRef( LabelName('demo-label'), StateMachine('testing-machine'), ) with pytest.raises(LabelAlreadyExists) as e: routemaster_api.create_label(label_ref, metadata={}) assert e.value.label == label_ref