Skip to content

Commit

Permalink
tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Oct 17, 2024
1 parent d5f2778 commit f4a6e4b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
66 changes: 37 additions & 29 deletions tests/test_communities/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
WorkflowRequestPolicy,
WorkflowTransitions,
)

from tests.test_communities.utils import link_api2testclient
from thesis.records.api import ThesisDraft

from oarepo_communities.proxies import current_oarepo_communities
Expand All @@ -49,20 +47,8 @@
from oarepo_communities.services.permissions.policy import (
CommunityDefaultWorkflowPermissions,
)


@pytest.fixture()
def scenario_permissions():

return CreatorsFromWorkflowRequestsPermissionPolicy


@pytest.fixture
def patch_requests_permissions(
requests_service_config,
scenario_permissions,
):
setattr(requests_service_config, "permission_policy_cls", scenario_permissions)
from tests.test_communities.utils import link_api2testclient
from oarepo_requests.services.permissions.workflow_policies import CreatorsFromWorkflowRequestsPermissionPolicy


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -230,8 +216,6 @@ class DefaultRequests(WorkflowRequestPolicy):
)




class PublishRequestsRecordOwnerInRecordCommunity(DefaultRequests):
publish_draft = WorkflowRequest(
requesters=[IfInState("draft", [RecordOwnerInRecordCommunity()])],
Expand Down Expand Up @@ -288,6 +272,7 @@ class NoRequests(WorkflowRequestPolicy):
transitions=WorkflowTransitions(),
)


class CuratorPublishRequests(DefaultRequests):
publish_draft = WorkflowRequest(
requesters=[IfInState("draft", [CommunityRole("owner")])],
Expand Down Expand Up @@ -328,7 +313,7 @@ class CuratorPublishRequests(DefaultRequests):
label=_("For testing assigned param filter."),
permission_policy_cls=TestCommunityWorkflowPermissions,
request_policy_cls=CuratorPublishRequests,
)
),
}


Expand Down Expand Up @@ -420,6 +405,7 @@ def app_config(app_config):
app_config["COMMUNITIES_CUSTOM_FIELDS"] = [WorkflowCF(name="workflow")]
app_config["COMMUNITIES_CUSTOM_FIELDS_UI"] = []

app_config["REQUESTS_PERMISSION_POLICY"] = CreatorsFromWorkflowRequestsPermissionPolicy
return app_config


Expand Down Expand Up @@ -657,19 +643,25 @@ def default_workflow_json():
@pytest.fixture()
def create_draft_via_resource(default_workflow_json):
def _create_draft(
client, community, expand=True, custom_workflow=None, additional_data=None, **kwargs
client,
community,
expand=True,
custom_workflow=None,
additional_data=None,
**kwargs,
):
json = copy.deepcopy(default_workflow_json)
if custom_workflow:
json["parent"]["workflow"] = custom_workflow
if additional_data:
json |= additional_data
#url = "/thesis/" + "?expand=true" if expand else "/thesis/"
url=f"/communities/{community.id}/thesis"
# url = "/thesis/" + "?expand=true" if expand else "/thesis/"
url = f"/communities/{community.id}/thesis"
return client.post(url, json=json, **kwargs)

return _create_draft


@pytest.fixture()
def get_request_type():
"""
Expand Down Expand Up @@ -697,13 +689,29 @@ def _create_request_from_link(request_types_json, request_type):

return _create_request_from_link


@pytest.fixture
def submit_request(get_request_link):
def create_request_by_link(get_request_link):
def _create_request(client, record, request_type):
applicable_requests = client.get(
link_api2testclient(record.json["links"]["applicable-requests"])
).json["hits"]["hits"]
create_link = link_api2testclient(
get_request_link(applicable_requests, request_type)
)
create_response = client.post(create_link)
return create_response

return _create_request


@pytest.fixture
def submit_request_by_link(create_request_by_link):
def _submit_request(client, record, request_type):
applicable_requests = client.get(link_api2testclient(record.json["links"]["applicable-requests"])).json["hits"]["hits"]
approve_link = link_api2testclient(get_request_link(applicable_requests, request_type))
create_approve_response = client.post(approve_link)
submit_approve_response = client.post(
link_api2testclient(create_approve_response.json["links"]["actions"]["submit"]))
return submit_approve_response
create_response = create_request_by_link(client, record, request_type)
submit_response = client.post(
link_api2testclient(create_response.json["links"]["actions"]["submit"])
)
return submit_response

return _submit_request
6 changes: 0 additions & 6 deletions tests/test_communities/test_community_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def test_community_publish(
community,
request_data_factory,
record_service,
patch_requests_permissions,
search_clear,
):
reader_client = logged_client(community_reader)
Expand Down Expand Up @@ -163,7 +162,6 @@ def test_community_delete(
community,
request_data_factory,
record_service,
patch_requests_permissions,
search_clear,
):
reader_client = logged_client(community_reader)
Expand Down Expand Up @@ -210,7 +208,6 @@ def test_community_migration(
request_data_factory,
record_service,
inviter,
patch_requests_permissions,
search_clear,
):
reader_client, owner_client, community_1, community_2 = _init_env(
Expand Down Expand Up @@ -269,7 +266,6 @@ def test_community_submission_secondary(
inviter,
request_data_factory,
record_service,
patch_requests_permissions,
search_clear,
):
reader_client, owner_client, community_1, community_2 = _init_env(
Expand Down Expand Up @@ -332,7 +328,6 @@ def test_remove_secondary(
inviter,
request_data_factory,
record_service,
patch_requests_permissions,
search_clear,
):
reader_client, owner_client, community_1, community_2 = _init_env(
Expand Down Expand Up @@ -420,7 +415,6 @@ def test_community_role_ui_serialization(
request_data_factory,
record_service,
ui_serialized_community_role,
patch_requests_permissions,
search_clear,
):
reader_client = logged_client(community_reader)
Expand Down
16 changes: 9 additions & 7 deletions tests/test_communities/test_param_interpreters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


def test_community_role_param_interpreter(
logged_client,
community_owner,
Expand All @@ -6,13 +8,12 @@ def test_community_role_param_interpreter(
community_with_workflow_factory,
record_service,
create_draft_via_resource,
submit_request,
create_request_by_link,
submit_request_by_link,
inviter,
search_clear,
):
owner_client = logged_client(community_owner)
curator_client = logged_client(community_curator)
reader_client = logged_client(community_reader)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
Expand All @@ -24,16 +25,17 @@ def test_community_role_param_interpreter(
record1 = create_draft_via_resource(owner_client, community=community_1)
record2 = create_draft_via_resource(owner_client, community=community_2)
record3 = create_draft_via_resource(
curator_client, community=community_3, custom_workflow="curator_publish"
owner_client, community=community_2, custom_workflow="curator_publish" # owner is creator but not receiver of the third request
)

response_1 = submit_request(reader_client, record1, "publish_draft")
response_2 = submit_request(reader_client, record2, "publish_draft")
response_3 = submit_request(owner_client, record3, "publish_draft")
response_1 = submit_request_by_link(owner_client, record1, "publish_draft")
response_2 = create_request_by_link(owner_client, record2, "publish_draft")
response_3 = submit_request_by_link(owner_client, record3, "publish_draft")

search_unfiltered = owner_client.get("/requests/")
assert len(search_unfiltered.json["hits"]["hits"]) == 3

search_filtered = owner_client.get("/requests/?assigned=true")


assert len(search_filtered.json["hits"]["hits"]) == 2
1 change: 0 additions & 1 deletion tests/test_communities/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def test_scenario_change(
inviter,
set_community_workflow,
service_config,
patch_requests_permissions,
search_clear,
):
owner_client = logged_client(community_owner)
Expand Down

0 comments on commit f4a6e4b

Please sign in to comment.