##// END OF EJS Templates
refactor to improve cell switching in edit mode...
refactor to improve cell switching in edit mode This code was repeated in both CodeCell and TextCell, both of which are extensions of Cell, so this just unifies the logic in Cell. TextCell had logic here to check if the cell was rendered or not, but I don't believe it is possible to end up triggering such a code path. (Should that be required, I can always just add back these methods to TextCell, performing the .rendered==True check, and calling the Cell prior to this, code mirror at_top would only return true on if the cursor was at the first character of the top line. Now, pressing up arrow on any character on the top line will take you to the cell above. The same applies for the bottom line. Pressing down arrow would only go to the next cell if the cursor was at a location *after* the last character (something that is only possible to achieve in vim mode if the last line is empty, for example). Now, down arrow on any character of the last line will go to the next cell.

File last commit:

r15103:246bd765
r15754:d60e793e
Show More
test_files.py
85 lines | 2.9 KiB | text/x-python | PythonLexer
MinRK
test /files/ gives 403 on hidden files
r13175 # coding: utf-8
"""Test the /files/ handler."""
import io
import os
from unicodedata import normalize
pjoin = os.path.join
import requests
from IPython.html.utils import url_path_join
from .launchnotebook import NotebookTestBase
from IPython.utils import py3compat
class FilesTest(NotebookTestBase):
def test_hidden_files(self):
not_hidden = [
u'å b',
MinRK
test 'files/' redirects...
r13564 u'å b/ç. d',
MinRK
test /files/ gives 403 on hidden files
r13175 ]
hidden = [
u'.å b',
MinRK
test 'files/' redirects...
r13564 u'å b/.ç d',
MinRK
test /files/ gives 403 on hidden files
r13175 ]
dirs = not_hidden + hidden
nbdir = self.notebook_dir.name
for d in dirs:
MinRK
s/os.path.sep/os.sep/
r13182 path = pjoin(nbdir, d.replace('/', os.sep))
MinRK
test /files/ gives 403 on hidden files
r13175 if not os.path.exists(path):
os.mkdir(path)
MinRK
Windows testing fixes
r13178 with open(pjoin(path, 'foo'), 'w') as f:
f.write('foo')
with open(pjoin(path, '.foo'), 'w') as f:
f.write('.foo')
MinRK
test /files/ gives 403 on hidden files
r13175 url = self.base_url()
for d in not_hidden:
MinRK
s/os.path.sep/os.sep/
r13182 path = pjoin(nbdir, d.replace('/', os.sep))
MinRK
test /files/ gives 403 on hidden files
r13175 r = requests.get(url_path_join(url, 'files', d, 'foo'))
r.raise_for_status()
MinRK
use request.text for Python 3 (content is always bytes)
r13565 self.assertEqual(r.text, 'foo')
MinRK
test /files/ gives 403 on hidden files
r13175 r = requests.get(url_path_join(url, 'files', d, '.foo'))
Brian E. Granger
Fixing test_files tests.
r15103 self.assertEqual(r.status_code, 404)
MinRK
test /files/ gives 403 on hidden files
r13175
for d in hidden:
MinRK
s/os.path.sep/os.sep/
r13182 path = pjoin(nbdir, d.replace('/', os.sep))
MinRK
test /files/ gives 403 on hidden files
r13175 for foo in ('foo', '.foo'):
r = requests.get(url_path_join(url, 'files', d, foo))
Brian E. Granger
Fixing test_files tests.
r15103 self.assertEqual(r.status_code, 404)
MinRK
test 'files/' redirects...
r13564
def test_old_files_redirect(self):
"""pre-2.0 'files/' prefixed links are properly redirected"""
nbdir = self.notebook_dir.name
base = self.base_url()
os.mkdir(pjoin(nbdir, 'files'))
os.makedirs(pjoin(nbdir, 'sub', 'files'))
for prefix in ('', 'sub'):
with open(pjoin(nbdir, prefix, 'files', 'f1.txt'), 'w') as f:
f.write(prefix + '/files/f1')
with open(pjoin(nbdir, prefix, 'files', 'f2.txt'), 'w') as f:
f.write(prefix + '/files/f2')
with open(pjoin(nbdir, prefix, 'f2.txt'), 'w') as f:
f.write(prefix + '/f2')
with open(pjoin(nbdir, prefix, 'f3.txt'), 'w') as f:
f.write(prefix + '/f3')
url = url_path_join(base, 'notebooks', prefix, 'files', 'f1.txt')
r = requests.get(url)
self.assertEqual(r.status_code, 200)
MinRK
use request.text for Python 3 (content is always bytes)
r13565 self.assertEqual(r.text, prefix + '/files/f1')
MinRK
test 'files/' redirects...
r13564
url = url_path_join(base, 'notebooks', prefix, 'files', 'f2.txt')
r = requests.get(url)
self.assertEqual(r.status_code, 200)
MinRK
use request.text for Python 3 (content is always bytes)
r13565 self.assertEqual(r.text, prefix + '/files/f2')
MinRK
test 'files/' redirects...
r13564
url = url_path_join(base, 'notebooks', prefix, 'files', 'f3.txt')
r = requests.get(url)
self.assertEqual(r.status_code, 200)
MinRK
use request.text for Python 3 (content is always bytes)
r13565 self.assertEqual(r.text, prefix + '/f3')
MinRK
test 'files/' redirects...
r13564