|
33 | 33 | from invenio_access.models import ActionUsers, Role |
34 | 34 | from invenio_db import db as db_ |
35 | 35 | from invenio_files_rest.models import Location |
| 36 | +from invenio_oaiserver.models import OAISet |
36 | 37 | from invenio_queues.proxies import current_queues |
37 | 38 | from invenio_search import current_search |
38 | 39 | from sqlalchemy_utils import create_database, database_exists |
@@ -87,7 +88,7 @@ def search(appctx): |
87 | 88 | should used the function-scoped :py:data:`search_clear` fixture to leave the |
88 | 89 | indexes clean for the following tests. |
89 | 90 | """ |
90 | | - from invenio_search import current_search, current_search_client |
| 91 | + from invenio_search import current_search_client |
91 | 92 | from invenio_search.errors import IndexAlreadyExistsError |
92 | 93 |
|
93 | 94 | try: |
@@ -236,16 +237,35 @@ def _make_organisation(code, is_shared=True): |
236 | 237 | record = OrganisationRecord.get_record_by_pid(code) |
237 | 238 |
|
238 | 239 | if not record: |
239 | | - record = OrganisationRecord.create(data, dbcommit=True) |
| 240 | + record = OrganisationRecord.create(data, dbcommit=True, with_bucket=True) |
240 | 241 | db.session.commit() |
241 | 242 | record.reindex() |
242 | | - current_search.flush_and_refresh(index="documents-document-v1.0.0-percolators") |
| 243 | + current_search.flush_and_refresh(index="organisations") |
243 | 244 |
|
244 | 245 | return record |
245 | 246 |
|
246 | 247 | return _make_organisation |
247 | 248 |
|
248 | 249 |
|
| 250 | +@pytest.fixture() |
| 251 | +def org_oaiset(db, organisation): |
| 252 | + """Create an OAISet for organisation.""" |
| 253 | + code = organisation["code"] |
| 254 | + oaiset = OAISet( |
| 255 | + spec=code, |
| 256 | + name=organisation["name"], |
| 257 | + search_pattern=f'organisation.code:"{code}"', |
| 258 | + system_created=True, |
| 259 | + ) |
| 260 | + db.session.add(oaiset) |
| 261 | + db.session.commit() |
| 262 | + current_search.flush_and_refresh(index="documents-document-v1.0.0-percolators") |
| 263 | + yield oaiset |
| 264 | + db.session.delete(oaiset) |
| 265 | + db.session.commit() |
| 266 | + current_search.flush_and_refresh(index="documents-document-v1.0.0-percolators") |
| 267 | + |
| 268 | + |
249 | 269 | @pytest.fixture() |
250 | 270 | def organisation(make_organisation): |
251 | 271 | """Create an organisation.""" |
|
0 commit comments