def _http_get(service, url, *args, **kwargs): self.assertEqual( url, 'https://bitbucket.org/api/1.0/repositories/' 'myuser/myrepo/raw/%s/path' % expected_revision) if expected_found: return b'{}', {} else: error = HTTPError(url, 404, 'Not Found', {}, None) error.read = lambda: error.reason raise error
def _http_get(service, url, *args, **kwargs): self.assertEqual( url, 'https://bitbucket.org/api/1.0/repositories/' 'myuser/myrepo/raw/%s/path' % expected_revision) if expected_found: return b'{}', {} else: error = HTTPError(url, 404, 'Not Found', {}, None) error.read = lambda: error.msg raise error
def _handler(client, request): url = request.url parts = urlparse(url) full_path = '%s?%s' % (parts.path, parts.query) path_info = paths.get(full_path) if path_info is None: path_info = paths.get(parts.path) if path_info is None: path_info = paths.get(None) if path_info is None: self.fail('Unexpected path "%s"' % full_path) status_code = path_info.get('status_code') or 200 payload = path_info.get('payload') or b'' headers = path_info.get('headers') or {} if status_code >= 400: raise HTTPError(url, status_code, '', headers, io.BytesIO(payload)) else: return HostingServiceHTTPResponse(request=request, url=url, data=payload, headers=headers, status_code=status_code)
def _http_get(service, url, *args, **kwargs): self.assertEqual( url, 'https://mydomain.unfuddle.com/api/v1/repositories/2/' 'history/?path=/path&commit=%s&count=0' % expected_revision) if expected_found: return '{}', {} else: raise HTTPError()
def _http_get(service, url, *args, **kwargs): self.assertEqual( url, 'https://api.github.com/repos/myuser/invalid' '?access_token=123') payload = { 'message': 'Not Found', } raise HTTPError(url, 404, '', {}, StringIO(json.dumps(payload)))
def _http_get(service, url, *args, **kwargs): if expect_git_blob_url: self.assertEqual( url, 'https://api3.codebasehq.com/myproj/myrepo/blob/123') else: self.assertEqual( url, 'https://api3.codebasehq.com/myproj/myrepo/blob/123/' 'myfile') if file_exists: return b'{}', {} else: raise HTTPError(url, 404, '', {}, StringIO())
def mock_urlopen(url, data=None, **kwargs): msg_dict = {'301': "Moved Permanently", '404': 'Not Found', '200': 'OK'} code = '404' msg = msg_dict.get(code) m = re.search("([0-9]*)$", url) if m: code = m.group(0) msg = msg_dict.get(code, 'Something Happened') if code == "200": return addinfourl(url, code, msg) raise HTTPError(url, code, msg, None, None)
def _http_get(service, url, *args, **kwargs): expected_url = ('https://mydomain.beanstalkapp.com/api/' 'repositories/myrepo/') if not base_commit_id and tool_name == 'Git': expected_url += 'blob?id=%s&name=path' % expected_revision else: expected_url += ('node.json?path=/path&revision=%s' % expected_revision) self.assertEqual(url, expected_url) if expected_found: return b'{}', {} else: raise HTTPError()
def test_get_file_http_with_http_error_404(self): """Testing SCMClient.get_file_http with HTTPError 404""" self.spy_on(urlopen, op=kgb.SpyOpRaise( HTTPError(url='https://example.com', code=404, msg=None, hdrs=None, fp=None))) client = SCMClient(path='/path/to/repo') with self.assertRaises(FileNotFoundError) as ctx: client.get_file_http('https://example.com', path='/path/to/file', revision='abc123') e = ctx.exception self.assertEqual(e.path, '/path/to/file') self.assertEqual(e.revision, 'abc123')
def test_get_file_http_with_http_error(self): """Testing SCMClient.get_file_http with HTTPError""" self.spy_on(urlopen, op=kgb.SpyOpRaise( HTTPError(url='https://example.com', code=500, msg='Kablam', hdrs=None, fp=None))) client = SCMClient(path='/path/to/repo') message = ( 'HTTP error code 500 when fetching file from https://example.com: ' 'HTTP Error 500: Kablam') with self.assertRaisesMessage(SCMError, message) as ctx: client.get_file_http('https://example.com', path='/path/to/file', revision='abc123') self.assertNotIsInstance(ctx.exception, FileNotFoundError)
def _handler(client, url, *args, **kwargs): parts = urlparse(url) path_info = paths.get('%s?%s' % (parts.path, parts.query)) if path_info is None: path_info = paths.get(parts.path) if path_info is None: path_info = paths.get(None) if path_info is None: self.fail('Unexpected path "%s"' % parts.path) status_code = path_info.get('status_code') payload = path_info.get('payload') or b'' headers = path_info.get('headers') or {} if status_code is not None and status_code >= 400: raise HTTPError(url, status_code, '', headers, io.BytesIO(payload)) else: return payload, headers
def _http_get(service, url, *args, **kwargs): if http_status == 200: return payload, {} else: raise HTTPError(url, http_status, '', {}, StringIO(payload))
def _http_get(service, url, *args, **kwargs): raise HTTPError(url, 403, '', {}, StringIO(''))
def _raise_403(obj): raise HTTPError('', 403, 'Authentication failed', None, None)