def test_raise_if_invalid_nested(simple_chain, error_out_deep): command_conf = { 'type': 'object', 'contentType': 'application/json', 'properties': { 'd0': { 'type': 'object', 'properties': { 'd1': { 'type': 'object', 'properties': { 'd2': { 'type': 'int' } } } } } } } output = {'d0': {'d1': {'d2': 'not_int' if error_out_deep else 100}}} if error_out_deep: with pytest.raises(FieldValueTypeMismatchOmgError): ServiceOutputValidator.raise_if_invalid(command_conf, output, simple_chain) else: ServiceOutputValidator.raise_if_invalid(command_conf, output, simple_chain)
def test_raise_if_invalid_for_null_object(simple_chain): command_conf = { 'type': 'object', 'contentType': 'application/json', 'properties': { 'my_object': { 'type': 'object' } } } output = {'my_object': None} with pytest.raises(MissingFieldOmgError): ServiceOutputValidator.raise_if_invalid(command_conf, output, simple_chain)
def test_raise_if_invalid(actual_value, omg_type, expect_throw, simple_chain): command_conf = { 'type': 'object', 'contentType': 'application/json', 'properties': { 'value': { 'type': omg_type } } } output = {'value': actual_value} if expect_throw: with pytest.raises(FieldValueTypeMismatchOmgError): ServiceOutputValidator.raise_if_invalid(command_conf, output, simple_chain) else: ServiceOutputValidator.raise_if_invalid(command_conf, output, simple_chain)
def test_raise_for_type_mismatch_unsupported_omg(): with pytest.raises(UnsupportedTypeOmgError): ServiceOutputValidator.raise_for_type_mismatch('foo', 'unknown_omg_type', 0, None)
def test_raise_if_invalid_for_objects_with_no_props(simple_chain): command_conf = {'type': 'object', 'contentType': 'application/json'} output = {'any': 'thing', 'is': 'allowed'} ServiceOutputValidator.raise_if_invalid(command_conf, output, simple_chain)