def test_multi_delete(self, root): from kotti.resources import Document from kotti.resources import File from kotti.views.edit.actions import NodeActions root['child1'] = Document(title="Child 1") root['child2'] = Document(title="Child 2") root['file1'] = File(title="File 1") request = DummyRequest() request.POST = MultiDict() id1 = str(root['child1'].id) id2 = str(root['child2'].id) id3 = str(root['file1'].id) request.POST.add('delete_nodes', 'delete_nodes') NodeActions(root, request).delete_nodes() assert request.session.pop_flash('info') ==\ ['Nothing was deleted.'] request.POST.add('children-to-delete', id1) request.POST.add('children-to-delete', id2) request.POST.add('children-to-delete', id3) NodeActions(root, request).delete_nodes() assert request.session.pop_flash('success') == \ ['${title} was deleted.', '${title} was deleted.', '${title} was deleted.']
def test_multi_rename(self, root): from kotti.resources import Document from kotti.views.edit.actions import NodeActions self.setUp() root["child1"] = Document(title="Child 1") root["child2"] = Document(title="Child 2") request = DummyRequest() request.POST = MultiDict() id1 = str(root["child1"].id) id2 = str(root["child2"].id) request.POST.add("children-to-rename", id1) request.POST.add("children-to-rename", id2) request.POST.add(id1 + "-name", "") request.POST.add(id1 + "-title", "Unhappy Child") request.POST.add(id2 + "-name", "happy-child") request.POST.add(id2 + "-title", "") request.POST.add("rename_nodes", "rename_nodes") NodeActions(root, request).rename_nodes() assert request.session.pop_flash("error") == ["Name and title are required."] request.POST.add(id1 + "-name", "unhappy-child") request.POST.add(id1 + "-title", "Unhappy Child") request.POST.add(id2 + "-name", "happy-child") request.POST.add(id2 + "-title", "Happy Child") request.POST.add("rename_nodes", "rename_nodes") NodeActions(root, request).rename_nodes() assert request.session.pop_flash("success") == ["Your changes have been saved."]
def test_multi_rename(self, root): from kotti.resources import Document from kotti.views.edit.actions import NodeActions self.setUp() root['child1'] = Document(title="Child 1") root['child2'] = Document(title="Child 2") request = DummyRequest() request.POST = MultiDict() id1 = str(root['child1'].id) id2 = str(root['child2'].id) request.POST.add('children-to-rename', id1) request.POST.add('children-to-rename', id2) request.POST.add(id1 + '-name', '') request.POST.add(id1 + '-title', 'Unhappy Child') request.POST.add(id2 + '-name', 'happy-child') request.POST.add(id2 + '-title', '') request.POST.add('rename_nodes', 'rename_nodes') NodeActions(root, request).rename_nodes() assert request.session.pop_flash('error') ==\ ['Name and title are required.'] request.POST.add(id1 + '-name', 'unhappy-child') request.POST.add(id1 + '-title', 'Unhappy Child') request.POST.add(id2 + '-name', 'happy-child') request.POST.add(id2 + '-title', 'Happy Child') request.POST.add('rename_nodes', 'rename_nodes') NodeActions(root, request).rename_nodes() assert request.session.pop_flash('success') ==\ ['Your changes have been saved.']
def test_multi_delete(self, root): from kotti.resources import Document from kotti.resources import File from kotti.views.edit.actions import NodeActions root["child1"] = Document(title="Child 1") root["child2"] = Document(title="Child 2") root["file1"] = File(title="File 1") request = DummyRequest() request.POST = MultiDict() id1 = str(root["child1"].id) id2 = str(root["child2"].id) id3 = str(root["file1"].id) request.POST.add("delete_nodes", "delete_nodes") NodeActions(root, request).delete_nodes() assert request.session.pop_flash("info") == ["Nothing was deleted."] request.POST.add("children-to-delete", id1) request.POST.add("children-to-delete", id2) request.POST.add("children-to-delete", id3) NodeActions(root, request).delete_nodes() assert request.session.pop_flash("success") == [ "${title} was deleted.", "${title} was deleted.", "${title} was deleted.", ]
def test_multi_rename(self): from kotti import DBSession from kotti.resources import Node from kotti.resources import Document from kotti.views.edit.actions import NodeActions self.setUp() root = DBSession.query(Node).get(1) root['child1'] = Document(title=u"Child 1") root['child2'] = Document(title=u"Child 2") request = DummyRequest() request.POST = MultiDict() id1 = str(root['child1'].id) id2 = str(root['child2'].id) request.POST.add('children-to-rename', id1) request.POST.add('children-to-rename', id2) request.POST.add(id1 + '-name', u'') request.POST.add(id1 + '-title', u'Unhappy Child') request.POST.add(id2 + '-name', u'happy-child') request.POST.add(id2 + '-title', u'') request.POST.add('rename_nodes', u'rename_nodes') NodeActions(root, request).rename_nodes() assert request.session.pop_flash('error') ==\ [u'Name and title are required.'] request.POST.add(id1 + '-name', u'unhappy-child') request.POST.add(id1 + '-title', u'Unhappy Child') request.POST.add(id2 + '-name', u'happy-child') request.POST.add(id2 + '-title', u'Happy Child') request.POST.add('rename_nodes', u'rename_nodes') NodeActions(root, request).rename_nodes() assert request.session.pop_flash('success') ==\ [u'Your changes have been saved.']
def test_multi_delete(self): from kotti import DBSession from kotti.resources import Node from kotti.resources import Document from kotti.resources import File from kotti.views.edit.actions import NodeActions root = DBSession.query(Node).get(1) root['child1'] = Document(title=u"Child 1") root['child2'] = Document(title=u"Child 2") root['file1'] = File(title=u"File 1") request = DummyRequest() request.POST = MultiDict() id1 = str(root['child1'].id) id2 = str(root['child2'].id) id3 = str(root['file1'].id) request.POST.add('delete_nodes', u'delete_nodes') NodeActions(root, request).delete_nodes() assert request.session.pop_flash('info') ==\ [u'Nothing deleted.'] request.POST.add('children-to-delete', id1) request.POST.add('children-to-delete', id2) request.POST.add('children-to-delete', id3) NodeActions(root, request).delete_nodes() assert request.session.pop_flash('success') ==\ [u'${title} deleted.', u'${title} deleted.', u'${title} deleted.']
def test_player_options(db_session): root = get_root() audio = root['audio'] = Audio() # test GET player_options = AudioView(audio, DummyRequest()).player_options() assert player_options.body.find("<form") > -1 assert player_options.body.find( 'action="http://example.com/audio/player_options"') > -1 # test POST with missing parameters post_request = DummyRequest() post_request.POST = {'save': 'save'} player_options = AudioView(audio, post_request).player_options() assert player_options.body.find("There was a problem with your submission") > -1 # noqa # test POST with all parameters post_request = DummyRequest() post_request.POST = default_player_options post_request.POST = PlayerOptionsSchema().serialize(post_request.POST) post_request.POST.update({'save': 'save'}) player_options = AudioView(audio, post_request).player_options() assert player_options.body.find("edit_player_options_success = true") > -1
def test_multi_delete(self): from kotti import DBSession from kotti.resources import Node from kotti.resources import Document from kotti.views.edit.actions import NodeActions root = DBSession.query(Node).get(1) root['child1'] = Document(title=u"Child 1") root['child2'] = Document(title=u"Child 2") request = DummyRequest() request.POST = MultiDict() id1 = str(root['child1'].id) id2 = str(root['child2'].id) request.POST.add('delete_nodes', u'delete_nodes') NodeActions(root, request).delete_nodes() assert request.session.pop_flash('info') ==\ [u'Nothing deleted.'] request.POST.add('children-to-delete', id1) request.POST.add('children-to-delete', id2) NodeActions(root, request).delete_nodes() assert request.session.pop_flash('success') ==\ [u'${title} deleted.', u'${title} deleted.']
def test_move_child_position_post(self, root, db_session): import transaction from kotti.resources import Document from kotti.resources import get_root from kotti.views.edit.actions import move_child_position # Create some documents root['child1'] = Document(title="Child 1") root['child2'] = Document(title="Child 2") root['child3'] = Document(title="Child 3") root['child4'] = Document(title="Child 4") root['child5'] = Document(title="Child 5") assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children ] == ['child1', 'child2', 'child3', 'child4', 'child5'] request = DummyRequest() # Move down request.POST = {'from': '0', 'to': '3'} result = move_child_position(root, request) transaction.commit() root = get_root() assert result['result'] == 'success' assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children ] == ['child2', 'child3', 'child4', 'child1', 'child5'] # Move up request.POST = {'from': '4', 'to': '0'} move_child_position(root, request) transaction.commit() root = get_root() assert result['result'] == 'success' assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children ] == ['child5', 'child2', 'child3', 'child4', 'child1'] # Invalid param value request.POST = {'from': 'a', 'to': '3'} result = move_child_position(root, request) assert result['result'] == 'error' request.POST = {'from': '0', 'to': '10'} result = move_child_position(root, request) assert result['result'] == 'error' request.POST = {'from': '10', 'to': '0'} result = move_child_position(root, request) assert result['result'] == 'error' # Missing param request.POST = { 'from': 'a', } result = move_child_position(root, request) assert result['result'] == 'error' # we have to clean up, because we committed transactions del root['child1'] del root['child2'] del root['child3'] del root['child4'] del root['child5'] transaction.commit()
def test_move_child_position_post(self, root, db_session): import transaction from kotti.resources import Document from kotti.resources import get_root from kotti.views.edit.actions import move_child_position # Create some documents root["child1"] = Document(title="Child 1") root["child2"] = Document(title="Child 2") root["child3"] = Document(title="Child 3") root["child4"] = Document(title="Child 4") root["child5"] = Document(title="Child 5") assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children] == [ "child1", "child2", "child3", "child4", "child5", ] request = DummyRequest() # Move down request.POST = {"from": "0", "to": "3"} result = move_child_position(root, request) transaction.commit() root = get_root() assert result["result"] == "success" assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children] == [ "child2", "child3", "child4", "child1", "child5", ] # Move up request.POST = {"from": "4", "to": "0"} move_child_position(root, request) transaction.commit() root = get_root() assert result["result"] == "success" assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children] == [ "child5", "child2", "child3", "child4", "child1", ] # Invalid param value request.POST = {"from": "a", "to": "3"} result = move_child_position(root, request) assert result["result"] == "error" request.POST = {"from": "0", "to": "10"} result = move_child_position(root, request) assert result["result"] == "error" request.POST = {"from": "10", "to": "0"} result = move_child_position(root, request) assert result["result"] == "error" # Missing param request.POST = {"from": "a"} result = move_child_position(root, request) assert result["result"] == "error" # we have to clean up, because we committed transactions del root["child1"] del root["child2"] del root["child3"] del root["child4"] del root["child5"] transaction.commit()
def test_move_child_position_post(self, root, db_session): import transaction from kotti.resources import Document from kotti.resources import get_root from kotti.views.edit.actions import move_child_position # Create some documents root['child1'] = Document(title=u"Child 1") root['child2'] = Document(title=u"Child 2") root['child3'] = Document(title=u"Child 3") root['child4'] = Document(title=u"Child 4") root['child5'] = Document(title=u"Child 5") assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children] == [ u'child1', u'child2', u'child3', u'child4', u'child5'] request = DummyRequest() # Move down request.POST = {'from': '0', 'to': '3'} result = move_child_position(root, request) transaction.commit() root = get_root() assert result['result'] == 'success' assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children] == [ u'child2', u'child3', u'child4', u'child1', u'child5'] # Move up request.POST = {'from': '4', 'to': '0'} move_child_position(root, request) transaction.commit() root = get_root() assert result['result'] == 'success' assert [c.position for c in root._children] == [0, 1, 2, 3, 4] assert [c.name for c in root._children] == [ u'child5', u'child2', u'child3', u'child4', u'child1'] # Invalid param value request.POST = {'from': 'a', 'to': '3'} result = move_child_position(root, request) assert result['result'] == 'error' request.POST = {'from': '0', 'to': '10'} result = move_child_position(root, request) assert result['result'] == 'error' request.POST = {'from': '10', 'to': '0'} result = move_child_position(root, request) assert result['result'] == 'error' # Missing param request.POST = {'from': 'a', } result = move_child_position(root, request) assert result['result'] == 'error' # we have to clean up, because we committed transactions del root['child1'] del root['child2'] del root['child3'] del root['child4'] del root['child5'] transaction.commit()