예제 #1
0
    def test_entry_create_parent_no_order(self, full_app, sqla_session):
        from testscaffold.services.resource_tree_service import tree_service

        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_default_tree(db_session=sqla_session)
        url_path = "/api/0.1/entries"

        headers = {str("x-testscaffold-auth-token"): str(token)}
        entry_dict = {
            "id": -9999,
            "resource_name": "some-new-entry",
            "note": "text",
            "parent_id": 1,
        }
        response = full_app.post_json(url_path, entry_dict, status=200, headers=headers)
        result = tree_service.from_parent_deeper(
            1, db_session=sqla_session, limit_depth=1
        )
        tree_struct = tree_service.build_subtree_strut(result)["children"]
        pprint.pprint(tree_struct)
        assert response.json["resource_id"] > 0
        assert response.json["ordering"] == 5
        new_id = response.json["resource_id"]
        assert [i for i in tree_struct.keys()] == [5, 6, 7, 8, new_id]
예제 #2
0
파일: index.py 프로젝트: ergo/testscaffold
 def index(self):
     request = self.request
     login_form = UserLoginForm(request.POST, context={"request": request})
     log.warning("index", extra={"foo": "xxx"})
     log.info("locale", extra={"locale": request.locale_name})
     result = tree_service.from_parent_deeper(
         None, limit_depth=2, db_session=request.dbsession
     )
     tree = tree_service.build_subtree_strut(result)
     return {"login_form": login_form, "menu_entries": tree["children"]}
예제 #3
0
def get_possible_parents(request):
    result = tree_service.from_parent_deeper(db_session=request.dbsession)

    choices = [("", request.localizer.translate(_("Root (/)")))]
    for row in result:
        choices.append(
            (
                row.Resource.resource_id,
                "{} {}".format("--" * row.depth, row.Resource.resource_name),
            )
        )
    return choices
예제 #4
0
    def test_entry_delete(self, full_app, sqla_session):
        from testscaffold.services.resource_tree_service import tree_service

        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            entry = create_entry(
                {"resource_name": "entry-x", "note": "x"}, sqla_session=session
            )
        url_path = "/api/0.1/entries/{}".format(entry.resource_id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        full_app.delete_json(url_path, status=200, headers=headers)
        result = tree_service.from_parent_deeper(None, db_session=sqla_session)
        assert len(result.all()) == 0
예제 #5
0
    def test_entry_delete_branch(self, full_app, sqla_session):
        from testscaffold.services.resource_tree_service import tree_service

        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_default_tree(db_session=sqla_session)

        url_path = "/api/0.1/entries/{}".format(1)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        full_app.delete_json(url_path, status=200, headers=headers)
        result = tree_service.from_parent_deeper(None, db_session=sqla_session)
        row_ids = [r.Resource.resource_id for r in result]
        ordering = [r.Resource.ordering for r in result]
        assert row_ids == [-1, 2, 4, 3, 10, 11, -2, -3]
        assert ordering == [1, 1, 1, 2, 3, 4, 2, 3]
예제 #6
0
 def get(self):
     request = self.request
     resource = request.context.resource
     result = tree_service.from_parent_deeper(
         resource.resource_id, limit_depth=2, db_session=request.dbsession
     )
     breadcrumbs = tree_service.path_upper(
         resource.resource_id, db_session=request.dbsession
     )
     tree = tree_service.build_subtree_strut(result)
     return {
         "resource": resource,
         "breadcrumbs": breadcrumbs,
         "menu_entries": tree["children"],
     }
예제 #7
0
    def test_entry_patch_same_parent(self, full_app, sqla_session):
        from testscaffold.services.resource_tree_service import tree_service

        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_default_tree(db_session=sqla_session)

        url_path = "/api/0.1/entries/{}".format(1)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        entry_dict = {"parent_id": -1}
        response = full_app.patch_json(
            url_path, entry_dict, status=200, headers=headers
        )
        result = tree_service.from_parent_deeper(None, db_session=sqla_session)
        tree_struct = tree_service.build_subtree_strut(result)["children"]
        pprint.pprint(tree_struct)
        assert response.json["ordering"] == 1
예제 #8
0
    def test_entry_patch_order_upper_branch_no_order(self, full_app, sqla_session):
        from testscaffold.services.resource_tree_service import tree_service

        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_default_tree(db_session=sqla_session)

        url_path = "/api/0.1/entries/{}".format(12)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        entry_dict = {"parent_id": 1}
        response = full_app.patch_json(
            url_path, entry_dict, status=200, headers=headers
        )
        result = tree_service.from_parent_deeper(1, db_session=sqla_session)
        tree_struct = tree_service.build_subtree_strut(result)["children"]
        pprint.pprint(tree_struct)
        assert response.json["ordering"] == 5
        assert [i for i in tree_struct.keys()] == [5, 6, 7, 8, 12]
        assert [i["node"].ordering for i in tree_struct.values()] == [1, 2, 3, 4, 5]
예제 #9
0
    def test_entry_patch_order_same_branch_nested(
            self, full_app, sqla_session, node_id, position, ordered_elems):
        from testscaffold.services.resource_tree_service import tree_service
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_default_tree(db_session=sqla_session)

        url_path = '/api/0.1/entries/{}'.format(node_id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        entry_dict = {
            'ordering': position
        }
        response = full_app.patch_json(url_path, entry_dict, status=200,
                                       headers=headers)
        result = tree_service.from_parent_deeper(
            1, db_session=sqla_session)
        tree_struct = tree_service.build_subtree_strut(result)['children']
        pprint.pprint(tree_struct)
        assert response.json['ordering'] == position
        assert [i for i in tree_struct.keys()] == ordered_elems
        assert [i['node'].ordering for i in tree_struct.values()] == [1, 2, 3,
                                                                      4]
예제 #10
0
    def test_root_entry_no_parent_last(self, full_app, sqla_session):
        from testscaffold.services.resource_tree_service import tree_service
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_default_tree(db_session=sqla_session)
        url_path = '/api/0.1/entries'

        headers = {str('x-testscaffold-auth-token'): str(token)}
        entry_dict = {
            'id': -9999,
            'resource_name': 'some-new-entry',
            'note': 'text',
            'ordering': 4
        }
        response = full_app.post_json(url_path, entry_dict, status=200,
                                      headers=headers)
        result = tree_service.from_parent_deeper(
            None, db_session=sqla_session, limit_depth=1)
        tree_struct = tree_service.build_subtree_strut(result)['children']
        assert response.json['resource_id'] > 0
        assert response.json['ordering'] == 4
        new_id = response.json['resource_id']
        assert [i for i in tree_struct.keys()] == [-1, -2, -3, new_id]
예제 #11
0
    def collection_list(self):
        result = tree_service.from_parent_deeper(db_session=self.request.dbsession)
        entries_tree = tree_service.build_subtree_strut(result)

        return {"entries_tree": entries_tree}
예제 #12
0
    def collection_list(self):
        result = tree_service.from_parent_deeper(
            db_session=self.request.dbsession)
        entries_tree = tree_service.build_subtree_strut(result)

        return {'entries_tree': entries_tree}