Add failing test for listing nonexistant directory

pull/37/head
Thomas Kluyver 13 years ago committed by MinRK
parent 99969474e0
commit 18f88d020f

@ -13,7 +13,7 @@ pjoin = os.path.join
import requests
from IPython.html.utils import url_path_join
from IPython.html.tests.launchnotebook import NotebookTestBase
from IPython.html.tests.launchnotebook import NotebookTestBase, assert_http_error
from IPython.nbformat.current import (new_notebook, write, read, new_worksheet,
new_heading_cell, to_notebook_json)
from IPython.utils.data import uniq_stable
@ -119,13 +119,9 @@ class APITest(NotebookTestBase):
expected = { normalize('NFC', name) for name in expected }
self.assertEqual(nbnames, expected)
def assert_404(self, name, path):
try:
self.nb_api.read(name, path)
except requests.HTTPError as e:
self.assertEqual(e.response.status_code, 404)
else:
assert False, "Reading a non-existent notebook should fail"
def test_list_nonexistant_dir(self):
with assert_http_error(404):
self.nb_api.list('nonexistant')
def test_get_contents(self):
for d, name in self.dirs_nbs:
@ -136,7 +132,8 @@ class APITest(NotebookTestBase):
self.assertIsInstance(nb['content']['metadata'], dict)
# Name that doesn't exist - should be a 404
self.assert_404('q.ipynb', 'foo')
with assert_http_error(404):
self.nb_api.read('q.ipynb', 'foo')
def _check_nb_created(self, resp, name, path):
self.assertEqual(resp.status_code, 201)
@ -212,4 +209,5 @@ class APITest(NotebookTestBase):
self.assertEqual(saved['path'], 'foo/bar')
assert os.path.isfile(pjoin(self.notebook_dir.name,'foo','bar','a2.ipynb'))
assert not os.path.isfile(pjoin(self.notebook_dir.name, 'foo', 'a.ipynb'))
self.assert_404('a.ipynb', 'foo')
with assert_http_error(404):
self.nb_api.read('a.ipynb', 'foo')

@ -9,7 +9,7 @@ import shutil
pjoin = os.path.join
from IPython.html.utils import url_path_join
from IPython.html.tests.launchnotebook import NotebookTestBase
from IPython.html.tests.launchnotebook import NotebookTestBase, assert_http_error
from IPython.nbformat.current import new_notebook, write
class SessionAPI(object):
@ -64,14 +64,6 @@ class SessionAPITest(NotebookTestBase):
self.sess_api.delete(session['id'])
shutil.rmtree(pjoin(self.notebook_dir.name, 'foo'))
def assert_404(self, id):
try:
self.sess_api.get(id)
except requests.HTTPError as e:
self.assertEqual(e.response.status_code, 404)
else:
assert False, "Getting nonexistent session didn't give HTTP error"
def test_create(self):
sessions = self.sess_api.list().json()
self.assertEqual(len(sessions), 0)
@ -101,7 +93,8 @@ class SessionAPITest(NotebookTestBase):
sessions = self.sess_api.list().json()
self.assertEqual(sessions, [])
self.assert_404(sid)
with assert_http_error(404):
self.sess_api.get(sid)
def test_modify(self):
newsession = self.sess_api.create('nb1.ipynb', 'foo').json()

@ -3,12 +3,12 @@
import sys
import time
import requests
from contextlib import contextmanager
from subprocess import Popen, PIPE
from unittest import TestCase
from IPython.utils.tempdir import TemporaryDirectory
class NotebookTestBase(TestCase):
"""A base class for tests that need a running notebook.
@ -67,3 +67,15 @@ class NotebookTestBase(TestCase):
@classmethod
def base_url(cls):
return 'http://localhost:%i/' % cls.port
@contextmanager
def assert_http_error(status):
try:
yield
except requests.HTTPError as e:
real_status = e.response.status_code
assert real_status == status, \
"Expected status %d, got %d" % (real_status, status)
else:
assert False, "Expected HTTP error status"
Loading…
Cancel
Save