Skip to content

Commit

Permalink
intermediary commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Jan 17, 2025
1 parent 9f648de commit c56f423
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 166 deletions.
4 changes: 2 additions & 2 deletions tests/test_communities/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
]

@pytest.fixture(autouse=True)
def init_cf(init_cf):
return init_cf
def init_communities_cf(init_communities_cf):
return init_communities_cf

@pytest.fixture(scope="module", autouse=True)
def location(location):
Expand Down
13 changes: 6 additions & 7 deletions tests/test_communities/test_community_inclusion.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import pytest
from invenio_access.permissions import system_identity
from pytest_oarepo.communities.functions import community_get_or_create

from oarepo_communities.errors import CommunityNotIncludedException


def test_include(
logged_client,
community_owner,
community_with_workflow_factory,
community_inclusion_service,
record_service,
search_clear,
):
owner_client = logged_client(community_owner)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
community_3 = community_with_workflow_factory("comm3", community_owner)
community_1 = community_get_or_create(community_owner, slug="comm1")
community_2 = community_get_or_create(community_owner, slug="comm2")
community_3 = community_get_or_create(community_owner, slug="comm3")

response = owner_client.post(f"/communities/{community_1.id}/thesis", json={})

Expand Down Expand Up @@ -51,15 +51,14 @@ def test_include(
def test_remove(
logged_client,
community_owner,
community_with_workflow_factory,
community_inclusion_service,
record_service,
search_clear,
):
owner_client = logged_client(community_owner)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
community_1 = community_get_or_create(community_owner, "comm1")
community_2 = community_get_or_create(community_owner, "comm2")

response = owner_client.post(f"/communities/{community_1.id}/thesis", json={})
record_id = response.json["id"]
Expand Down
59 changes: 27 additions & 32 deletions tests/test_communities/test_community_records.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pytest_oarepo.communities.functions import community_get_or_create, invite

from thesis.records.api import ThesisDraft, ThesisRecord


Expand Down Expand Up @@ -41,15 +43,14 @@ def test_create_record_in_community_without_model_in_url(
def test_search(
logged_client,
community_owner,
community_with_workflow_factory,
published_record_with_community_factory,
record_service,
search_clear,
):
owner_client = logged_client(community_owner)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
community_1 = community_get_or_create(community_owner, "comm1")
community_2 = community_get_or_create(community_owner, "comm2")

record1 = published_record_with_community_factory(owner_client, community_1.id)
record2 = published_record_with_community_factory(owner_client, community_2.id)
Expand All @@ -70,8 +71,8 @@ def test_search(
assert len(response_draft1.json["hits"]["hits"]) == 1
assert len(response_draft2.json["hits"]["hits"]) == 1

assert response_record1.json["hits"]["hits"][0]["id"] == record1.json["id"]
assert response_record2.json["hits"]["hits"][0]["id"] == record2.json["id"]
assert response_record1.json["hits"]["hits"][0]["id"] == record1["id"]
assert response_record2.json["hits"]["hits"][0]["id"] == record2["id"]


# todo tests for search links
Expand All @@ -80,15 +81,14 @@ def test_search(
def test_search_model(
logged_client,
community_owner,
community_with_workflow_factory,
published_record_with_community_factory,
record_service,
search_clear,
):
owner_client = logged_client(community_owner)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
community_1 = community_get_or_create(community_owner, "comm1")
community_2 = community_get_or_create(community_owner, "comm2")

record1 = published_record_with_community_factory(owner_client, community_1.id)
record2 = published_record_with_community_factory(owner_client, community_2.id)
Expand All @@ -102,29 +102,28 @@ def test_search_model(
assert len(response_record1.json["hits"]["hits"]) == 1
assert len(response_record2.json["hits"]["hits"]) == 1

assert response_record1.json["hits"]["hits"][0]["id"] == record1.json["id"]
assert response_record2.json["hits"]["hits"][0]["id"] == record2.json["id"]
assert response_record1.json["hits"]["hits"][0]["id"] == record1["id"]
assert response_record2.json["hits"]["hits"][0]["id"] == record2["id"]


def test_user_search(
logged_client,
community_owner,
users,
community_with_workflow_factory,
inviter,
draft_with_community_factory,
search_clear,
):
community_reader = users[0]
owner_client = logged_client(community_owner)
reader_client = logged_client(community_reader)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
inviter(community_reader, community_1.id, "reader")
community_1 = community_get_or_create(community_owner, "comm1")
community_2 = community_get_or_create(community_owner, "comm2")
invite(community_reader, community_1.id, "reader")

record1 = owner_client.post(f"/communities/{community_1.id}/thesis", json={}).json
record2 = owner_client.post(f"/communities/{community_2.id}/thesis", json={}).json
record3 = reader_client.post(f"/communities/{community_1.id}/thesis", json={}).json
record1 = draft_with_community_factory(owner_client, str(community_1.id))
record2 = draft_with_community_factory(owner_client, str(community_2.id))
record3 = draft_with_community_factory(reader_client, str(community_1.id))

ThesisRecord.index.refresh()
ThesisDraft.index.refresh()
Expand All @@ -149,22 +148,21 @@ def test_user_search_model(
logged_client,
community_owner,
users,
community_with_workflow_factory,
draft_with_community_factory,
record_service,
inviter,
search_clear,
):
community_reader = users[0]
owner_client = logged_client(community_owner)
reader_client = logged_client(community_reader)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
inviter(community_reader, community_1.id, "reader")
community_1 = community_get_or_create(community_owner, "comm1")
community_2 = community_get_or_create(community_owner, "comm2")
invite(community_reader, community_1.id, "reader")

record1 = owner_client.post(f"/communities/{community_1.id}/thesis", json={}).json
record2 = owner_client.post(f"/communities/{community_2.id}/thesis", json={}).json
record3 = reader_client.post(f"/communities/{community_1.id}/thesis", json={}).json
record1 = draft_with_community_factory(owner_client, str(community_1.id))
record2 = draft_with_community_factory(owner_client, str(community_2.id))
record3 = draft_with_community_factory(reader_client, str(community_1.id))

ThesisRecord.index.refresh()
ThesisDraft.index.refresh()
Expand All @@ -182,7 +180,6 @@ def test_user_search_model(
def test_search_links(
logged_client,
community_owner,
community_with_workflow_factory,
published_record_with_community_factory,
record_service,
search_clear,
Expand All @@ -191,7 +188,7 @@ def test_search_links(

owner_client = logged_client(community_owner)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_1 = community_get_or_create(community_owner, "comm1")

for _ in range(30):
published_record_with_community_factory(owner_client, community_1.id)
Expand Down Expand Up @@ -240,16 +237,14 @@ def check_links(model_suffix):
def test_search_ui_serialization(
logged_client,
community_owner,
community_with_workflow_factory,
published_record_with_community_factory,
record_service,
inviter,
search_clear,
):
owner_client = logged_client(community_owner)

community_1 = community_with_workflow_factory("comm1", community_owner)
community_2 = community_with_workflow_factory("comm2", community_owner)
community_1 = community_get_or_create(community_owner, "comm1")
community_2 = community_get_or_create(community_owner, "comm2")

record1 = published_record_with_community_factory(owner_client, community_1.id)
record2 = published_record_with_community_factory(owner_client, community_2.id)
Expand Down
Loading

0 comments on commit c56f423

Please sign in to comment.