Skip to content

Commit

Permalink
Merge branch 'links-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Oct 12, 2023
2 parents ecc96b3 + 9827e55 commit ffd7043
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build-tests/thesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ record:
module:
qualified: thesis
permissions:
presets: ['everyone']
presets: ['read_only']
use:
- invenio

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ from io import BytesIO
import pytest

{{ vars.resource_config.class|generate_import }}
{{ parent_record.resource_config.class|generate_import }}
{{ metadata_record.resource_config.class|generate_import }}
{{ file_record.resource_config.class|generate_import }}

BASE_URL_DRAFT_FILES = {{ vars.resource_config.class|base_name }}.url_prefix.replace({% raw %}"<pid_value>"{% endraw %}, "{id}")
BASE_URL_FILES = {{ file_record.resource_config.class|base_name }}.url_prefix.replace({% raw %}"<pid_value>"{% endraw %}, "{id}")
BASE_URL = {{ parent_record.resource_config.class|base_name }}.url_prefix
BASE_URL = {{ metadata_record.resource_config.class|base_name }}.url_prefix

@pytest.fixture()
def published_id(client_with_credentials, location, headers):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ class ModelSchema(ma.Schema):
)

def process_ext_resource(self, datatype, section, **kwargs):
if self.is_draft_files_profile:
if datatype.root.profile == "draft_files":
cfg = section.config
cfg["ext-service-name"] = "service_draft_files"
cfg["ext-resource-name"] = "resource_draft_files"

def before_model_prepare(self, datatype, *, context, **kwargs):
self.is_draft_files_profile = context["profile"] == "draft_files"
if not self.is_draft_files_profile:
if not datatype.root.profile == "draft_files":
return
ext = set_default(datatype, "ext-resource", {})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class DraftFilesFieldModelComponent(FilesFieldModelComponent):
dependency_remap = FilesFieldModelComponent

def before_model_prepare(self, datatype, *, context, **kwargs):
if context["profile"] not in {"files", "draft_files"}:
if datatype.root.profile not in {"files", "draft_files"}:
return
files_field = set_default(datatype, "files-field", {})
if context["profile"] == "draft_files":
if datatype.root.profile == "draft_files":
record_class = datatype.definition["record"]["class"]
files_field.setdefault("file-class", base_name(record_class))
files_field.setdefault("field-args", ["store=False", "delete=False"])
Expand All @@ -28,7 +28,7 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
],
)

if context["profile"] == "files":
if datatype.root.profile == "files":
files_field.setdefault(
"field-args", ["store=False", "create=False", "delete=False"]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DraftFilesParentComponent(DraftParentComponent):
affects = [DraftParentComponent]

def before_model_prepare(self, datatype, *, context, **kwargs):
if context["profile"] == "files":
if datatype.root.profile == "files":
draft_parent_record = set_default(datatype, "draft-parent-record", {})
draft_parent_record_metadata = set_default(
datatype, "draft-parent-record-metadata", {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class ModelSchema(ma.Schema):
)

def process_mb_invenio_record_service_config(self, *, datatype, section, **kwargs):
if self.is_draft_files_profile:
if datatype.root.profile == "draft_files":
# override class as it has to be a parent class
section.config.setdefault("record", {})[
"class"
] = datatype.parent_record.definition["record"]["class"]
] = datatype.draft_record.definition["record"]["class"]

def process_links(self, datatype, section: Section, **kwargs):
url_prefix = url_prefix2link(datatype.definition["resource-config"]["base-url"])

if self.is_record_profile:
if datatype.root.profile == "record":
has_files = "files" in datatype.definition
if not has_files:
return
Expand Down Expand Up @@ -75,7 +75,7 @@ def process_links(self, datatype, section: Section, **kwargs):
)
),

if self.is_draft_files_profile:
if datatype.root.profile == "draft_files":
if "links_search" in section.config:
section.config.pop("links_search")
# remove normal links and add
Expand Down Expand Up @@ -113,13 +113,11 @@ def process_links(self, datatype, section: Section, **kwargs):
]

def before_model_prepare(self, datatype, *, context, **kwargs):
self.is_draft_files_profile = context["profile"] == "draft_files"
self.is_record_profile = context["profile"] == "record"
if not context["profile"] == "draft_files":
if not datatype.root.profile == "draft_files":
return

parent_record_datatype: DataType = context["parent_record"]
datatype.parent_record = parent_record_datatype
draft_record_datatype: DataType = context["draft_record"]
datatype.draft_record = draft_record_datatype

set_default(datatype, "search-options", {}).setdefault("skip", True)
set_default(datatype, "json-schema-settings", {}).setdefault("skip", True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InvenioDraftsFilesRecordComponent(DataTypeComponent):
]

def before_model_prepare(self, datatype, *, context, **kwargs):
if context["profile"] == "record":
if datatype.root.profile == "record":
append_array(
datatype,
"service-config",
Expand Down
2 changes: 1 addition & 1 deletion oarepo_model_builder_drafts_files/datatypes/draft_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class ModelSchema(ModelDataType.ModelSchema):
)

def prepare(self, context):
self.parent_record = context["parent_record"]
self.draft_record = context["draft_record"]
self.file_record = context["file_record"]
super().prepare(context)
4 changes: 2 additions & 2 deletions oarepo_model_builder_drafts_files/profiles/draft_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def build(
# from cache. It files profile is called the first, then this will call prepare({})
# on the record and will take some time (no files will be generated, only class names
# allocated)
parent_record = model.get_schema_section("draft", model_path[:-1] + ["draft"])
draft_record = model.get_schema_section("draft", model_path[:-1] + ["draft"])
file_record = model.get_schema_section("files", model_path[:-1] + ["files"])

draft_file_profile = dict_get(model.schema, model_path)
Expand All @@ -38,7 +38,7 @@ def build(
output_directory=output_directory,
builder=builder,
context={
"parent_record": parent_record,
"draft_record": draft_record,
"file_record": file_record,
"profile": "draft_files",
"profile_module": "files",
Expand Down

0 comments on commit ffd7043

Please sign in to comment.