def test_move_child_position_json(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.json_body = {"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.json_body = {"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.json_body = {"from": "a", "to": "3"} result = move_child_position(root, request) assert result["result"] == "error" request.json_body = {"from": "0", "to": "10"} result = move_child_position(root, request) assert result["result"] == "error" request.json_body = {"from": "10", "to": "0"} result = move_child_position(root, request) assert result["result"] == "error" # Missing param request.json_body = {"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_json(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.json_body = {'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.json_body = {'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.json_body = {'from': 'a', 'to': '3'} result = move_child_position(root, request) assert result['result'] == 'error' request.json_body = {'from': '0', 'to': '10'} result = move_child_position(root, request) assert result['result'] == 'error' request.json_body = {'from': '10', 'to': '0'} result = move_child_position(root, request) assert result['result'] == 'error' # Missing param request.json_body = { '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_json(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.json_body = {'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.json_body = {'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.json_body = {'from': 'a', 'to': '3'} result = move_child_position(root, request) assert result['result'] == 'error' request.json_body = {'from': '0', 'to': '10'} result = move_child_position(root, request) assert result['result'] == 'error' request.json_body = {'from': '10', 'to': '0'} result = move_child_position(root, request) assert result['result'] == 'error' # Missing param request.json_body = {'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()