From 01d8ffa8fbfce8479c2538e5973a2a738b6c2b0a Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Thu, 29 Aug 2024 09:02:19 +0200 Subject: [PATCH 1/2] communities --- oarepo_doi/actions/doi.py | 42 +++- oarepo_doi/services/components/__init__.py | 29 ++- run-tests.sh | 5 + setup.cfg | 2 +- tests/conftest.py | 228 ++++++++------------- tests/test_requests.py | 78 ++++--- tests/thesis.yaml | 19 +- 7 files changed, 216 insertions(+), 187 deletions(-) diff --git a/oarepo_doi/actions/doi.py b/oarepo_doi/actions/doi.py index 80e1faa..49d225a 100644 --- a/oarepo_doi/actions/doi.py +++ b/oarepo_doi/actions/doi.py @@ -1,6 +1,6 @@ from invenio_requests.customizations import actions from flask import current_app -from oarepo_doi.api import create_doi +from oarepo_doi.api import create_doi, edit_doi class CreateDoiAction(actions.CreateAction): log_event = True @@ -8,15 +8,29 @@ class CreateDoiAction(actions.CreateAction): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.username = current_app.config.get("DATACITE_USERNAME") - self.password = current_app.config.get("DATACITE_PASSWORD") + self.mode = current_app.config.get("DATACITE_MODE") self.url = current_app.config.get("DATACITE_URL") - self.prefix = current_app.config.get("DATACITE_PREFIX") self.mapping = current_app.config.get("DATACITE_MAPPING") + self.username = None + self.password = None + self.prefix = None + + def credentials(self, community): + credentials_def = current_app.config.get("DATACITE_CREDENTIALS") + + community_credentials = getattr(credentials_def, community, None) + if community_credentials is None and "DATACITE_CREDENTIALS_DEFAULT" in current_app.config: + community_credentials = current_app.config.get("DATACITE_CREDENTIALS_DEFAULT") + self.username = community_credentials["username"] + self.password = community_credentials["password"] + self.prefix = community_credentials["prefix"] + def execute(self, identity, uow, *args, **kwargs): topic = self.request.topic.resolve() + self.credentials(topic['parent']['communities']['default']) + if topic.is_draft: create_doi(self, topic, topic["metadata"], None) else: @@ -30,16 +44,28 @@ class EditDoiAction(actions.AcceptAction): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.username = current_app.config.get("DATACITE_USERNAME") - self.password = current_app.config.get("DATACITE_PASSWORD") + self.mode = current_app.config.get("DATACITE_MODE") self.url = current_app.config.get("DATACITE_URL") - self.prefix = current_app.config.get("DATACITE_PREFIX") self.mapping = current_app.config.get("DATACITE_MAPPING") + self.username = None + self.password = None + self.prefix = None + + def credentials(self, community): + credentials_def = current_app.config.get("DATACITE_CREDENTIALS") + + community_credentials = getattr(credentials_def, community, None) + if community_credentials is None and "DATACITE_CREDENTIALS_DEFAULT" in current_app.config: + community_credentials = current_app.config.get("DATACITE_CREDENTIALS_DEFAULT") + self.username = community_credentials["username"] + self.password = community_credentials["password"] + self.prefix = community_credentials["prefix"] + def execute(self, identity, uow, *args, **kwargs): topic = self.request.topic.resolve() - + self.credentials(topic['parent']['communities']['default']) if topic.is_draft: edit_doi(self, topic, None) else: diff --git a/oarepo_doi/services/components/__init__.py b/oarepo_doi/services/components/__init__.py index 3d56fd9..59a6d50 100644 --- a/oarepo_doi/services/components/__init__.py +++ b/oarepo_doi/services/components/__init__.py @@ -13,30 +13,45 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.mode = current_app.config.get("DATACITE_MODE") - - #this will be changed after oarepo-communities release - self.username = current_app.config.get("DATACITE_USERNAME") - self.password = current_app.config.get("DATACITE_PASSWORD") self.url = current_app.config.get("DATACITE_URL") - self.prefix = current_app.config.get("DATACITE_PREFIX") - # - self.mapping = current_app.config.get("DATACITE_MAPPING") + self.username = None + self.password = None + self.prefix = None + + + + def credentials(self, community): + credentials_def = current_app.config.get("DATACITE_CREDENTIALS") + + community_credentials = getattr(credentials_def, community, None) + if community_credentials is None and "DATACITE_CREDENTIALS_DEFAULT" in current_app.config: + community_credentials = current_app.config.get("DATACITE_CREDENTIALS_DEFAULT") + self.username = community_credentials["username"] + self.password = community_credentials["password"] + self.prefix = community_credentials["prefix"] + def create(self, identity, data=None, record=None, **kwargs): + if self.mode == "AUTOMATIC_DRAFT": + self.credentials(data['parent']['communities']['default']) create_doi(self, record,data, None) def update_draft(self, identity, data=None, record=None, **kwargs): if self.mode == "AUTOMATIC_DRAFT": + self.credentials(data['parent']['communities']['default']) edit_doi(self, record) def update(self, identity, data=None, record=None, **kwargs): if self.mode == "AUTOMATIC_DRAFT" or self.mode == "AUTOMATIC": + self.credentials(data['parent']['communities']['default']) edit_doi(self, record) def publish(self, identity, data=None, record=None, **kwargs): if self.mode == "AUTOMATIC": + self.credentials(data['parent']['communities']['default']) create_doi(self, record, data, "publish") if self.mode == "AUTOMATIC_DRAFT": + self.credentials(data['parent']['communities']['default']) edit_doi(self, record, "publish") diff --git a/run-tests.sh b/run-tests.sh index 5552f09..9683e07 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -24,6 +24,11 @@ fi if test -d $VENV_TESTS ; then rm -rf $VENV_TESTS fi +pip install -U oarepo-model-builder \ + oarepo-model-builder-tests \ + oarepo-model-builder-requests \ + oarepo-model-builder-drafts \ + oarepo-model-builder-workflows oarepo-compile-model ./tests/thesis.yaml --output-directory ./thesis -vvv python3 -m venv $VENV_TESTS diff --git a/setup.cfg b/setup.cfg index 38a9bd2..a8885e2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-doi -version = 1.0.1 +version = 1.0.2 description = authors = Alzbeta Pokorna readme = README.md diff --git a/tests/conftest.py b/tests/conftest.py index c3164ab..621575d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,21 +1,19 @@ +import copy import os import yaml import pytest -from flask_principal import Identity, Need, UserNeed -from flask_security.utils import hash_password, login_user -from invenio_access.models import ActionRoles -from invenio_access.permissions import superuser_access -from invenio_accounts.models import Role + +from flask_security.utils import login_user +from invenio_access.permissions import system_identity from invenio_accounts.testutils import login_user_via_session from invenio_app.factory import create_api from invenio_requests.customizations import CommentEventType, LogEventType -from invenio_requests.proxies import current_request_type_registry, current_requests -from invenio_requests.records.api import Request, RequestEventFormat from thesis.proxies import current_service -from thesis.records.api import ThesisRecord -# from thesis.proxies import current_service -# from thesis.records.api import ThesisRecord +from invenio_users_resources.records import UserAggregate +@pytest.fixture() +def default_workflow_json(): + return {"parent": {"workflow": "default"}} @pytest.fixture(scope="function") def sample_metadata_list(): @@ -52,161 +50,103 @@ def app_config(app_config): return app_config -@pytest.fixture(scope="module") -def identity_simple(): - """Simple identity fixture.""" - i = Identity(1) - i.provides.add(UserNeed(1)) - i.provides.add(Need(method="system_role", value="any_user")) - i.provides.add(Need(method="system_role", value="authenticated_user")) - return i - - -@pytest.fixture(scope="module") -def identity_simple_2(): - """Simple identity fixture.""" - i = Identity(2) - i.provides.add(UserNeed(2)) - i.provides.add(Need(method="system_role", value="any_user")) - i.provides.add(Need(method="system_role", value="authenticated_user")) - return i +class LoggedClient: + def __init__(self, client, user_fixture): + self.client = client + self.user_fixture = user_fixture + def _login(self): + login_user(self.user_fixture.user, remember=True) + login_user_via_session(self.client, email=self.user_fixture.email) -@pytest.fixture(scope="module") -def requests_service(app): - """Request Factory fixture.""" + def post(self, *args, **kwargs): + self._login() + return self.client.post(*args, **kwargs) - return current_requests.requests_service + def get(self, *args, **kwargs): + self._login() + return self.client.get(*args, **kwargs) + def put(self, *args, **kwargs): + self._login() + return self.client.put(*args, **kwargs) -@pytest.fixture(scope="module") -def request_events_service(app): - """Request Factory fixture.""" - service = current_requests.request_events_service - return service - + def delete(self, *args, **kwargs): + self._login() + return self.client.delete(*args, **kwargs) @pytest.fixture() -def create_request(requests_service): - """Request Factory fixture.""" - - def _create_request(identity, input_data, receiver, request_type, **kwargs): - """Create a request.""" - # Need to use the service to get the id - item = requests_service.create( - identity, input_data, request_type=request_type, receiver=receiver, **kwargs - ) - return item._request - - return _create_request +def logged_client(client): + def _logged_client(user): + return LoggedClient(client, user) + return _logged_client @pytest.fixture() -def submit_request(create_request, requests_service, **kwargs): - """Opened Request Factory fixture.""" - - def _submit_request(identity, data, **kwargs): - """Create and submit a request.""" - request = create_request(identity, input_data=data, **kwargs) - id_ = request.id - return requests_service.execute_action(identity, id_, "submit", data)._request - - return _submit_request +def users(app, db, UserFixture): + user1 = UserFixture( + email="user1@example.org", + password="password", + active=True, + confirmed=True, + ) + user1.create(app, db) + user2 = UserFixture( + email="user2@example.org", + password="beetlesmasher", + active=True, + confirmed=True, + ) + user2.create(app, db) -@pytest.fixture(scope="module") -def users(app): - """Create example users.""" - # This is a convenient way to get a handle on db that, as opposed to the - # fixture, won't cause a DB rollback after the test is run in order - # to help with test performance (creating users is a module -if not higher- - # concern) - from invenio_db import db - - with db.session.begin_nested(): - datastore = app.extensions["security"].datastore - - su_role = Role(name="superuser-access") - db.session.add(su_role) - - su_action_role = ActionRoles.create(action=superuser_access, role=su_role) - db.session.add(su_action_role) - - user1 = datastore.create_user( - email="user1@example.org", password=hash_password("password"), active=True - ) - user2 = datastore.create_user( - email="user2@example.org", password=hash_password("password"), active=True - ) - admin = datastore.create_user( - email="admin@example.org", password=hash_password("password"), active=True - ) - admin.roles.append(su_role) + user3 = UserFixture( + email="user3@example.org", + password="beetlesmasher", + active=True, + confirmed=True, + ) + user3.create(app, db) db.session.commit() - return [user1, user2, admin] - + UserAggregate.index.refresh() + return [user1, user2, user3] @pytest.fixture() -def client_with_login(client, users): - """Log in a user to the client.""" - user = users[0] - login_user(user) - login_user_via_session(client, email=user.email) - return client - - -@pytest.fixture(scope="function") -def request_record_input_data(): - """Input data to a Request record.""" - ret = { - "title": "Doc1 approval", - "payload": { - "content": "Can you approve my document doc1 please?", - "format": RequestEventFormat.HTML.value, - }, - } - return ret - +def urls(): + return {"BASE_URL": "/thesis/", "BASE_URL_REQUESTS": "/requests/"} @pytest.fixture(scope="module") def record_service(): return current_service +@pytest.fixture() +def create_doi_data_function(): + def ret_data(record_id): + return { + "request_type": "create_doi", + "topic": {"thesis_draft": record_id}, + } -@pytest.fixture(scope="function") -def example_topic_draft(record_service, identity_simple): - draft = record_service.create(identity_simple, {}) - return draft._obj - - -@pytest.fixture(scope="function") -def example_topic(record_service, identity_simple): - draft = record_service.create(identity_simple, {}) - record = record_service.publish(identity_simple, draft.id) - id_ = record.id - record = ThesisRecord.pid.resolve(id_) - return record - - -@pytest.fixture(scope="module") -def identity_creator(identity_simple): # for readability - return identity_simple - - -@pytest.fixture(scope="module") -def identity_receiver(identity_simple_2): # for readability - return identity_simple_2 + return ret_data +@pytest.fixture() +def record_factory(record_service, default_workflow_json): + def record(identity, custom_workflow=None, additional_data=None): + json = copy.deepcopy(default_workflow_json) + if custom_workflow: # specifying this assumes use of workflows + json["parent"]["workflow"] = custom_workflow + json = { + "metadata": { + "title": "Title", + + }, + **json, + } + if additional_data: + json |= additional_data + draft = record_service.create(identity, json) + record = record_service.publish(system_identity, draft.id) + return record._obj -@pytest.fixture(scope="function") -def request_with_receiver_user( - requests_service, example_topic, identity_creator, users -): - receiver = users[1] - type_ = current_request_type_registry.lookup("generic_request", quiet=True) - request_item = requests_service.create( - identity_creator, {}, type_, receiver=receiver, topic=example_topic - ) - request = Request.get_record(request_item.id) - return request_item + return record \ No newline at end of file diff --git a/tests/test_requests.py b/tests/test_requests.py index 0399c0c..47a01f6 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1,6 +1,3 @@ -from invenio_access.permissions import system_identity -from invenio_base.utils import obj_or_import_string - def test_datacite_config(app): @@ -8,26 +5,61 @@ def test_datacite_config(app): assert "DATACITE_PREFIX" in app.config +def link_api2testclient(api_link): + base_string = "https://127.0.0.1:5000/api/" + return api_link[len(base_string) - 1 :] + + +def test_edit_autoaccept( + logged_client, + users, + urls, + create_doi_data_function, + record_factory, + search_clear, +): + creator = users[0] + creator_client = logged_client(creator) + + record1 = record_factory(creator.identity) + id_ = record1["id"] + + # test direct edit is forbidden + direct_edit = creator_client.post( + f"{urls['BASE_URL']}{id_}/draft", + ) + assert direct_edit.status_code == 403 + + resp_request_create = creator_client.post( + urls["BASE_URL_REQUESTS"], + json=create_doi_data_function(record1["id"]), + ) + resp_request_submit = creator_client.post( + link_api2testclient(resp_request_create.json["links"]["actions"]["submit"]), + ) + # is request accepted and closed? + request = creator_client.get( + f'{urls["BASE_URL_REQUESTS"]}{resp_request_create.json["id"]}', + ).json + + assert request["status"] == "accepted" + assert not request["is_open"] + assert request["is_closed"] + assert "draft_record:links:self" in request["payload"] + assert "draft_record:links:self_html" in request["payload"] + # ThesisRecord.index.refresh() + # ThesisDraft.index.refresh() + # edit action worked? + # search = creator_client.get( + # f'user{urls["BASE_URL"]}', + # ).json[ + # "hits" + # ]["hits"] + # assert len(search) == 1 + # assert search[0]["links"]["self"].endswith("/draft") + # assert search[0]["id"] == id_ + # + -# def test_request(app, client_with_login): -# with client_with_login.get(f"/thesis/") as c: -# assert c.status_code == 200 -# -# -# def test_create(app, db, record_service, sample_metadata_list, search_clear): -# created_records = [] -# for sample_metadata_point in sample_metadata_list: -# created_records.append( -# record_service.create(system_identity, sample_metadata_point) -# ) -# for sample_metadata_point, created_record in zip( -# sample_metadata_list, created_records -# ): -# created_record_reread = record_service.read( -# system_identity, created_record["id"] -# ) -# assert ( -# created_record_reread.data["metadata"] == sample_metadata_point["metadata"] -# ) diff --git a/tests/thesis.yaml b/tests/thesis.yaml index 449d29e..4292d00 100644 --- a/tests/thesis.yaml +++ b/tests/thesis.yaml @@ -1,12 +1,23 @@ record: use: - - invenio + - invenio module: qualified: thesis permissions: presets: [ 'everyone' ] + draft: {} properties: metadata: - properties: - title: - type: keyword \ No newline at end of file + properties: + title: + type: fulltext + creators[]: + type: keyword + contributors[]: + type: keyword + +settings: + schema-server: 'local://' +profiles: +- record +- draft From b43b3ad4e75bbd490946bfbd0a9fa772c881ebc5 Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Thu, 29 Aug 2024 09:08:53 +0200 Subject: [PATCH 2/2] tests --- run-tests.sh | 7 +- tests/conftest.py | 228 ++++++++++++++++++++++++++--------------- tests/test_requests.py | 60 +---------- tests/thesis.yaml | 19 +--- 4 files changed, 152 insertions(+), 162 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 9683e07..70202ef 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -24,11 +24,6 @@ fi if test -d $VENV_TESTS ; then rm -rf $VENV_TESTS fi -pip install -U oarepo-model-builder \ - oarepo-model-builder-tests \ - oarepo-model-builder-requests \ - oarepo-model-builder-drafts \ - oarepo-model-builder-workflows oarepo-compile-model ./tests/thesis.yaml --output-directory ./thesis -vvv python3 -m venv $VENV_TESTS @@ -41,4 +36,4 @@ pip install -e ".[tests]" pytest ./thesis/tests -vvv -pytest tests -vvv +pytest tests -vvv \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 621575d..a52f0e6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,19 +1,21 @@ -import copy import os import yaml import pytest - -from flask_security.utils import login_user -from invenio_access.permissions import system_identity +from flask_principal import Identity, Need, UserNeed +from flask_security.utils import hash_password, login_user +from invenio_access.models import ActionRoles +from invenio_access.permissions import superuser_access +from invenio_accounts.models import Role from invenio_accounts.testutils import login_user_via_session from invenio_app.factory import create_api from invenio_requests.customizations import CommentEventType, LogEventType +from invenio_requests.proxies import current_request_type_registry, current_requests +from invenio_requests.records.api import Request, RequestEventFormat from thesis.proxies import current_service -from invenio_users_resources.records import UserAggregate +from thesis.records.api import ThesisRecord +# from thesis.proxies import current_service +# from thesis.records.api import ThesisRecord -@pytest.fixture() -def default_workflow_json(): - return {"parent": {"workflow": "default"}} @pytest.fixture(scope="function") def sample_metadata_list(): @@ -50,103 +52,161 @@ def app_config(app_config): return app_config -class LoggedClient: - def __init__(self, client, user_fixture): - self.client = client - self.user_fixture = user_fixture +@pytest.fixture(scope="module") +def identity_simple(): + """Simple identity fixture.""" + i = Identity(1) + i.provides.add(UserNeed(1)) + i.provides.add(Need(method="system_role", value="any_user")) + i.provides.add(Need(method="system_role", value="authenticated_user")) + return i + + +@pytest.fixture(scope="module") +def identity_simple_2(): + """Simple identity fixture.""" + i = Identity(2) + i.provides.add(UserNeed(2)) + i.provides.add(Need(method="system_role", value="any_user")) + i.provides.add(Need(method="system_role", value="authenticated_user")) + return i - def _login(self): - login_user(self.user_fixture.user, remember=True) - login_user_via_session(self.client, email=self.user_fixture.email) - def post(self, *args, **kwargs): - self._login() - return self.client.post(*args, **kwargs) +@pytest.fixture(scope="module") +def requests_service(app): + """Request Factory fixture.""" - def get(self, *args, **kwargs): - self._login() - return self.client.get(*args, **kwargs) + return current_requests.requests_service - def put(self, *args, **kwargs): - self._login() - return self.client.put(*args, **kwargs) - def delete(self, *args, **kwargs): - self._login() - return self.client.delete(*args, **kwargs) +@pytest.fixture(scope="module") +def request_events_service(app): + """Request Factory fixture.""" + service = current_requests.request_events_service + return service + @pytest.fixture() -def logged_client(client): - def _logged_client(user): - return LoggedClient(client, user) +def create_request(requests_service): + """Request Factory fixture.""" + + def _create_request(identity, input_data, receiver, request_type, **kwargs): + """Create a request.""" + # Need to use the service to get the id + item = requests_service.create( + identity, input_data, request_type=request_type, receiver=receiver, **kwargs + ) + return item._request + + return _create_request - return _logged_client @pytest.fixture() -def users(app, db, UserFixture): - user1 = UserFixture( - email="user1@example.org", - password="password", - active=True, - confirmed=True, - ) - user1.create(app, db) +def submit_request(create_request, requests_service, **kwargs): + """Opened Request Factory fixture.""" - user2 = UserFixture( - email="user2@example.org", - password="beetlesmasher", - active=True, - confirmed=True, - ) - user2.create(app, db) + def _submit_request(identity, data, **kwargs): + """Create and submit a request.""" + request = create_request(identity, input_data=data, **kwargs) + id_ = request.id + return requests_service.execute_action(identity, id_, "submit", data)._request + + return _submit_request - user3 = UserFixture( - email="user3@example.org", - password="beetlesmasher", - active=True, - confirmed=True, - ) - user3.create(app, db) + +@pytest.fixture(scope="module") +def users(app): + """Create example users.""" + # This is a convenient way to get a handle on db that, as opposed to the + # fixture, won't cause a DB rollback after the test is run in order + # to help with test performance (creating users is a module -if not higher- + # concern) + from invenio_db import db + + with db.session.begin_nested(): + datastore = app.extensions["security"].datastore + + su_role = Role(name="superuser-access") + db.session.add(su_role) + + su_action_role = ActionRoles.create(action=superuser_access, role=su_role) + db.session.add(su_action_role) + + user1 = datastore.create_user( + email="user1@example.org", password=hash_password("password"), active=True + ) + user2 = datastore.create_user( + email="user2@example.org", password=hash_password("password"), active=True + ) + admin = datastore.create_user( + email="admin@example.org", password=hash_password("password"), active=True + ) + admin.roles.append(su_role) db.session.commit() - UserAggregate.index.refresh() - return [user1, user2, user3] + return [user1, user2, admin] + @pytest.fixture() -def urls(): - return {"BASE_URL": "/thesis/", "BASE_URL_REQUESTS": "/requests/"} +def client_with_login(client, users): + """Log in a user to the client.""" + user = users[0] + login_user(user) + login_user_via_session(client, email=user.email) + return client + + +@pytest.fixture(scope="function") +def request_record_input_data(): + """Input data to a Request record.""" + ret = { + "title": "Doc1 approval", + "payload": { + "content": "Can you approve my document doc1 please?", + "format": RequestEventFormat.HTML.value, + }, + } + return ret + @pytest.fixture(scope="module") def record_service(): return current_service -@pytest.fixture() -def create_doi_data_function(): - def ret_data(record_id): - return { - "request_type": "create_doi", - "topic": {"thesis_draft": record_id}, - } - return ret_data +@pytest.fixture(scope="function") +def example_topic_draft(record_service, identity_simple): + draft = record_service.create(identity_simple, {}) + return draft._obj -@pytest.fixture() -def record_factory(record_service, default_workflow_json): - def record(identity, custom_workflow=None, additional_data=None): - json = copy.deepcopy(default_workflow_json) - if custom_workflow: # specifying this assumes use of workflows - json["parent"]["workflow"] = custom_workflow - json = { - "metadata": { - "title": "Title", - - }, - **json, - } - if additional_data: - json |= additional_data - draft = record_service.create(identity, json) - record = record_service.publish(system_identity, draft.id) - return record._obj - return record \ No newline at end of file +@pytest.fixture(scope="function") +def example_topic(record_service, identity_simple): + draft = record_service.create(identity_simple, {}) + record = record_service.publish(identity_simple, draft.id) + id_ = record.id + record = ThesisRecord.pid.resolve(id_) + return record + + +@pytest.fixture(scope="module") +def identity_creator(identity_simple): # for readability + return identity_simple + + +@pytest.fixture(scope="module") +def identity_receiver(identity_simple_2): # for readability + return identity_simple_2 + + +@pytest.fixture(scope="function") +def request_with_receiver_user( + requests_service, example_topic, identity_creator, users +): + receiver = users[1] + type_ = current_request_type_registry.lookup("generic_request", quiet=True) + request_item = requests_service.create( + identity_creator, {}, type_, receiver=receiver, topic=example_topic + ) + request = Request.get_record(request_item.id) + return request_item \ No newline at end of file diff --git a/tests/test_requests.py b/tests/test_requests.py index 47a01f6..7816f92 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1,3 +1,6 @@ +from invenio_access.permissions import system_identity +from invenio_base.utils import obj_or_import_string + def test_datacite_config(app): @@ -5,61 +8,4 @@ def test_datacite_config(app): assert "DATACITE_PREFIX" in app.config -def link_api2testclient(api_link): - base_string = "https://127.0.0.1:5000/api/" - return api_link[len(base_string) - 1 :] - - -def test_edit_autoaccept( - logged_client, - users, - urls, - create_doi_data_function, - record_factory, - search_clear, -): - creator = users[0] - creator_client = logged_client(creator) - - record1 = record_factory(creator.identity) - id_ = record1["id"] - - # test direct edit is forbidden - direct_edit = creator_client.post( - f"{urls['BASE_URL']}{id_}/draft", - ) - assert direct_edit.status_code == 403 - - resp_request_create = creator_client.post( - urls["BASE_URL_REQUESTS"], - json=create_doi_data_function(record1["id"]), - ) - resp_request_submit = creator_client.post( - link_api2testclient(resp_request_create.json["links"]["actions"]["submit"]), - ) - # is request accepted and closed? - request = creator_client.get( - f'{urls["BASE_URL_REQUESTS"]}{resp_request_create.json["id"]}', - ).json - - assert request["status"] == "accepted" - assert not request["is_open"] - assert request["is_closed"] - - assert "draft_record:links:self" in request["payload"] - assert "draft_record:links:self_html" in request["payload"] - - # ThesisRecord.index.refresh() - # ThesisDraft.index.refresh() - # edit action worked? - # search = creator_client.get( - # f'user{urls["BASE_URL"]}', - # ).json[ - # "hits" - # ]["hits"] - # assert len(search) == 1 - # assert search[0]["links"]["self"].endswith("/draft") - # assert search[0]["id"] == id_ - # - diff --git a/tests/thesis.yaml b/tests/thesis.yaml index 4292d00..449d29e 100644 --- a/tests/thesis.yaml +++ b/tests/thesis.yaml @@ -1,23 +1,12 @@ record: use: - - invenio + - invenio module: qualified: thesis permissions: presets: [ 'everyone' ] - draft: {} properties: metadata: - properties: - title: - type: fulltext - creators[]: - type: keyword - contributors[]: - type: keyword - -settings: - schema-server: 'local://' -profiles: -- record -- draft + properties: + title: + type: keyword \ No newline at end of file