def test_unknown_extension_with_python_contents_results_in_python_mimetype(self): name = 'test.thisisnotarealextensionidonotcarwhatyousay' python_file = os.path.join(HERE, 'test_utils.py') with open(python_file, 'r') as the_file: content = the_file.read() mimetype = get_mimetype(name, content) assert_equal('text/x-python', mimetype)
def github_download_file(**kwargs): node_settings = kwargs['node_addon'] path = get_path(kwargs) ref = request.args.get('sha') connection = GitHub.from_settings(node_settings.user_settings) try: name, data, _ = connection.file(node_settings.user, node_settings.repo, path, ref=ref) except TooBigError: raise HTTPError( http.BAD_REQUEST, data={ 'message_short': 'File too large', 'message_long': 'This file is too large to download through ' 'the GitHub API.', }, ) if data is None: raise HTTPError(http.NOT_FOUND) # Build response resp = make_response(data) mimetype = get_mimetype(path, data) # Add binary MIME type if mimetype not found if mimetype is None: resp.headers['Content-Type'] = 'application/octet-stream' else: resp.headers['Content-Type'] = mimetype resp.headers['Content-Disposition'] = 'attachment; filename={0}'.format( name) return resp
def github_download_file(**kwargs): node_settings = kwargs['node_addon'] path = get_path(kwargs) ref = request.args.get('sha') connection = GitHub.from_settings(node_settings.user_settings) try: name, data, _ = connection.file( node_settings.user, node_settings.repo, path, ref=ref ) except TooBigError: raise HTTPError( http.BAD_REQUEST, data={ 'message_short': 'File too large', 'message_long': 'This file is too large to download through ' 'the GitHub API.', }, ) if data is None: raise HTTPError(http.NOT_FOUND) # Build response resp = make_response(data) mimetype = get_mimetype(path, data) # Add binary MIME type if mimetype not found if mimetype is None: resp.headers['Content-Type'] = 'application/octet-stream' else: resp.headers['Content-Type'] = mimetype resp.headers['Content-Disposition'] = 'attachment; filename={0}'.format( name) return resp
def test_unknown_extension_with_real_file_results_in_python_mimetype(self): name = 'test_views.notarealfileextension' maybe_python_file = os.path.join(HERE, 'test_files', name) mimetype = get_mimetype(maybe_python_file) assert_equal('text/x-python', mimetype)
def test_unknown_extension_with_no_contents_not_real_file_results_in_exception2(self): name = 'test.thisisnotarealextensionidonotcarwhatyousay' mime_type = get_mimetype(name) assert_equal(None, mime_type)
def test_unknown_extension_with_no_contents_not_real_file_results_in_exception(self): name = 'test.thisisnotarealextensionidonotcarwhatyousay' with assert_raises(IOError): get_mimetype(name)
def test_get_markdown_mimetype_from_filename(self): name = 'test.md' mimetype = get_mimetype(name) assert_equal('text/x-markdown', mimetype)
def test_unknown_extension_with_no_contents_not_real_file_results_in_exception( self): name = 'test.thisisnotarealextensionidonotcarwhatyousay' mime_type = get_mimetype(name) assert_equal(None, mime_type)
def test_unknown_extension_with_no_contents_not_real_file_results_in_exception( self): name = 'test.thisisnotarealextensionidonotcarwhatyousay' with assert_raises(IOError): get_mimetype(name)