Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 def test_unknown_extension_with_no_contents_not_real_file_results_in_exception(self):
     name = 'test.thisisnotarealextensionidonotcarwhatyousay'
     with assert_raises(IOError):
         get_mimetype(name)
Ejemplo n.º 8
0
 def test_get_markdown_mimetype_from_filename(self):
     name = 'test.md'
     mimetype = get_mimetype(name)
     assert_equal('text/x-markdown', mimetype)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 def test_unknown_extension_with_no_contents_not_real_file_results_in_exception(
         self):
     name = 'test.thisisnotarealextensionidonotcarwhatyousay'
     with assert_raises(IOError):
         get_mimetype(name)
Ejemplo n.º 12
0
 def test_get_markdown_mimetype_from_filename(self):
     name = 'test.md'
     mimetype = get_mimetype(name)
     assert_equal('text/x-markdown', mimetype)