From b48737015f760af3b0dd7f32e45e090dfa2347df 2014-12-17 19:38:45 From: Scott Sanderson Date: 2014-12-17 19:38:45 Subject: [PATCH] TEST: More fine-grained test for directory contents. Verify that each entry in a directory listing matches the result of a content-less direct get. --- diff --git a/IPython/html/services/contents/tests/test_manager.py b/IPython/html/services/contents/tests/test_manager.py index f0ac596..d2c6a3d 100644 --- a/IPython/html/services/contents/tests/test_manager.py +++ b/IPython/html/services/contents/tests/test_manager.py @@ -188,8 +188,30 @@ class TestContentsManager(TestCase): self.assertEqual(model2['path'], '{0}/{1}'.format(sub_dir.strip('/'), name)) # Test getting directory model + + # Create a sub-sub directory to test getting directory contents with a + # subdir. + sub_sub_dir_path = 'foo/bar' + self.make_dir(sub_sub_dir_path) + dirmodel = cm.get('foo') self.assertEqual(dirmodel['type'], 'directory') + self.assertIsInstance(dirmodel['content'], list) + self.assertEqual(len(dirmodel['content']), 2) + + # Directory contents should match the contents of each individual entry + # when requested with content=False. + model2_no_content = cm.get(sub_dir + name, content=False) + sub_sub_dir_no_content = cm.get(sub_sub_dir_path, content=False) + for entry in dirmodel['content']: + # Order isn't guaranteed by the spec, so this is a hacky way of + # verifying that all entries are matched. + if entry['path'] == sub_sub_dir_no_content['path']: + self.assertEqual(entry, sub_sub_dir_no_content) + elif entry['path'] == model2_no_content['path']: + self.assertEqual(entry, model2_no_content) + else: + self.fail("Unexpected directory entry: %s" % entry()) with self.assertRaises(HTTPError): cm.get('foo', type='file')