Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/weko-items-ui/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
'item_create_scope = weko_items_ui.scopes:item_create_scope',
'item_update_scope = weko_items_ui.scopes:item_update_scope',
'item_delete_scope = weko_items_ui.scopes:item_delete_scope',
'ranking_read_scope = weko_items_ui.scopes:ranking_read_scope'
'ranking_read_scope = weko_items_ui.scopes:ranking_read_scope',
'item_bulk_process_scope = weko_items_ui.scopes:item_bulk_process_scope',
],
'invenio_db.models': [
'weko_items_ui = weko_items_ui.models',
Expand Down
61 changes: 61 additions & 0 deletions modules/weko-items-ui/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from invenio_access.models import ActionRoles, ActionUsers
from invenio_accounts import InvenioAccounts
from invenio_accounts.models import Role, User
from invenio_accounts.utils import jwt_create_token
from invenio_accounts.testutils import create_test_user
from invenio_assets import InvenioAssets
from invenio_communities.models import Community
Expand All @@ -51,6 +52,8 @@
DEPOSIT_JSONSCHEMAS_PREFIX,
)
from invenio_files_rest.models import Location, Bucket,ObjectVersion
from invenio_oauth2server import InvenioOAuth2Server
from invenio_oauth2server.models import Client, Token
from invenio_records_files.api import RecordsBuckets
from invenio_records_ui import InvenioRecordsUI
from invenio_files_rest import InvenioFilesREST
Expand Down Expand Up @@ -113,6 +116,7 @@
from weko_items_ui.config import WEKO_ITEMS_UI_CRIS_LINKAGE_RESEARCHMAP_TYPE_MAPPINGS ,WEKO_ITEMS_UI_CRIS_LINKAGE_RESEARCHMAP_MAPPINGS,WEKO_ITEMS_UI_CRIS_LINKAGE_RESEARCHMAP_MERGE_MODE_DEFAULT
from weko_groups import WekoGroups
from .helpers import create_record, json_data
from zipfile import ZipFile, ZIP_DEFLATED


# @event.listens_for(Engine, "connect")
Expand Down Expand Up @@ -272,6 +276,7 @@ def base_app(instance_path):
InvenioRecordsUI(app_)
InvenioFilesREST(app_)
InvenioJSONSchemas(app_)
InvenioOAuth2Server(app_)
InvenioSearch(app_)
InvenioStats(app_)
Menu(app_)
Expand Down Expand Up @@ -335,6 +340,48 @@ def db(app):
db_.session.remove()
db_.drop_all()

@pytest.fixture()
def tokens(app,users,db):
scopes = [
"deposit:write deposit:actions item:create item:bulkprocess",
"deposit:write deposit:actions item:create user:activity item:bulkprocess",
"deposit:write user:activity",
""
]
tokens = []

for i, scope in enumerate(scopes):
user = users[i]
user_id = str(user["id"])

test_client = Client(
client_id=f"dev{user_id}",
client_secret=f"dev{user_id}",
name="Test name",
description="test description",
is_confidential=False,
user_id=user_id,
_default_scopes="deposit:write"
)
test_token = Token(
client=test_client,
user_id=user_id,
token_type="bearer",
access_token=jwt_create_token(user_id=user_id),
expires=datetime.now() + timedelta(hours=10),
is_personal=False,
is_internal=False,
_scopes=scope
)

db.session.add(test_client)
db.session.add(test_token)
tokens.append({"token":test_token, "client":test_client, "scope":scope})

db.session.commit()

return tokens

@pytest.fixture()
def esindex(app,db_records, es):
index_name = app.config["INDEXER_DEFAULT_INDEX"]
Expand Down Expand Up @@ -23464,3 +23511,17 @@ def restricted_settings(db):
{"item_application": {"application_item_types": [1], "item_application_enable": True}, "display_request_form": True},
id=10
)

@pytest.fixture()
def make_zip():
def factory():
fp = BytesIO()
with ZipFile(fp, 'w', compression=ZIP_DEFLATED) as new_zip:
for dir, subdirs, files in os.walk("tests/data/zip_data/data"):
new_zip.write(dir,dir.split("/")[-1])
for file in files:
new_zip.write(os.path.join(dir, file),os.path.join(dir.split("/")[-1],file))
fp.seek(0)
return fp
return factory

239 changes: 117 additions & 122 deletions modules/weko-items-ui/tests/test_utils.py

Large diffs are not rendered by default.

Loading
Loading