Skip to content

Commit

Permalink
Merge pull request #82 from oarepo/draftlisting&testbuild
Browse files Browse the repository at this point in the history
Draftlisting&testbuild
  • Loading branch information
SilvyPuzzlewell authored Jul 26, 2023
2 parents 41f7b69 + b814d3a commit 0c1902f
Show file tree
Hide file tree
Showing 48 changed files with 87 additions and 1,062 deletions.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions oarepo_runtime/drafts/systemfields/has_draftcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from invenio_records.dictutils import dict_set
from invenio_records.systemfields import SystemField
from sqlalchemy.orm.exc import NoResultFound

from oarepo_runtime.cf import CustomFieldsMixin


# taken from https://github.com/inveniosoftware/invenio-rdm-records/blob/master/invenio_rdm_records/records/systemfields/has_draftcheck.py
class HasDraftCheckField(CustomFieldsMixin, SystemField):
"""PID status field which checks against an expected status."""

def __init__(self, draft_cls=None, key=None, **kwargs):
"""Initialize the PIDField.
It stores the `record.has_draft` value in the secondary storage
system's record or defaults to `False` if the `draft_cls` is not passed
e.g Draft records.
:param key: Attribute name of the HasDraftCheckField.
:param draft_cls: The draft class to use for querying.
"""
super().__init__(key=key, **kwargs)
self.draft_cls = draft_cls

#
# Data descriptor methods (i.e. attribute access)
#
def __get__(self, record, owner=None):
if record is None:
return self # returns the field itself.

# If not draft_cls is passed return False
if self.draft_cls is None:
return False

try:
self.draft_cls.get_record(record.id)
return True
except NoResultFound:
return False

def pre_dump(self, record, data, **kwargs):
dict_set(data, self.key, record.has_draft)
"""
def post_load(self, record, data, **kwargs):
record.pop(self.key, None)
"""
3 changes: 3 additions & 0 deletions oarepo_runtime/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ def init_config(self, app):

elif k.startswith("DATASTREAMS_"):
app.config.setdefault(k, getattr(ext_config, k))

elif k == "HAS_DRAFT_CUSTOM_FIELD":
app.config.setdefault(k, getattr(ext_config, k))
3 changes: 3 additions & 0 deletions oarepo_runtime/ext_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from oarepo_runtime.datastreams.readers.yaml import YamlReader
from oarepo_runtime.datastreams.writers.service import ServiceWriter
from oarepo_runtime.datastreams.writers.yaml import YamlWriter
from invenio_records_resources.services.custom_fields import BooleanCF

OAREPO_PERMISSIONS_PRESETS = {
"read_only": ReadOnlyPermissionPolicy,
Expand Down Expand Up @@ -53,3 +54,5 @@
DEFAULT_DATASTREAMS_EXCLUDES = []

DATASTREAMS_CONFIG_GENERATOR = default_config_generator

HAS_DRAFT_CUSTOM_FIELD = [BooleanCF("has_draft")]
24 changes: 18 additions & 6 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
#!/bin/bash

set -e

set -e
pip install -e '.[tests]'
pip install -e 'tests/records2'
pip uninstall -y uritemplate
pip install uritemplate
export PYTHONPATH=.

MODEL="records2"
VENV=".model_venv"

if test -d ./tests/$MODEL; then
rm -rf ./tests/$MODEL
fi

if test -d ./$VENV; then
rm -rf ./$VENV
fi

oarepo-compile-model ./tests/$MODEL.yaml --output-directory ./tests/$MODEL -vvv
python3 -m venv $VENV
. $VENV/bin/activate
pip install -U setuptools pip wheel
pip install "./tests/$MODEL[tests]"
rm -rf ./tests/$MODEL/tests
pytest tests
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-runtime
version = 1.3.20
version = 1.3.21
description = A set of runtime extensions of Invenio repository
authors = Alzbeta Pokorna
readme = README.md
Expand Down Expand Up @@ -34,6 +34,8 @@ tests =
invenio-search[opensearch2]
oarepo>=11.0,<12
uritemplate>=4.1.1
oarepo-model-builder
oarepo-model-builder-tests

# Generated with:
# git ls-files | egrep '^oarepo' | grep -v '.py$' | grep -v '.gitkeep' | sed 's#/[^/]*$##' | sort -u | sed 's#$#/*,#' | sed 's#^[^/]*/##' | tr '\n' ' '
Expand Down
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
See https://pytest-invenio.readthedocs.io/ for documentation on which test
fixtures are available.
"""

import os

import pytest
from flask_principal import Identity, Need, UserNeed
Expand Down Expand Up @@ -66,6 +66,12 @@ def app_config(app_config):
app_config["DATASTREAMS_TRANSFORMERS"] = {
"status": StatusTransformer,
}
app_config["SEARCH_HOSTS"] = [
{
"host": os.environ.get("OPENSEARCH_HOST", "localhost"),
"port": os.environ.get("OPENSEARCH_PORT", "9200"),
}
]
return app_config


Expand Down
149 changes: 0 additions & 149 deletions tests/records/data/sample_data.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/records/pyproject.toml

This file was deleted.

26 changes: 0 additions & 26 deletions tests/records/records2

This file was deleted.

40 changes: 0 additions & 40 deletions tests/records/setup.cfg

This file was deleted.

3 changes: 0 additions & 3 deletions tests/records/setup.py

This file was deleted.

8 changes: 6 additions & 2 deletions tests/records2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
model:
record:
use: invenio
schema-server: local://
properties:
metadata:
properties:
title: keyword
module:
qualified: records2
permissions:
presets: [ 'everyone' ]

Loading

0 comments on commit 0c1902f

Please sign in to comment.