[python] add method to set/get default configuration (#5315)

* [python] add method to set/get default configuration

* [python] change method name and fix handling api_key

* python: using modified deepcopy to set/get default configuration

* python: update samples

* python: update samples
This commit is contained in:
Tomasz Prus
2020-02-23 21:10:44 +01:00
committed by GitHub
parent e4823cf4e6
commit 3f0c163f0c
13 changed files with 318 additions and 8 deletions

View File

@@ -22,14 +22,30 @@ class TestConfiguration(unittest.TestCase):
pass
def tearDown(self):
pass
# reset Configuration
petstore_api.Configuration.set_default(None)
def testConfiguration(self):
# check that different instances use different dictionaries
c1 = petstore_api.Configuration()
c2 = petstore_api.Configuration()
assert id(c1.api_key) != id(c2.api_key)
assert id(c1.api_key_prefix) != id(c2.api_key_prefix)
self.assertNotEqual(id(c1.api_key), id(c2.api_key))
self.assertNotEqual(id(c1.api_key_prefix), id(c2.api_key_prefix))
def testDefaultConfiguration(self):
# prepare default configuration
c1 = petstore_api.Configuration(host="example.com")
c1.debug = True
petstore_api.Configuration.set_default(c1)
# get default configuration
c2 = petstore_api.Configuration.get_default_copy()
self.assertEqual(c2.host, "example.com")
self.assertTrue(c2.debug)
self.assertNotEqual(id(c1.api_key), id(c2.api_key))
self.assertNotEqual(id(c1.api_key_prefix), id(c2.api_key_prefix))
if __name__ == '__main__':