From 4d4864640380893cf06ce627f4bcd1ed9286d8ac Mon Sep 17 00:00:00 2001 From: Ted Chambers Date: Sat, 23 Nov 2019 12:50:47 -0500 Subject: [PATCH] add test --- azure-devops/azure/devops/client.py | 2 +- azure-devops/azure/devops/connection.py | 5 +- .../azure/devops/issue_tests/__init__.py | 7 +++ .../devops/issue_tests/test_issue_268.py | 47 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 azure-devops/azure/devops/issue_tests/__init__.py create mode 100644 azure-devops/azure/devops/issue_tests/test_issue_268.py diff --git a/azure-devops/azure/devops/client.py b/azure-devops/azure/devops/client.py index 4ad4014..ad71109 100644 --- a/azure-devops/azure/devops/client.py +++ b/azure-devops/azure/devops/client.py @@ -187,7 +187,7 @@ class Client(object): try: logger.debug('File cache hit for options on: %s', url) self._locations[url] = self._base_deserialize.deserialize_data(OPTIONS_FILE_CACHE[url], - '[ApiResourceLocation]') + '[ApiResourceLocation]') return self._locations[url] except DeserializationError as ex: logger.debug(ex, exc_info=True) diff --git a/azure-devops/azure/devops/connection.py b/azure-devops/azure/devops/connection.py index 419e37b..ea21a5a 100644 --- a/azure-devops/azure/devops/connection.py +++ b/azure-devops/azure/devops/connection.py @@ -109,8 +109,9 @@ class Connection(object): if not force and RESOURCE_FILE_CACHE[location_client.normalized_url]: try: logger.debug('File cache hit for resources on: %s', location_client.normalized_url) - self._resource_areas = location_client._base_deserialize.deserialize_data(RESOURCE_FILE_CACHE[location_client.normalized_url], - '[ResourceAreaInfo]') + self._resource_areas = location_client._base_deserialize.deserialize_data( + RESOURCE_FILE_CACHE[location_client.normalized_url], + '[ResourceAreaInfo]') return self._resource_areas except Exception as ex: logger.debug(ex, exc_info=True) diff --git a/azure-devops/azure/devops/issue_tests/__init__.py b/azure-devops/azure/devops/issue_tests/__init__.py new file mode 100644 index 0000000..f885a96 --- /dev/null +++ b/azure-devops/azure/devops/issue_tests/__init__.py @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +# Generated file, DO NOT EDIT +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------------------------- diff --git a/azure-devops/azure/devops/issue_tests/test_issue_268.py b/azure-devops/azure/devops/issue_tests/test_issue_268.py new file mode 100644 index 0000000..9dbfab0 --- /dev/null +++ b/azure-devops/azure/devops/issue_tests/test_issue_268.py @@ -0,0 +1,47 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import pprint +import unittest + +from msrest import Deserializer +from msrest.universal_http import HTTPClientResponse + + +class _TestResponse(HTTPClientResponse): + def __init__(self, text): + super(_TestResponse, self).__init__(request=None, internal_response=None) + self._text = text + + def text(self, encoding=None): + return self._text + + +class TestDeserialization(unittest.TestCase): + + # https://github.com/microsoft/azure-devops-python-api/issues/268 + def test_deserialization_issue_268_50(self): + from azure.devops.v5_0.task_agent import models + self._test_deserialization(models.__dict__.items(), _268_type, _268_json) + + # https://github.com/microsoft/azure-devops-python-api/issues/268 + def test_deserialization_issue_268_51(self): + from azure.devops.v5_1.task_agent import models + self._test_deserialization(models.__dict__.items(), _268_type, _268_json) + + @staticmethod + def _test_deserialization(models, data_type, json): + client_models = {k: v for k, v in models if isinstance(v, type)} + deserializer = Deserializer(client_models) + response = _TestResponse(json) + task_agent_response = deserializer(data_type, response) + pprint.pprint(task_agent_response.__dict__) + + +if __name__ == '__main__': + unittest.main() + +_268_type = 'TaskAgentReference' +_268_json = '{"id":0,"name":null,"version":null,"osDescription":"Foo","provisioningState":null}'