コード例 #1
0
    def test_bootstrap_ignore_remote_caching(self, requests):
        requests.get.return_value = mock.Mock()
        requests.get.return_value.json.return_value = {
            'hey': {
                'methods': ['IGNORE']
            }
        }

        app = mock.Mock()
        app.extensions = {'symbolic_ratelimits': {}}
        app.app_context = mock.mock_open()
        app.config = {'WEBSERVICES_DISCOVERY_CACHE_DIR': ''}

        with mock.patch("__builtin__.open", mock.mock_open()) as mock_file:

            discovery_utils.bootstrap_remote_service(
                'http://foo.bar-us-east-1.com:8980/tee', '/foo', app)
            requests.get.assert_called_with(
                'http://foo.bar-us-east-1.com:8980/', timeout=5)
            try:
                mock_file.assert_called_with(
                    '/tmp/http:foobar-us-east-1com:8980tee', 'w')
                raise Exception('The file was opened!')
            except AssertionError:
                pass
コード例 #2
0
ファイル: test_discoverer.py プロジェクト: aaccomazzi/adsws
    def test_bootstrap_from_cache(self, m_json, requests, m_os):
        requests.get.side_effect = ConnectionError()
        requests.exceptions.ConnectionError = ConnectionError
        app = mock.Mock()
        app.app_context = mock.mock_open()
        app.config = {'WEBSERVICES_DISCOVERY_CACHE_DIR' : '/tmp'}
        m_os.path.join = os.path.join
        m_os.path.exists.return_value = True
        with mock.patch("__builtin__.open", mock.mock_open(read_data='{"hey": {"methods": ["IGNORE"]}}')) as mock_file:

            discovery_utils.bootstrap_remote_service('http://foo.bar-us-east-1.com:8980/tee', '/foo', app)
            requests.get.assert_called_with('http://foo.bar-us-east-1.com:8980/', timeout=5)
            m_os.path.exists.called_with('/tmp/http:foobar-us-east-1com:8980tee')
            m_json.loads.assert_called_with('{"hey": {"methods": ["IGNORE"]}}')
コード例 #3
0
ファイル: test_discoverer.py プロジェクト: romanchyla/adsws
    def test_bootstrap_from_cache(self, m_json, requests, m_os):
        requests.get.side_effect = ConnectionError()
        requests.exceptions.ConnectionError = ConnectionError
        app = mock.Mock()
        app.app_context = mock.mock_open()
        app.config = {'WEBSERVICES_DISCOVERY_CACHE_DIR' : '/tmp'}
        m_os.path.join = os.path.join
        m_os.path.exists.return_value = True
        with mock.patch("__builtin__.open", mock.mock_open(read_data='{"hey": {"methods": ["IGNORE"]}}')) as mock_file:

            discovery_utils.bootstrap_remote_service('http://foo.bar-us-east-1.com:8980/tee', '/foo', app)
            requests.get.assert_called_with('http://foo.bar-us-east-1.com:8980/', timeout=5)
            m_os.path.exists.called_with('/tmp/http:foobar-us-east-1com:8980tee')
            m_json.loads.assert_called_with('{"hey": {"methods": ["IGNORE"]}}')
コード例 #4
0
ファイル: test_discoverer.py プロジェクト: aaccomazzi/adsws
    def test_bootstrap_remote_caching(self, requests):
        requests.get.return_value = mock.Mock()
        requests.get.return_value.json.return_value = {'hey': {'methods': ['IGNORE']}}

        app = mock.Mock()
        app.app_context = mock.mock_open()
        app.config = {'WEBSERVICES_DISCOVERY_CACHE_DIR' : '/tmp'}

        with mock.patch("__builtin__.open", mock.mock_open()) as mock_file:

            discovery_utils.bootstrap_remote_service('http://foo.bar-us-east-1.com:8980/tee', '/foo', app)
            requests.get.assert_called_with('http://foo.bar-us-east-1.com:8980/', timeout=5)
            mock_file.assert_called_with('/tmp/http:foobar-us-east-1com:8980tee', 'w')
            file_handle = mock_file.return_value.__enter__.return_value
            file_handle.write.assert_called_with('{"hey": {"methods": ["IGNORE"]}}')
コード例 #5
0
ファイル: test_discoverer.py プロジェクト: romanchyla/adsws
    def test_bootstrap_remote_caching(self, requests):
        requests.get.return_value = mock.Mock()
        requests.get.return_value.json.return_value = {'hey': {'methods': ['IGNORE']}}

        app = mock.Mock()
        app.app_context = mock.mock_open()
        app.config = {'WEBSERVICES_DISCOVERY_CACHE_DIR' : '/tmp'}

        with mock.patch("__builtin__.open", mock.mock_open()) as mock_file:

            discovery_utils.bootstrap_remote_service('http://foo.bar-us-east-1.com:8980/tee', '/foo', app)
            requests.get.assert_called_with('http://foo.bar-us-east-1.com:8980/', timeout=5)
            mock_file.assert_called_with('/tmp/http:foobar-us-east-1com:8980tee', 'w')
            file_handle = mock_file.return_value.__enter__.return_value
            file_handle.write.assert_called_with('{"hey": {"methods": ["IGNORE"]}}')
コード例 #6
0
ファイル: test_discoverer.py プロジェクト: romanchyla/adsws
    def test_bootstrap_ignore_remote_caching(self, requests):
        requests.get.return_value = mock.Mock()
        requests.get.return_value.json.return_value = {'hey': {'methods': ['IGNORE']}}

        app = mock.Mock()
        app.app_context = mock.mock_open()
        app.config = {'WEBSERVICES_DISCOVERY_CACHE_DIR' : ''}

        with mock.patch("__builtin__.open", mock.mock_open()) as mock_file:

            discovery_utils.bootstrap_remote_service('http://foo.bar-us-east-1.com:8980/tee', '/foo', app)
            requests.get.assert_called_with('http://foo.bar-us-east-1.com:8980/', timeout=5)
            try:
                mock_file.assert_called_with('/tmp/http:foobar-us-east-1com:8980tee', 'w')
                raise Exception('The file was opened!')
            except AssertionError:
                pass