def setUp(self): self.blank_collection = MockCollection( path='/blank_collection/', get_descendants=Mock(return_value=[]), get_parent=lambda: self.top_collection ) self.sub_object = MockObject( path='/collection/sub_object', getcontentlength=42, get_descendants=Mock(return_value=[]), get_parent=lambda: self.top_collection ) self.missing_sub_object = MissingMockObject( path='/collection/missing_sub_object', getcontentlength=42, get_descendants=Mock(return_value=[]), get_parent=lambda: self.top_collection ) self.missing_sub_collection = MissingMockCollection( path='/collection/missing_sub_collection', get_descendants=Mock(return_value=[]), get_parent=lambda: self.top_collection ) self.sub_collection = MockCollection( path='/collection/sub_colection/', get_descendants=Mock(return_value=[]), get_parent=lambda: self.top_collection ) self.top_collection = MockCollection( path='/collection/', get_descendants=Mock(return_value=[self.sub_object, self.sub_collection]) )
def test_copy_collection_depth_0(self): child = MockObject('/path/to/src/child', copy=Mock()) src = MockCollection('/path/to/src/', get_children=Mock(return_value=[child]), delete=Mock()) dst = MissingMockCollection('/path/to/dst/', create_collection=Mock()) src.copy(dst, 0) dst.create_collection.assert_called_with() self.assertEqual(child.copy.call_count, 0)
def test_copy_collection_collision(self): child = MockObject('/path/to/src/child', copy=Mock()) src = MockCollection('/path/to/src/', get_children=Mock(return_value=[child]), delete=Mock()) dst = MockCollection('/path/to/dst/', create_collection=Mock()) src.copy_collection(dst) self.assertEqual(dst.create_collection.call_count, 0) self.assertEqual(child.copy.call_args[0][0].path, ['path', 'to', 'dst', 'child'])
def test_move_collection(self): child = MockObject('/path/to/src/child', move=Mock()) src = MockCollection('/path/to/src/', get_children=Mock(return_value=[child]), delete=Mock()) dst = MissingMockCollection('/path/to/dst/', create_collection=Mock()) src.move(dst) src.delete.assert_called_with() dst.create_collection.assert_called_with() self.assertEqual(child.move.call_args[0][0].path, ['path', 'to', 'dst', 'child'])
def test_copy_collection_depth_0(self): child = MockObject('/path/to/src/child', copy=Mock()) src = MockCollection('/path/to/src/', get_children=Mock(return_value=[child]), delete=Mock()) dst = MissingMockCollection('/path/to/dst/', create_collection=Mock()) src.copy(dst, 0) dst.create_collection.assert_called_with() self.assertEqual(child.copy.call_count, 0)
def test_copy_collection_collision(self): child = MockObject('/path/to/src/child', copy=Mock()) src = MockCollection('/path/to/src/', get_children=Mock(return_value=[child]), delete=Mock()) dst = MockCollection('/path/to/dst/', create_collection=Mock()) src.copy_collection(dst) self.assertEqual(dst.create_collection.call_count, 0) self.assertEqual(child.copy.call_args[0][0].path, ['path', 'to', 'dst', 'child'])
def test_move_collection(self): child = MockObject('/path/to/src/child', move=Mock()) src = MockCollection('/path/to/src/', get_children=Mock(return_value=[child]), delete=Mock()) dst = MissingMockCollection('/path/to/dst/', create_collection=Mock()) src.move(dst) src.delete.assert_called_with() dst.create_collection.assert_called_with() self.assertEqual(child.move.call_args[0][0].path, ['path', 'to', 'dst', 'child'])
def test_get_collection(self): path = '/collection/' v = DavView(path=path, acl_class=FullAcl, base_url='/base', _allowed_methods=Mock(return_value=['ALL'])) v.__dict__['resource'] = MockCollection(path) resp = v.get(None, path) self.assertEqual(b"listing", resp.content) self.assertEqual("Wed, 24 Dec 2014 06:00:00 +0000", resp['Last-Modified'])
def test_allowed_missing_collection(self): v = DavView() parent = MockCollection('/path/to/obj') v.__dict__['resource'] = MissingMockCollection( '/path/', get_parent=Mock(return_value=parent)) self.assertListEqual( v._allowed_methods(), ['HEAD', 'OPTIONS', 'PROPFIND', 'GET', 'PUT', 'MKCOL'])
def test_get_collection_redirect(self): actual_path = '/collection/' wrong_path = '/collection' v = DavView(path=wrong_path, acl_class=FullAcl) v.__dict__['resource'] = MockCollection(actual_path) request = Mock(META={'SERVERNANE': 'testserver'}, build_absolute_uri=Mock(return_value=wrong_path)) resp = v.get(request, wrong_path, 'xbody') self.assertEqual(resp.status_code, 302) self.assertEqual(actual_path, resp['Location'])
def test_options_collection(self): path = '/collection/' v = DavView(path=path, _allowed_methods=Mock(return_value=['ALL']), acl_class=FullAcl) v.__dict__['resource'] = MockCollection(path) resp = v.options(None, path) self.assertEqual(sorted(resp.items()), [ ('Allow', 'ALL'), ('Content-Length', '0'), ('Content-Type', 'text/xml; charset="utf-8"'), ('DAV', '1,2'), ])