def test_get_labels_error_response(routemaster_api: RoutemasterAPI): httpretty.register_uri( httpretty.GET, 'http://localhost:2017/state-machines/none/labels', content_type='application/json', status=502, ) testing_machine = StateMachine('none') with pytest.raises(requests.HTTPError): routemaster_api.get_labels(testing_machine)
def test_get_labels_unknown_state_machine(routemaster_api: RoutemasterAPI): httpretty.register_uri( httpretty.GET, 'http://localhost:2017/state-machines/none/labels', content_type='application/json', status=404, ) testing_machine = StateMachine('none') with pytest.raises(UnknownStateMachine) as e: routemaster_api.get_labels(testing_machine) assert e.value.state_machine == 'none'
def test_get_labels(routemaster_api: RoutemasterAPI): data = { 'labels': [ { 'name': 'first-label' }, { 'name': 'other-label' }, ] } httpretty.register_uri( httpretty.GET, 'http://localhost:2017/state-machines/testing-machine/labels', body=json.dumps(data), content_type='application/json', ) testing_machine = StateMachine('testing-machine') labels = routemaster_api.get_labels(testing_machine) assert labels == [ LabelRef(LabelName('first-label'), testing_machine), LabelRef(LabelName('other-label'), testing_machine), ]