Skip to content

Commit

Permalink
tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Feb 9, 2024
1 parent 8a560aa commit bb24c70
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion oarepo_model_builder/datatypes/components/model/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ def before_model_prepare(self, datatype, **kwargs):
"format_serializer_cls", "flask_resources.serializers.JSONSerializer"
)
json.setdefault(
"schema_context_args", {'"object_key"': '"ui"', '"identity"': "{{ flask.g{g.identity} }}"}
"schema-context-args", {'"object_key"': '"ui"', '"identity"': "{{ flask.g{g.identity} }}"}
)
4 changes: 3 additions & 1 deletion tests/test_datatype_prepare.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from oarepo_model_builder.schema import ModelSchema


def test_prepare_datatype():
module = "my.test"
model = ModelSchema(
Expand All @@ -23,6 +22,7 @@ def test_prepare_datatype():
},
)
record_section = model.get_schema_section(profile="record", section="record")

assert record_section.definition == {
"api-blueprint": {
"alias": "my_test_record",
Expand Down Expand Up @@ -78,6 +78,7 @@ def test_prepare_datatype():
"imports": [],
"list_schema_cls": "flask_resources.BaseListSchema",
"module": "my.test.resources.records.ui",
"schema-context-args": {'"object_key"': '"ui"', '"identity"': "{{ flask.g{g.identity} }}"}
},
"mapping": {
"alias": "my_test_record",
Expand Down Expand Up @@ -267,6 +268,7 @@ def test_prepare_datatype():
"generate": True,
"module": "my.test.services.records.config",
"service-id": "test",
"result-item-class": "invenio_records_resources.services.records.results.RecordItem",
"result-list-class": "oarepo_runtime.services.results.RecordList",
},
"sortable": [],
Expand Down
3 changes: 2 additions & 1 deletion tests/test_marshmallow_ui_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def test_generate_json_serializer(fulltext_builder):
from test.services.records.ui_schema import TestUISchema
from flask_resources.serializers import JSONSerializer
from flask_resources import BaseListSchema
from flask import g
Expand All @@ -564,7 +565,7 @@ def __init__(self):
format_serializer_cls=JSONSerializer,
object_schema_cls=TestUISchema,
list_schema_cls=BaseListSchema,
schema_context={"object_key": "ui"},
schema_context={"object_key": "ui", "identity": g.identity}
)
'''
)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_model_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def test_model_saver():
"invenio_records_resources.services.RecordServiceConfig{InvenioRecordServiceConfig}",
],
"components": [],
"result-item-class": "invenio_records_resources.services.records.results.RecordItem",
"result-list-class": "oarepo_runtime.services.results.RecordList",
},
"service": {
Expand Down Expand Up @@ -238,6 +239,7 @@ def test_model_saver():
"generate": True,
"list_schema_cls": "flask_resources.BaseListSchema",
"format_serializer_cls": "flask_resources.serializers.JSONSerializer",
"schema-context-args": {'"identity"': '{{ flask.g{g.identity} }}', '"object_key"': '"ui"'},
},
"mapping": {
"generate": True,
Expand Down Expand Up @@ -548,6 +550,7 @@ def test_model_saver_invenio():
"invenio_records_resources.services.RecordServiceConfig{InvenioRecordServiceConfig}",
],
"components": [],
"result-item-class": "invenio_records_resources.services.records.results.RecordItem",
"result-list-class": "oarepo_runtime.services.results.RecordList",
},
"service": {
Expand All @@ -571,6 +574,7 @@ def test_model_saver_invenio():
"generate": True,
"list_schema_cls": "flask_resources.BaseListSchema",
"format_serializer_cls": "flask_resources.serializers.JSONSerializer",
"schema-context-args": {'"identity"': '{{ flask.g{g.identity} }}', '"object_key"': '"ui"'},
},
"mapping": {
"generate": True,
Expand Down
5 changes: 4 additions & 1 deletion tests/test_simple_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,12 @@ def test_service_config():
from test.services.records.schema import TestSchema
from test.services.records.search import TestSearchOptions
from oarepo_runtime.services.results import RecordList
from invenio_records_resources.services.records.results import RecordItem
class TestServiceConfig(PermissionsPresetsConfigMixin, InvenioRecordServiceConfig):
"""TestRecord service config."""
result_item_cls = RecordItem
result_list_cls = RecordList
PERMISSIONS_PRESETS = ["everyone"]
url_prefix = "/test/"
Expand Down Expand Up @@ -529,6 +531,7 @@ def test_ui_serializer_builder():
from test.services.records.ui_schema import TestUISchema
from flask_resources.serializers import JSONSerializer
from flask_resources import BaseListSchema
from flask import g
class TestUIJSONSerializer(LocalizedUIJSONSerializer):
"""UI JSON serializer."""
Expand All @@ -539,7 +542,7 @@ def __init__(self):
format_serializer_cls=JSONSerializer,
object_schema_cls=TestUISchema,
list_schema_cls=BaseListSchema,
schema_context={"object_key": "ui"},
schema_context={ "object_key": "ui", "identity": g.identity }
)
'''
)

0 comments on commit bb24c70

Please sign in to comment.