コード例 #1
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_builds_client_if_present_in_cache_but_stale(self):
     with patch('swaggerpy.client.time.time', side_effect=[2, 3]):
         client.factory = client.SwaggerClientFactory()
         client.factory.cache['foo'] = client.CachedClient('bar', 0, 1)
         with patch('swaggerpy.client.SwaggerClient') as mock:
             client.get_client('foo')
             mock.assert_called_once_with('foo')
コード例 #2
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_builds_client_if_present_in_cache_but_stale(self):
     with patch('swaggerpy.client.time.time', side_effect=[2, 3]):
         client.factory = client.SwaggerClientFactory()
         client.factory.cache['foo'] = client.CachedClient('bar', 0, 1)
         with patch('swaggerpy.client.SwaggerClient') as mock:
             client.get_client('foo')
             mock.assert_called_once_with('foo')
コード例 #3
0
 def test_cache_of_a_json_dict(self):
     client.get_client({'swaggerVersion': '1.2', 'apis': []})
     self.assertTrue(
         repr(({
             'swaggerVersion': '1.2',
             'apis': []
         }, )) + "[]" in client.cache.cache)
コード例 #4
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_uses_the_cache_if_present_and_fresh(self):
     client.factory = client.SwaggerClientFactory()
     client.factory.cache['foo'] = client.CachedClient('bar', 2, 1)
     with patch('swaggerpy.client.SwaggerClient') as mock:
         with patch('swaggerpy.client.time.time', side_effect=[2]):
             client.get_client('foo')
             assert not mock.called
コード例 #5
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_uses_the_cache_if_present_and_fresh(self):
     client.factory = client.SwaggerClientFactory()
     client.factory.cache['foo'] = client.CachedClient('bar', 2, 1)
     with patch('swaggerpy.client.SwaggerClient') as mock:
         with patch('swaggerpy.client.time.time', side_effect=[2]):
             client.get_client('foo')
             assert not mock.called
コード例 #6
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_get_client_uses_instantiated_factory_second_time(self):
     with patch.object(SwaggerClientFactory, '__call__') as mock_method:
         mock_method.client.return_value = None
         client.factory = SwaggerClientFactory()
         prev_factory = client.factory
         client.get_client()
         self.assertTrue(prev_factory is client.factory)
コード例 #7
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_get_client_uses_instantiated_factory_second_time(self):
     with patch.object(SwaggerClientFactory, '__call__') as mock_method:
         mock_method.client.return_value = None
         client.factory = SwaggerClientFactory()
         prev_factory = client.factory
         client.get_client()
         self.assertTrue(prev_factory is client.factory)
コード例 #8
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_is_stale_returns_false_before_timeout(self):
     with patch('swaggerpy.client.SwaggerClient'):
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('test', timeout=10)
             self.assertFalse(client.factory.cache['test'].is_stale(11))
コード例 #9
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_builds_client_if_not_present_in_cache(self):
     with patch('swaggerpy.client.SwaggerClient') as mock:
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('foo')
             mock.assert_called_once_with('foo')
コード例 #10
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_is_stale_returns_false_before_timeout(self):
     with patch('swaggerpy.client.SwaggerClient'):
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('test', timeout=10)
             self.assertFalse(client.factory.cache['test'].is_stale(11))
コード例 #11
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_is_stale_returns_true_after_timeout(self):
     with patch('swaggerpy.client.SwaggerClient'):
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('test', timeout=10)
             self.assertTrue(client.factory.cache['test'].is_stale(12))
コード例 #12
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_serialization_of_json_dict(self):
     client.get_client({'swaggerVersion': '1.2', 'apis': []})
     self.assertTrue({
         'swaggerVersion': '1.2',
         'apis': []
     } in map(json.loads, client.factory.cache.keys()))
コード例 #13
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_is_stale_returns_true_after_timeout(self):
     with patch('swaggerpy.client.SwaggerClient'):
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('test', timeout=10)
             self.assertTrue(client.factory.cache['test'].is_stale(12))
コード例 #14
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_serialization_of_json_dict(self):
     client.get_client({'swaggerVersion': '1.2', 'apis': []})
     self.assertTrue({'swaggerVersion': '1.2', 'apis': []} in
                     map(json.loads, client.factory.cache.keys()))
コード例 #15
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_get_client_allows_json_dict(self):
     client_stub = client.get_client(self.resource_listing)
     self.assertTrue(isinstance(client_stub, client.SwaggerClient))
コード例 #16
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_get_client_instantiates_new_factory_if_not_set(self):
     with patch.object(SwaggerClientFactory, '__call__') as mock_method:
         mock_method.client.return_value = None
         client.get_client()
         self.assertTrue(client.factory is not None)
コード例 #17
0
 def test_cache_with_async_http_client(self, _):
     url = 'http://example.com/api-docs'
     swagger_client = client.get_client(
         url, http_client=AsynchronousHttpClient())
     other = client.get_client(url, http_client=AsynchronousHttpClient())
     assert swagger_client is other
コード例 #18
0
 def test_is_stale_returns_false_before_ttl(self):
     with patch('swaggerpy.client.SwaggerClient'):
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('test', ttl=10)
             assert not client.cache.cache["('test',)[]"].is_stale(11)
コード例 #19
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_get_client_instantiates_new_factory_if_not_set(self):
     with patch.object(SwaggerClientFactory, '__call__') as mock_method:
         mock_method.client.return_value = None
         client.get_client()
         self.assertTrue(client.factory is not None)
コード例 #20
0
ファイル: client_test.py プロジェクト: asgillmor/swagger-py
 def test_builds_client_if_not_present_in_cache(self):
     with patch('swaggerpy.client.SwaggerClient') as mock:
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('foo')
             mock.assert_called_once_with('foo')
コード例 #21
0
ファイル: client_test.py プロジェクト: Neston3/swagger-py
 def test_get_client_allows_json_dict(self):
     client_stub = client.get_client(self.resource_listing)
     self.assertTrue(isinstance(client_stub, client.SwaggerClient))
コード例 #22
0
 def test_is_stale_returns_true_after_ttl(self):
     with patch('swaggerpy.client.SwaggerClient'):
         with patch('swaggerpy.client.time.time', side_effect=[1]):
             client.get_client('test', ttl=10)
             self.assertTrue(client.cache.cache["('test',){}"].is_stale(12))