예제 #1
0
    def test__put_user_config_endpoint__error__400__invalid_format(
            self, user_api_factory: UserApiFactory, web_testapp: TestApp,
            user_config: typing.Dict):
        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )

        transaction.commit()

        user_id = test_user.user_id
        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        response = web_testapp.put_json(
            "/api/users/{user_id}/config".format(user_id=user_id),
            params={
                "parameters": user_config
            },
            status=400,
        ).json_body
        assert response["code"] == ErrorCode.GENERIC_SCHEMA_VALIDATION_ERROR
        assert response["message"] == "Validation error of input data"
예제 #2
0
    def test__subscribe_workspace__err__400__not_a_on_request_workspace(
        self,
        user_api_factory: UserApiFactory,
        workspace_api_factory: WorkspaceApiFactory,
        web_testapp: TestApp,
        subscription_lib_factory: SubscriptionLibFactory,
        admin_user: User,
    ):
        open_workspace = workspace_api_factory.get().create_workspace(
            "open", access_type=WorkspaceAccessType.OPEN, save_now=True)
        on_request_workspace = workspace_api_factory.get().create_workspace(
            "on_request",
            access_type=WorkspaceAccessType.ON_REQUEST,
            save_now=True)
        confidential_workspace = workspace_api_factory.get().create_workspace(
            "confidential",
            access_type=WorkspaceAccessType.CONFIDENTIAL,
            save_now=True)

        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )
        transaction.commit()
        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        params = {"workspace_id": on_request_workspace.workspace_id}
        res = web_testapp.put_json(
            "/api/users/{}/workspace_subscriptions".format(test_user.user_id),
            status=200,
            params=params,
        )
        params = {"workspace_id": open_workspace.workspace_id}
        res = web_testapp.put_json(
            "/api/users/{}/workspace_subscriptions".format(test_user.user_id),
            status=400,
            params=params,
        )
        assert res.json_body["code"] == ErrorCode.INVALID_WORKSPACE_ACCESS_TYPE
        params = {"workspace_id": confidential_workspace.workspace_id}
        res = web_testapp.put_json(
            "/api/users/{}/workspace_subscriptions".format(test_user.user_id),
            status=400,
            params=params,
        )
        assert res.json_body["code"] == ErrorCode.INVALID_WORKSPACE_ACCESS_TYPE
예제 #3
0
    def test__put_user_config_endpoint_with_update(
            self, user_api_factory: UserApiFactory, web_testapp: TestApp):
        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )

        transaction.commit()

        fixture_params1 = {"param1": 1, "param2": "two"}
        fixture_params2 = {"param2": 2, "param3": "hello"}
        expected_result = {"param1": 1, "param2": 2, "param3": "hello"}

        user_id = test_user.user_id
        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        web_testapp.put_json(
            "/api/users/{user_id}/config".format(user_id=user_id),
            params={"parameters": fixture_params1},
            status=204,
        )

        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        res = web_testapp.get(
            "/api/users/{user_id}/config".format(user_id=user_id), status=200)

        assert json.loads(res.body,
                          encoding="utf-8")["parameters"] == fixture_params1

        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        web_testapp.put_json(
            "/api/users/{user_id}/config".format(user_id=user_id),
            params={"parameters": fixture_params2},
            status=204,
        )

        transaction.commit()

        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        res = web_testapp.get(
            "/api/users/{user_id}/config".format(user_id=user_id), status=200)

        assert json.loads(res.body,
                          encoding="utf-8")["parameters"] == expected_result
예제 #4
0
    def test__get_workspace_subscription__ok__200__nominal_case(
        self,
        user_api_factory: UserApiFactory,
        workspace_api_factory: WorkspaceApiFactory,
        web_testapp: TestApp,
        subscription_lib_factory: SubscriptionLibFactory,
        admin_user: User,
    ):
        on_request_workspace = workspace_api_factory.get().create_workspace(
            "on_request",
            access_type=WorkspaceAccessType.ON_REQUEST,
            save_now=True)

        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )
        subscription_lib_factory.get(test_user).submit_subscription(
            workspace=on_request_workspace)
        transaction.commit()
        web_testapp.authorization = ("Basic", ("*****@*****.**",
                                               "*****@*****.**"))
        res = web_testapp.get("/api/workspaces/{}/subscriptions".format(
            on_request_workspace.workspace_id),
                              status=200)
        assert len(res.json_body) == 1
        first_subscription = res.json_body[0]
        assert first_subscription[
            "state"] == WorkspaceSubscriptionState.PENDING.value
        assert first_subscription["workspace"][
            "workspace_id"] == on_request_workspace.workspace_id
        assert first_subscription["author"]["user_id"] == test_user.user_id
        assert first_subscription["created_date"]
        assert first_subscription["evaluation_date"] is None
        assert first_subscription["evaluator"] is None
예제 #5
0
    def test__accept_workspace_subscription__err__400__already_in(
        self,
        user_api_factory: UserApiFactory,
        workspace_api_factory: WorkspaceApiFactory,
        web_testapp: TestApp,
        subscription_lib_factory: SubscriptionLibFactory,
        role_api_factory: RoleApiFactory,
        admin_user: User,
    ):
        on_request_workspace = workspace_api_factory.get().create_workspace(
            "on_request",
            access_type=WorkspaceAccessType.ON_REQUEST,
            save_now=True)

        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )
        rapi = role_api_factory.get()
        rapi.create_one(test_user, on_request_workspace,
                        UserRoleInWorkspace.READER, False)
        subscription_lib_factory.get(test_user).submit_subscription(
            workspace=on_request_workspace)
        transaction.commit()
        params = {"role": "contributor"}
        web_testapp.authorization = ("Basic", ("*****@*****.**",
                                               "*****@*****.**"))
        res = web_testapp.put_json(
            "/api/workspaces/{}/subscriptions/{}/accept".format(
                on_request_workspace.workspace_id, test_user.user_id),
            status=400,
            params=params,
        )
        assert res.json_body["code"] == ErrorCode.USER_ROLE_ALREADY_EXIST
예제 #6
0
    def test__accept_workspace_subscription__ok__200__nominal_case(
        self,
        user_api_factory: UserApiFactory,
        workspace_api_factory: WorkspaceApiFactory,
        web_testapp: TestApp,
        subscription_lib_factory: SubscriptionLibFactory,
        admin_user: User,
    ):
        on_request_workspace = workspace_api_factory.get().create_workspace(
            "on_request",
            access_type=WorkspaceAccessType.ON_REQUEST,
            save_now=True)

        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )
        subscription_lib_factory.get(test_user).submit_subscription(
            workspace=on_request_workspace)
        transaction.commit()
        params = {"role": "contributor"}
        web_testapp.authorization = ("Basic", ("*****@*****.**",
                                               "*****@*****.**"))
        web_testapp.put_json(
            "/api/workspaces/{}/subscriptions/{}/accept".format(
                on_request_workspace.workspace_id, test_user.user_id),
            status=204,
            params=params,
        )
        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        web_testapp.get(
            "/api/workspaces/{}".format(on_request_workspace.workspace_id),
            status=200,
        )
예제 #7
0
    def test__get_user_config_endpoint_new_user(
            self, user_api_factory: UserApiFactory, web_testapp: TestApp):
        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )
        transaction.commit()
        user_id = test_user.user_id
        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))
        res = web_testapp.get(
            "/api/users/{user_id}/config".format(user_id=user_id), status=200)

        assert json.loads(res.body, encoding="utf-8")["parameters"] == {}
예제 #8
0
파일: test_event.py 프로젝트: inkhey/tracim
    def test_unit__get_receiver_ids_workspace_subscription_event__reject_subscription(
        self,
        session: TracimSession,
        user_api_factory: UserApiFactory,
        subscription_lib_factory: SubscriptionLibFactory,
        admin_user: User,
        workspace_api_factory: WorkspaceApiFactory,
        role_api_factory: RoleApiFactory,
    ):
        user_api = user_api_factory.get()
        profile = Profile.USER
        subscriber = user_api.create_user(
            "*****@*****.**",
            password="******",
            do_save=True,
            do_notify=False,
            profile=profile,
        )
        workspace_content_manager = user_api.create_user(
            "*****@*****.**",
            password="******",
            do_save=True,
            do_notify=False,
            profile=profile,
        )
        workspace_manager = user_api.create_user(
            "*****@*****.**",
            password="******",
            do_save=True,
            do_notify=False,
            profile=profile,
        )
        other_user = user_api.create_user(
            "*****@*****.**",
            password="******",
            do_save=True,
            do_notify=False,
            profile=profile,
        )
        workspace_api = workspace_api_factory.get(current_user=admin_user)
        my_workspace = workspace_api.create_workspace(
            "test workspace", save_now=True, access_type=WorkspaceAccessType.ON_REQUEST
        )
        workspace_in_context = workspace_api.get_workspace_with_context(my_workspace)
        subscription_lib = subscription_lib_factory.get(current_user=subscriber)
        rapi = role_api_factory.get(current_user=subscriber)
        rapi.create_one(
            workspace_content_manager, my_workspace, UserRoleInWorkspace.CONTENT_MANAGER, False
        )
        rapi.create_one(
            workspace_manager, my_workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False
        )
        subscription = subscription_lib.submit_subscription(my_workspace)
        subscription_lib.reject_subscription(subscription)
        transaction.commit()
        fields = {
            Event.AUTHOR_FIELD: UserSchema().dump(user_api.get_user_with_context(admin_user)).data,
            Event.WORKSPACE_FIELD: WorkspaceSchema().dump(workspace_in_context).data,
            Event.SUBSCRIPTION_FIELD: WorkspaceSubscriptionSchema().dump(subscription).data,
        }
        event = Event(
            entity_type=EntityType.WORKSPACE_SUBSCRIPTION,
            operation=OperationType.MODIFIED,
            fields=fields,
        )

        receivers_ids = FakeLiveMessageBuilder()._get_receiver_ids(event, session)
        assert subscriber.user_id in receivers_ids
        assert workspace_manager.user_id in receivers_ids
        assert admin_user.user_id in receivers_ids
        assert workspace_content_manager.user_id not in receivers_ids
        assert other_user.user_id not in receivers_ids
예제 #9
0
    def test__subscribe_workspace__ok__200__resubscribe_to_rejected_subscription(
        self,
        user_api_factory: UserApiFactory,
        workspace_api_factory: WorkspaceApiFactory,
        web_testapp: TestApp,
        subscription_lib_factory: SubscriptionLibFactory,
        admin_user: User,
        event_helper: EventHelper,
    ):
        on_request_workspace = workspace_api_factory.get().create_workspace(
            "on_request",
            access_type=WorkspaceAccessType.ON_REQUEST,
            save_now=True)
        uapi = user_api_factory.get()
        profile = Profile.USER
        test_user = uapi.create_user(
            email="*****@*****.**",
            password="******",
            name="bob",
            profile=profile,
            timezone="Europe/Paris",
            lang="fr",
            do_save=True,
            do_notify=False,
        )
        subscription = subscription_lib_factory.get(
            test_user).submit_subscription(workspace=on_request_workspace)
        subscription_lib_factory.get().reject_subscription(subscription)
        transaction.commit()
        web_testapp.authorization = ("Basic", ("*****@*****.**", "password"))

        res = web_testapp.get("/api/users/{}/workspace_subscriptions".format(
            test_user.user_id),
                              status=200)
        assert len(res.json_body) == 1
        subscription = res.json_body[0]
        assert subscription[
            "state"] == WorkspaceSubscriptionState.REJECTED.value
        assert subscription["workspace"][
            "workspace_id"] == on_request_workspace.workspace_id
        assert subscription["author"]["user_id"] == test_user.user_id
        assert subscription["created_date"]
        assert subscription["evaluation_date"]
        assert subscription["evaluator"]["user_id"] == admin_user.user_id

        # resubscribe rejected subscription
        params = {"workspace_id": on_request_workspace.workspace_id}
        res = web_testapp.put_json(
            "/api/users/{}/workspace_subscriptions".format(test_user.user_id),
            status=200,
            params=params,
        )
        subscription = res.json_body
        assert subscription[
            "state"] == WorkspaceSubscriptionState.PENDING.value
        assert subscription["workspace"][
            "workspace_id"] == on_request_workspace.workspace_id
        assert subscription["author"]["user_id"] == test_user.user_id
        assert subscription["created_date"]
        assert subscription["evaluation_date"] is None
        assert subscription["evaluator"] is None

        last_event = event_helper.last_event
        assert last_event.event_type == "workspace_subscription.modified"
        author = web_testapp.get("/api/users/{}".format(test_user.user_id),
                                 status=200).json_body
        assert last_event.author == author
        web_testapp.authorization = ("Basic", ("*****@*****.**",
                                               "*****@*****.**"))
        workspace = web_testapp.get("/api/workspaces/{}".format(
            on_request_workspace.workspace_id),
                                    status=200).json_body
        assert last_event.workspace == workspace
        assert last_event.subscription["state"] == subscription["state"]
        assert last_event.subscription["workspace"] == subscription[
            "workspace"]
        assert last_event.subscription["author"] == subscription["author"]
        assert last_event.subscription["evaluator"] == subscription[
            "evaluator"]

        # after resubscribe
        res = web_testapp.get("/api/users/{}/workspace_subscriptions".format(
            test_user.user_id),
                              status=200)
        assert len(res.json_body) == 1
        subscription = res.json_body[0]
        assert subscription[
            "state"] == WorkspaceSubscriptionState.PENDING.value
        assert subscription["workspace"][
            "workspace_id"] == on_request_workspace.workspace_id
        assert subscription["author"]["user_id"] == test_user.user_id
        assert subscription["created_date"]
        assert subscription["evaluation_date"] is None
        assert subscription["evaluator"] is None

        last_event = event_helper.last_event
        assert last_event.event_type == "workspace_subscription.modified"
        author = web_testapp.get("/api/users/{}".format(test_user.user_id),
                                 status=200).json_body
        assert last_event.author == author
        web_testapp.authorization = ("Basic", ("*****@*****.**",
                                               "*****@*****.**"))
        workspace = web_testapp.get("/api/workspaces/{}".format(
            on_request_workspace.workspace_id),
                                    status=200).json_body
        assert last_event.workspace == workspace
        assert last_event.subscription["state"] == subscription["state"]
        assert last_event.subscription["workspace"] == subscription[
            "workspace"]
        assert last_event.subscription["author"] == subscription["author"]
        assert last_event.subscription["evaluator"] == subscription[
            "evaluator"]