Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Operation rename and bug fix #1302

Merged
merged 12 commits into from
Aug 8, 2016
4 changes: 4 additions & 0 deletions src/client/Python/msrest/msrest/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ def serialize_date(attr, **kwargs):
:param Date attr: Object to be serialized.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmazuel - I've made a couple of minor changes to serialization.py, if you could do a quick review :)
They should not be breaking, and I doubt are used by the existing clients so may not need a new release yet.

Effectively it's a change to support default/constant date and datetime values by allowing strings to passed in instead of date or datetime objects. The strings would need to already be in the correct ISO formatting that the request will serialize to. Let me know if you think this is okay.

:rtype: str
"""
if isinstance(attr, str):
attr = isodate.parse_date(attr)
t = "{:04}-{:02}-{:02}".format(attr.year, attr.month, attr.day)
return t

Expand All @@ -613,6 +615,8 @@ def serialize_duration(attr, **kwargs):
:param TimeDelta attr: Object to be serialized.
:rtype: str
"""
if isinstance(attr, str):
attr = isodate.parse_duration(attr)
return isodate.duration_isoformat(attr)

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ def test_azure_special_parameters(self):
client.api_version_default.get_method_global_valid()
client.api_version_default.get_path_global_valid()
client.api_version_default.get_swagger_global_valid()
client.api_version_local.get_method_local_valid(validApiVersion)
client.api_version_local.get_method_local_null(None)
client.api_version_local.get_path_local_valid(validApiVersion)
client.api_version_local.get_swagger_local_valid(validApiVersion)
client.api_version_local.get_method_local_valid()
client.api_version_local.get_method_local_null()
client.api_version_local.get_path_local_valid()
client.api_version_local.get_swagger_local_valid()

client.skip_url_encoding.get_method_path_valid(unencodedPath)
client.skip_url_encoding.get_path_path_valid(unencodedPath)
client.skip_url_encoding.get_swagger_path_valid(unencodedPath)
client.skip_url_encoding.get_swagger_path_valid()
client.skip_url_encoding.get_method_query_valid(unencodedQuery)
client.skip_url_encoding.get_path_query_valid(unencodedQuery)
client.skip_url_encoding.get_swagger_query_valid(unencodedQuery)
client.skip_url_encoding.get_swagger_query_valid()
client.skip_url_encoding.get_method_query_null()
client.skip_url_encoding.get_method_query_null(None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,23 @@ class ApiVersionLocalOperations(object):
:param config: Configuration of service client.
:param serializer: An object model serializer.
:param deserializer: An objec model deserializer.
:ivar api_version: This should appear as a method parameter, use value '2.0'. Constant value: "2.0".
"""

def __init__(self, client, config, serializer, deserializer):

self._client = client
self._serialize = serializer
self._deserialize = deserializer
self.api_version = "2.0"

self.config = config

def get_method_local_valid(
self, api_version="2.0", custom_headers=None, raw=False, **operation_config):
self, custom_headers=None, raw=False, **operation_config):
"""Get method with api-version modeled in the method. pass in
api-version = '2.0' to succeed.

:param api_version: This should appear as a method parameter, use
value '2.0'
:type api_version: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
Expand All @@ -54,7 +53,7 @@ def get_method_local_valid(

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

# Construct headers
header_parameters = {}
Expand Down Expand Up @@ -124,13 +123,10 @@ def get_method_local_null(
return client_raw_response

def get_path_local_valid(
self, api_version="2.0", custom_headers=None, raw=False, **operation_config):
self, custom_headers=None, raw=False, **operation_config):
"""Get method with api-version modeled in the method. pass in
api-version = '2.0' to succeed.

:param api_version: This should appear as a method parameter, use
value '2.0'
:type api_version: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
Expand All @@ -145,7 +141,7 @@ def get_path_local_valid(

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

# Construct headers
header_parameters = {}
Expand All @@ -169,13 +165,10 @@ def get_path_local_valid(
return client_raw_response

def get_swagger_local_valid(
self, api_version="2.0", custom_headers=None, raw=False, **operation_config):
self, custom_headers=None, raw=False, **operation_config):
"""Get method with api-version modeled in the method. pass in
api-version = '2.0' to succeed.

:param api_version: The api version, which appears in the query, the
value is always '2.0'
:type api_version: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
Expand All @@ -190,7 +183,7 @@ def get_swagger_local_valid(

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

# Construct headers
header_parameters = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ class SkipUrlEncodingOperations(object):
:param config: Configuration of service client.
:param serializer: An object model serializer.
:param deserializer: An objec model deserializer.
:ivar unencoded_path_param: An unencoded path parameter with value 'path1/path2/path3'. Constant value: "path1/path2/path3".
:ivar q1: An unencoded query parameter with value 'value1&q2=value2&q3=value3'. Constant value: "value1&q2=value2&q3=value3".
"""

def __init__(self, client, config, serializer, deserializer):

self._client = client
self._serialize = serializer
self._deserialize = deserializer
self.unencoded_path_param = "path1/path2/path3"
self.q1 = "value1&q2=value2&q3=value3"

self.config = config

Expand Down Expand Up @@ -129,13 +133,10 @@ def get_path_path_valid(
return client_raw_response

def get_swagger_path_valid(
self, unencoded_path_param="path1/path2/path3", custom_headers=None, raw=False, **operation_config):
self, custom_headers=None, raw=False, **operation_config):
"""Get method with unencoded path parameter with value
'path1/path2/path3'.

:param unencoded_path_param: An unencoded path parameter with value
'path1/path2/path3'
:type unencoded_path_param: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
Expand All @@ -148,7 +149,7 @@ def get_swagger_path_valid(
# Construct URL
url = '/azurespecials/skipUrlEncoding/swagger/path/valid/{unencodedPathParam}'
path_format_arguments = {
'unencodedPathParam': self._serialize.url("unencoded_path_param", unencoded_path_param, 'str', skip_quote=True)
'unencodedPathParam': self._serialize.url("self.unencoded_path_param", self.unencoded_path_param, 'str', skip_quote=True)
}
url = self._client.format_url(url, **path_format_arguments)

Expand Down Expand Up @@ -311,13 +312,10 @@ def get_path_query_valid(
return client_raw_response

def get_swagger_query_valid(
self, q1="value1&q2=value2&q3=value3", custom_headers=None, raw=False, **operation_config):
self, custom_headers=None, raw=False, **operation_config):
"""Get method with unencoded query parameter with value
'value1&q2=value2&q3=value3'.

:param q1: An unencoded query parameter with value
'value1&q2=value2&q3=value3'
:type q1: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
Expand All @@ -332,7 +330,7 @@ def get_swagger_query_valid(

# Construct parameters
query_parameters = {}
query_parameters['q1'] = self._serialize.query("q1", q1, 'str', skip_quote=True)
query_parameters['q1'] = self._serialize.query("self.q1", self.q1, 'str', skip_quote=True)

# Construct headers
header_parameters = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class AzureMethodGroupTemplateModel : MethodGroupTemplateModel
public AzureMethodGroupTemplateModel(ServiceClient serviceClient, string methodGroupName)
: base(serviceClient, methodGroupName)
{
MethodGroupType = methodGroupName + "Operations";
// Clear base initialized MethodTemplateModels and re-populate with
// AzureMethodTemplateModel
MethodTemplateModels.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public AzureServiceClientTemplateModel(ServiceClient serviceClient) : base(servi
.ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
// Removing all models that contain the extension "x-ms-external", as they will be
// generated in python client runtime for azure - "ms-rest-azure".
ModelTemplateModels.RemoveAll(m => m.Extensions.ContainsKey(AzureExtensions.PageableExtension));
ModelTemplateModels.RemoveAll(m => m.Extensions.ContainsKey(AzureExtensions.ExternalExtension));
ModelTemplateModels.RemoveAll(m => m.Extensions.ContainsKey(AzureExtensions.PageableExtension) && (bool)m.Extensions[AzureExtensions.PageableExtension]);
ModelTemplateModels.RemoveAll(m => m.Extensions.ContainsKey(AzureExtensions.ExternalExtension) && (bool)m.Extensions[AzureExtensions.ExternalExtension]);

HasAnyModel = false;
if (serviceClient.ModelTypes.Any())
Expand All @@ -39,7 +39,7 @@ public AzureServiceClientTemplateModel(ServiceClient serviceClient) : base(servi

public bool HasAnyLongRunOperation
{
get { return MethodTemplateModels.Any(m => m.Extensions.ContainsKey(AzureExtensions.LongRunningExtension)); }
get { return MethodTemplateModels.Any(m => m.Extensions.ContainsKey(AzureExtensions.LongRunningExtension) && (bool)m.Extensions[AzureExtensions.LongRunningExtension]); }
}

public bool HasAnyCloudErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
@if (Model.InputParameterTransformation.Any())
{
@EmptyLine
}
@if (Model.ConstantParameters.Any())
{
foreach (var parameter in Model.ConstantParameters)
{
@:@(parameter.Name) = @(parameter.DefaultValue)
}
@EmptyLine
}
# Construct URL
url = '@(Model.Url)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ class @(Model.MethodGroupType)(object):
:param config: Configuration of service client.
:param serializer: An object model serializer.
:param deserializer: An objec model deserializer.
@foreach(var property in Model.ConstantProperties)
{
@:@Model.GetPropertyDocumentationString(property)
}
"""
@EmptyLine
def __init__(self, client, config, serializer, deserializer):
@EmptyLine
self._client = client
self._serialize = serializer
self._deserialize = deserializer
@foreach(var property in Model.ConstantProperties)
{
@:@property.Name = @property.DefaultValue
}
@EmptyLine
self.config = config
@foreach (var method in Model.MethodTemplateModels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
@if (Model.InputParameterTransformation.Any())
{
@EmptyLine
}
@if (Model.ConstantParameters.Any())
{
foreach (var parameter in Model.ConstantParameters)
{
@:@(parameter.Name) = @(parameter.DefaultValue)
}
@EmptyLine
}
def internal_paging(next_link=None, raw=False):
@EmptyLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class @(Model.Name)Configuration(AzureConfiguration):
@: @ParameterWrapComment(string.Empty, ServiceClientTemplateModel.GetPropertyDocumentationString(property))
@: @ParameterWrapComment(string.Empty, ":type " + property.Name + ": " + Model.GetPropertyDocumentationType(property.Type))
}
@foreach(var property in Model.ConstantProperties)
{
@: @ParameterWrapComment(string.Empty, ServiceClientTemplateModel.GetPropertyDocumentationString(property))
@: @ParameterWrapComment(string.Empty, ":type " + property.Name + ": " + Model.GetPropertyDocumentationType(property.Type))
}

@if (!Model.IsCustomBaseUri)
{
Expand Down Expand Up @@ -89,6 +94,10 @@ else
{
@:self.@(property.Name) = @(property.Name)
}
foreach (var property in Model.ConstantProperties)
{
@:self.@(property.Name) = @(property.DefaultValue)
}
}
@EmptyLine
@EmptyLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def dst(self,dt):
class ComplexTests(unittest.TestCase):

def test_complex(self):
client = AutoRestComplexTestService(base_url="http://localhost:3000",api_version="2015-01-01")
client = AutoRestComplexTestService(base_url="http://localhost:3000")

# GET basic/valid
basic_result = client.basic_operations.get_valid()
Expand Down
Loading