Пример #1
0
    def test_group_permission_remove_proper(self, full_app, sqla_session):
        perm_name = 'edit'
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group({'group_name': 'aaaa'}, sqla_session=session)
            resource = create_entry({
                'resource_name': 'entry-x',
                'note': 'x'
            },
                                    sqla_session=session)
            perm_inst = GroupResourcePermission(group_id=group.id,
                                                perm_name=perm_name)
            resource.group_permissions.append(perm_inst)

        node_id = resource.resource_id
        qs = parse.urlencode({'group_id': group.id, 'perm_name': perm_name})
        url_path = '/api/0.1/resources/{}/group_permissions?{}'.format(
            node_id, qs)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        response = full_app.delete(url_path, status=200, headers=headers)
        perm_inst = GroupResourcePermissionService.get(group.id,
                                                       resource_id=node_id,
                                                       perm_name=perm_name,
                                                       db_session=sqla_session)
        assert not isinstance(perm_inst, GroupResourcePermission)
Пример #2
0
 def test_group_delete(self, full_app, sqla_session):
     with session_context(sqla_session) as session:
         admin, token = create_admin(session)
         group = create_group({"group_name": "testX"}, sqla_session=session)
     url_path = "/api/0.1/groups/{}".format(group.id)
     headers = {str("x-testscaffold-auth-token"): str(token)}
     full_app.delete_json(url_path, status=200, headers=headers)
Пример #3
0
    def test_group_create_no_json(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = '/api/0.1/groups'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        full_app.post_json(url_path, status=422, headers=headers)
Пример #4
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]
Пример #5
0
    def test_root_entry_no_parent_middle(self, full_app, sqla_session):
        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': 2
        }
        response = full_app.post_json(url_path, entry_dict, status=200,
                                      headers=headers)
        from testscaffold.services.resource_tree_service import tree_service
        result = tree_service.from_parent_deeper(
            None, 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'] == 2
        new_id = response.json['resource_id']
        assert [i for i in tree_struct.keys()] == [-1, new_id, -2, -3]
Пример #6
0
    def test_entries_list(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            for x in range(1, 51):
                create_entry(
                    {
                        'resource_name': 'entry-x{}'.format(x),
                        'note': 'x{}'.format(x)
                    },
                    sqla_session=session)
                create_entry(
                    {
                        'resource_name': 'entry-y{}'.format(x),
                        'note': 'y{}'.format(x)
                    },
                    sqla_session=session)

        url_path = '/api/0.1/entries'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        response = full_app.get(url_path, status=200, headers=headers)
        items = response.json

        assert len(items) == 50
        assert items[0]['resource_name'] == 'entry-x1'
        assert items[49]['resource_name'] == 'entry-y25'
        assert response.headers['x-pages'] == '2'
        assert response.headers['x-current-page'] == '1'
        assert response.headers['x-total-count'] == '100'
Пример #7
0
    def test_user_delete(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group(
                {"group_name": "test"},
                permissions=["root_administration", "admin_panel"],
                sqla_session=session,
            )
            user_a = create_user(
                {"user_name": "aaaa", "email": "foo"}, sqla_session=session
            )
            user_b = create_user(
                {"user_name": "bbbb", "email": "foo2"}, sqla_session=session
            )
            group.users.append(user_a)
            group.users.append(user_b)

        url_path = "/api/0.1/groups/{}/users".format(group.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        qs = parse.urlencode({"user_name": user_b.user_name})

        assert len(group.users) == 2
        full_app.delete("{}?{}".format(url_path, qs), status=200, headers=headers)
        sqla_session.expire_all()
        assert group.users[0].id == user_a.id
Пример #8
0
    def test_user_permission_add_proper(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            user = create_user({
                'user_name': 'aaaa',
                'email': 'foo'
            },
                               sqla_session=session)
            resource = create_entry({
                'resource_name': 'entry-x',
                'note': 'x'
            },
                                    sqla_session=session)

        node_id = resource.resource_id
        url_path = '/api/0.1/resources/{}/user_permissions'.format(node_id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        perm_name = 'edit'
        perm_dict = {'user_name': user.user_name, 'perm_name': perm_name}
        response = full_app.post_json(url_path,
                                      perm_dict,
                                      status=200,
                                      headers=headers)
        assert response.json['user_id'] == user.id
        assert response.json['perm_name'] == perm_name
        assert response.json['resource_id'] == node_id
        perm_inst = UserResourcePermissionService.get(user.id,
                                                      resource_id=node_id,
                                                      perm_name=perm_name,
                                                      db_session=sqla_session)
        assert isinstance(perm_inst, UserResourcePermission)
Пример #9
0
 def test_group_delete(self, full_app, sqla_session):
     with session_context(sqla_session) as session:
         admin, token = create_admin(session)
         group = create_group({'group_name': 'testX'}, sqla_session=session)
     url_path = '/api/0.1/groups/{}'.format(group.id)
     headers = {str('x-testscaffold-auth-token'): str(token)}
     full_app.delete_json(url_path, status=200, headers=headers)
Пример #10
0
    def test_group_create_no_json(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = "/api/0.1/groups"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        full_app.post_json(url_path, status=422, headers=headers)
Пример #11
0
 def test_entry_delete(self, full_app, sqla_session):
     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)
Пример #12
0
    def test_entry_create_bad_json(self, full_app, sqla_session,
                                   test_input, error_keys):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = '/api/0.1/entries'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        response = full_app.post_json(url_path, test_input, status=422,
                                      headers=headers)
        assert sorted(error_keys) == sorted(response.json.keys())
Пример #13
0
    def test_entry_create_bad_json(
        self, full_app, sqla_session, test_input, error_keys
    ):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = "/api/0.1/entries"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        response = full_app.post_json(url_path, test_input, status=422, headers=headers)
        assert sorted(error_keys) == sorted(response.json.keys())
Пример #14
0
    def test_group_create_bad_json(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = "/api/0.1/groups"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        group_dict = {"xxx": "yyy"}
        response = full_app.post_json(url_path, group_dict, status=422, headers=headers)
        required = ["group_name"]
        assert sorted(required) == sorted(response.json.keys())
Пример #15
0
 def test_user_delete(self, full_app, sqla_session):
     with session_context(sqla_session) as session:
         admin, token = create_admin(session)
         user = create_user(
             {"user_name": "testX", "email": "*****@*****.**"},
             sqla_session=session,
         )
     url_path = "/api/0.1/users/{}".format(user.id)
     headers = {str("x-testscaffold-auth-token"): str(token)}
     full_app.delete_json(url_path, status=200, headers=headers)
Пример #16
0
    def test_group_create_bad_json(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = '/api/0.1/groups'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        group_dict = {'xxx': 'yyy'}
        response = full_app.post_json(url_path, group_dict, status=422,
                                      headers=headers)
        required = ['group_name']
        assert sorted(required) == sorted(response.json.keys())
Пример #17
0
    def test_user_delete_not_found(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group(
                {'group_name': 'test'},
                permissions=['root_administration', 'admin_panel'],
                sqla_session=session)

        url_path = '/api/0.1/groups/{}/users'.format(group.id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        full_app.delete(url_path, status=404, headers=headers)
Пример #18
0
    def test_permission_delete_not_found(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            user = create_user(
                {"user_name": "testX", "email": "*****@*****.**"},
                sqla_session=session,
            )

        url_path = "/api/0.1/users/{}/permissions".format(user.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        permission = {"perm_name": "c"}
        full_app.delete(url_path, permission, status=404, headers=headers)
Пример #19
0
 def test_user_delete(self, full_app, sqla_session):
     with session_context(sqla_session) as session:
         admin, token = create_admin(session)
         user = create_user(
             {
                 'user_name': 'testX',
                 'email': '*****@*****.**'
             },
             sqla_session=session)
     url_path = '/api/0.1/users/{}'.format(user.id)
     headers = {str('x-testscaffold-auth-token'): str(token)}
     full_app.delete_json(url_path, status=200, headers=headers)
Пример #20
0
    def test_permission_add(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group({"group_name": "test"}, sqla_session=session)

        url_path = "/api/0.1/groups/{}/permissions".format(group.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        permission = {"perm_name": "root_administration"}
        assert not list(group.permissions)
        full_app.post_json(url_path, permission, status=200, headers=headers)
        sqla_session.expire_all()
        assert group.permissions[0].perm_name == "root_administration"
Пример #21
0
    def test_user_delete_not_found(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group(
                {"group_name": "test"},
                permissions=["root_administration", "admin_panel"],
                sqla_session=session,
            )

        url_path = "/api/0.1/groups/{}/users".format(group.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        full_app.delete(url_path, status=404, headers=headers)
Пример #22
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
Пример #23
0
    def test_users_list(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_user(
                {"user_name": "test2", "email": "[email protected]"},
                sqla_session=session,
            )

        url_path = "/api/0.1/users"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        response = full_app.get(url_path, status=200, headers=headers)
        items = response.json
        assert len(items) == 2
Пример #24
0
    def test_groups_list(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_group({'group_name': 'test', 'description': 'foo'},
                         sqla_session=session)
            create_group({'group_name': 'test2', 'description': 'foo2'},
                         sqla_session=session)

        url_path = '/api/0.1/groups'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        response = full_app.get(url_path, status=200, headers=headers)
        items = response.json
        assert len(items) == 2
Пример #25
0
    def test_users_list(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_user({
                'user_name': 'test2',
                'email': '[email protected]'
            },
                        sqla_session=session)

        url_path = '/api/0.1/users'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        response = full_app.get(url_path, status=200, headers=headers)
        items = response.json
        assert len(items) == 2
Пример #26
0
    def test_user_duplicate(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = "/api/0.1/users"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        user_dict = {
            "id": -9999,
            "user_name": "test",
            "password": "******",
            "email": "*****@*****.**",
        }
        response = full_app.post_json(url_path, user_dict, status=422, headers=headers)
        assert response.json["user_name"]
Пример #27
0
    def test_permission_add(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group({'group_name': 'test'}, sqla_session=session)

        url_path = '/api/0.1/groups/{}/permissions'.format(group.id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        permission = {
            'perm_name': 'root_administration',
        }
        assert not list(group.permissions)
        full_app.post_json(url_path, permission, status=200, headers=headers)
        sqla_session.expire_all()
        assert group.permissions[0].perm_name == 'root_administration'
Пример #28
0
    def test_group_create(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = "/api/0.1/groups"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        group_dict = {
            "id": -9999,
            "group_name": "some-new_group",
            "description": "description",
        }
        response = full_app.post_json(url_path, group_dict, status=200, headers=headers)
        assert response.json["id"] > 0
        assert group_dict["group_name"] == response.json["group_name"]
        assert group_dict["description"] == response.json["description"]
Пример #29
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]
Пример #30
0
    def test_groups_list(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_group(
                {"group_name": "test", "description": "foo"}, sqla_session=session
            )
            create_group(
                {"group_name": "test2", "description": "foo2"}, sqla_session=session
            )

        url_path = "/api/0.1/groups"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        response = full_app.get(url_path, status=200, headers=headers)
        items = response.json
        assert len(items) == 2
Пример #31
0
    def test_group_create(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = '/api/0.1/groups'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        group_dict = {
            'id': -9999,
            'group_name': 'some-new_group',
            'description': 'description'
        }
        response = full_app.post_json(url_path, group_dict, status=200,
                                      headers=headers)
        assert response.json['id'] > 0
        assert group_dict['group_name'] == response.json['group_name']
        assert group_dict['description'] == response.json['description']
Пример #32
0
    def test_permission_delete(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group(
                {"group_name": "test"},
                permissions=["root_administration", "admin_panel"],
                sqla_session=session,
            )

        url_path = "/api/0.1/groups/{}/permissions".format(group.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        permission = {"perm_name": "root_administration"}
        qs = parse.urlencode(permission)
        full_app.delete("{}?{}".format(url_path, qs), status=200, headers=headers)
        sqla_session.expire_all()
        assert group.permissions[0].perm_name == "admin_panel"
Пример #33
0
    def test_entry_patch(self, full_app, sqla_session):
        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)}
        entry_dict = {"resource_id": -9, "resource_name": "CHANGED", "note": "CHANGED"}
        response = full_app.patch_json(
            url_path, entry_dict, status=200, headers=headers
        )
        assert response.json["resource_id"] == entry.resource_id
        assert entry_dict["resource_name"] == response.json["resource_name"]
        assert entry_dict["note"] == response.json["note"]
Пример #34
0
    def test_permission_delete_not_found(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            user = create_user(
                {
                    'user_name': 'testX',
                    'email': '*****@*****.**'
                },
                sqla_session=session)

        url_path = '/api/0.1/users/{}/permissions'.format(user.id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        permission = {
            'perm_name': 'c',
        }
        full_app.delete(url_path, permission, status=404, headers=headers)
Пример #35
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
Пример #36
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
Пример #37
0
    def test_user_duplicate(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = '/api/0.1/users'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        user_dict = {
            'id': -9999,
            'user_name': 'test',
            'password': '******',
            'email': '*****@*****.**'
        }
        response = full_app.post_json(url_path,
                                      user_dict,
                                      status=422,
                                      headers=headers)
        assert response.json['user_name']
Пример #38
0
    def test_root_entry_no_parent_wrong_order(
        self, full_app, sqla_session, ordering, expected
    ):
        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": ordering,
        }
        response = full_app.post_json(url_path, entry_dict, status=422, headers=headers)
        assert expected in response.json["ordering"][0]
Пример #39
0
    def test_root_entry_no_parent_wrong_order(
            self, full_app, sqla_session, ordering, expected):
        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': ordering
        }
        response = full_app.post_json(url_path, entry_dict, status=422,
                                      headers=headers)
        assert expected in response.json['_schema'][0]
Пример #40
0
    def test_permission_delete(self, full_app, sqla_session):
        from ziggurat_foundations.models.services.user import UserService
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            user = create_user(
                {"user_name": "testX", "email": "*****@*****.**"},
                permissions=["root_administration", "admin_panel"],
                sqla_session=session,
            )

        url_path = "/api/0.1/users/{}/permissions".format(user.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        permission = {"perm_name": "root_administration"}
        qs = parse.urlencode(permission)
        full_app.delete("{}?{}".format(url_path, qs), status=200, headers=headers)
        sqla_session.expire_all()
        permissions = UserService.permissions(user)
        assert permissions[0].perm_name == "admin_panel"
Пример #41
0
    def test_permission_delete(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group(
                {'group_name': 'test'},
                permissions=['root_administration', 'admin_panel'],
                sqla_session=session)

        url_path = '/api/0.1/groups/{}/permissions'.format(group.id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        permission = {
            'perm_name': 'root_administration',
        }
        qs = parse.urlencode(permission)
        full_app.delete('{}?{}'.format(url_path, qs),
                        status=200, headers=headers)
        sqla_session.expire_all()
        assert group.permissions[0].perm_name == 'admin_panel'
Пример #42
0
    def test_entry_create(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(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": 1,
        }
        response = full_app.post_json(url_path, entry_dict, status=200, headers=headers)
        assert response.json["owner_user_id"] == admin.id
        assert response.json["resource_id"] > 0
        assert response.json["ordering"] == 1
        assert entry_dict["resource_name"] == response.json["resource_name"]
        assert entry_dict["note"] == response.json["note"]
Пример #43
0
    def test_group_permission_wrong_resource(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group({'group_name': 'aaaa'}, sqla_session=session)
            resource = create_entry({
                'resource_name': 'entry-x',
                'note': 'x'
            },
                                    sqla_session=session)

        node_id = resource.resource_id
        url_path = '/api/0.1/resources/{}/group_permissions'.format(-55)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        perm_dict = {'group_id': group.id, 'perm_name': 'blabla'}
        response = full_app.post_json(url_path,
                                      perm_dict,
                                      status=404,
                                      headers=headers)
Пример #44
0
    def test_group_permission_remove_wrong(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group({'group_name': 'aaaa'}, sqla_session=session)
            resource = create_entry({
                'resource_name': 'entry-x',
                'note': 'x'
            },
                                    sqla_session=session)

        node_id = resource.resource_id
        qs = parse.urlencode({'user_id': -99, 'perm_name': 'BLABLA'})
        url_path = '/api/0.1/resources/{}/group_permissions?{}'.format(
            node_id, qs)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        response = full_app.delete(url_path, status=422, headers=headers)
        assert 'perm_name' in response.json
        assert 'group_id' in response.json
Пример #45
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]
Пример #46
0
    def test_entry_patch_order_same_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(-2)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        entry_dict = {'ordering': 3}
        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'] == 3
        assert [i for i in tree_struct.keys()] == [-1, -3, -2]
        assert [i['node'].ordering for i in tree_struct.values()] == [1, 2, 3]
Пример #47
0
    def test_user_patch(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            user = create_user(
                {"user_name": "testX", "email": "*****@*****.**"},
                sqla_session=session,
            )

        url_path = "/api/0.1/users/{}".format(user.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        user_dict = {
            "id": -9,
            "user_name": "some-new_userCHANGED",
            "email": "*****@*****.**",
        }
        response = full_app.patch_json(url_path, user_dict, status=200, headers=headers)
        assert response.json["id"] == user.id
        assert user_dict["user_name"] == response.json["user_name"]
        assert user_dict["email"] == response.json["email"]
Пример #48
0
    def test_user_create(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = "/api/0.1/users"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        user_dict = {
            "id": -9999,
            "user_name": "some-new_user",
            "password": "******",
            "email": "*****@*****.**",
        }
        response = full_app.post_json(url_path, user_dict, status=200, headers=headers)
        assert response.json["id"] > 0
        assert user_dict["user_name"] == response.json["user_name"]
        assert user_dict["email"] == response.json["email"]
        assert "last_login_date" in response.json
        assert "registered_date" in response.json
        assert response.json["status"] == 1
Пример #49
0
    def test_entry_patch(self, full_app, sqla_session):
        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)}
        entry_dict = {
            'resource_id': -9,
            'resource_name': 'CHANGED',
            'note': 'CHANGED'
        }
        response = full_app.patch_json(url_path, entry_dict, status=200,
                                       headers=headers)
        assert response.json['resource_id'] == entry.resource_id
        assert entry_dict['resource_name'] == response.json['resource_name']
        assert entry_dict['note'] == response.json['note']
Пример #50
0
    def test_entry_create(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(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': 1
        }
        response = full_app.post_json(url_path, entry_dict, status=200,
                                      headers=headers)
        assert response.json['owner_user_id'] == admin.id
        assert response.json['resource_id'] > 0
        assert response.json['ordering'] == 1
        assert entry_dict['resource_name'] == response.json['resource_name']
        assert entry_dict['note'] == response.json['note']
Пример #51
0
    def test_group_patch(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group(
                {'group_name': 'testX', 'description': 'testX'},
                sqla_session=session)

        url_path = '/api/0.1/groups/{}'.format(group.id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        group_dict = {
            'id': -9,
            'group_name': 'some-new_groupCHANGED',
            'description': 'changed'
        }
        response = full_app.patch_json(url_path, group_dict, status=200,
                                       headers=headers)
        assert response.json['id'] == group.id
        assert group_dict['group_name'] == response.json['group_name']
        assert group_dict['description'] == response.json['description']
Пример #52
0
    def test_user_add(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group({'group_name': 'test'},
                                 sqla_session=session)
            user_a = create_user({'user_name': 'aaaa', 'email': 'foo'},
                                 sqla_session=session)
            user_b = create_user({'user_name': 'bbbb', 'email': 'foo2'},
                                 sqla_session=session)

        url_path = '/api/0.1/groups/{}/users'.format(group.id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        assert not list(group.users)
        full_app.post_json(url_path, {'user_name': user_a.user_name},
                           status=200, headers=headers)
        full_app.post_json(url_path, {'user_name': user_b.user_name},
                           status=200, headers=headers)
        sqla_session.expire_all()
        assert len(group.users) == 2
Пример #53
0
    def test_users_filtering(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            create_user(
                {"user_name": "test2", "email": "[email protected]"},
                sqla_session=session,
            )
            create_user(
                {"user_name": "foo", "email": "[email protected]"}, sqla_session=session
            )
            create_user(
                {"user_name": "barbaz", "email": "[email protected]"},
                sqla_session=session,
            )

        url_path = "/api/0.1/users?user_name_like=bar"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        response = full_app.get(url_path, status=200, headers=headers)
        items = response.json
        assert items[0]["user_name"] == "barbaz"
Пример #54
0
    def test_permission_add(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            user = create_user(
                {
                    'user_name': 'testX',
                    'email': '*****@*****.**'
                },
                sqla_session=session)

        url_path = '/api/0.1/users/{}/permissions'.format(user.id)
        headers = {str('x-testscaffold-auth-token'): str(token)}
        permission = {
            'perm_name': 'root_administration',
        }
        assert not list(user.permissions)
        full_app.post_json(url_path, permission, status=200, headers=headers)
        sqla_session.expire_all()
        print(user.permissions)
        assert user.permissions[0].perm_name == 'root_administration'
Пример #55
0
    def test_group_patch(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group(
                {"group_name": "testX", "description": "testX"}, sqla_session=session
            )

        url_path = "/api/0.1/groups/{}".format(group.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        group_dict = {
            "id": -9,
            "group_name": "some-new_groupCHANGED",
            "description": "changed",
        }
        response = full_app.patch_json(
            url_path, group_dict, status=200, headers=headers
        )
        assert response.json["id"] == group.id
        assert group_dict["group_name"] == response.json["group_name"]
        assert group_dict["description"] == response.json["description"]
Пример #56
0
    def test_entry_patch_order_upper_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, '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'] == 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, 5]
Пример #57
0
    def test_user_create(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)

        url_path = '/api/0.1/users'
        headers = {str('x-testscaffold-auth-token'): str(token)}
        user_dict = {
            'id': -9999,
            'user_name': 'some-new_user',
            'password': '******',
            'email': '*****@*****.**'
        }
        response = full_app.post_json(url_path,
                                      user_dict,
                                      status=200,
                                      headers=headers)
        assert response.json['id'] > 0
        assert user_dict['user_name'] == response.json['user_name']
        assert user_dict['email'] == response.json['email']
        assert 'last_login_date' in response.json
        assert 'registered_date' in response.json
        assert response.json['status'] == 1
Пример #58
0
    def test_user_add(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            group = create_group({"group_name": "test"}, sqla_session=session)
            user_a = create_user(
                {"user_name": "aaaa", "email": "foo"}, sqla_session=session
            )
            user_b = create_user(
                {"user_name": "bbbb", "email": "foo2"}, sqla_session=session
            )

        url_path = "/api/0.1/groups/{}/users".format(group.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        assert not list(group.users)
        full_app.post_json(
            url_path, {"user_name": user_a.user_name}, status=200, headers=headers
        )
        full_app.post_json(
            url_path, {"user_name": user_b.user_name}, status=200, headers=headers
        )
        sqla_session.expire_all()
        assert len(group.users) == 2
Пример #59
0
    def test_entries_list(self, full_app, sqla_session):
        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            for x in range(1, 51):
                create_entry(
                    {"resource_name": "entry-x{}".format(x), "note": "x{}".format(x)},
                    sqla_session=session,
                )
                create_entry(
                    {"resource_name": "entry-y{}".format(x), "note": "y{}".format(x)},
                    sqla_session=session,
                )

        url_path = "/api/0.1/entries"
        headers = {str("x-testscaffold-auth-token"): str(token)}
        response = full_app.get(url_path, status=200, headers=headers)
        items = response.json

        assert len(items) == 50
        assert items[0]["resource_name"] == "entry-x1"
        assert items[49]["resource_name"] == "entry-y25"
        assert response.headers["x-pages"] == "2"
        assert response.headers["x-current-page"] == "1"
        assert response.headers["x-total-count"] == "100"
Пример #60
0
    def test_cleanup(self, sqla_session):
        from testscaffold.models.user import User

        with session_context(sqla_session) as session:
            user = User(id=1, email="foasfsfao", user_name="barafsf")
            user.persist(flush=True, db_session=session)