def test_values_from_list_duplicate(self): from openapi_python_client.parser.properties import EnumProperty data = ["abc", "123", "a23", "abc"] with pytest.raises(ValueError): EnumProperty.values_from_list(data)
def test_property_from_data_enum(self, mocker): name = mocker.MagicMock() required = mocker.MagicMock() data = mocker.MagicMock(title=None) EnumProperty = mocker.patch(f"{MODULE_NAME}.EnumProperty") mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=name) from openapi_python_client.parser.properties import property_from_data p = property_from_data(name=name, required=required, data=data) EnumProperty.values_from_list.assert_called_once_with(data.enum) EnumProperty.assert_called_once_with( name=name, required=required, values=EnumProperty.values_from_list(), default=data.default, title=name) assert p == EnumProperty() EnumProperty.reset_mock() data.title = mocker.MagicMock() property_from_data( name=name, required=required, data=data, ) EnumProperty.assert_called_once_with( name=name, required=required, values=EnumProperty.values_from_list(), default=data.default, title=data.title)
def test_values_from_list(self): from openapi_python_client.parser.properties import EnumProperty data = ["abc", "123", "a23", "1bc"] result = EnumProperty.values_from_list(data) assert result == { "ABC": "abc", "VALUE_1": "123", "A23": "a23", "VALUE_3": "1bc", }
def test_values_from_list(self): from openapi_python_client.parser.properties import EnumProperty data = ["abc", "123", "a23", "1bc", 4, -3, "a Thing WIth spaces"] result = EnumProperty.values_from_list(data) assert result == { "ABC": "abc", "VALUE_1": "123", "A23": "a23", "VALUE_3": "1bc", "VALUE_4": 4, "VALUE_NEGATIVE_3": -3, "A_THING_WITH_SPACES": "a Thing WIth spaces", }