Skip to content

Commit 9d97afb

Browse files
committed
test: updates tests for opensearch 3
Signed-off-by: Pamfilos Fokianos <[email protected]>
1 parent 050a7d4 commit 9d97afb

8 files changed

Lines changed: 32 additions & 33 deletions

File tree

.github/workflows/web-api.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Run darker
2525
run: |
2626
pip install flake8
27-
pip install darker[isort]
27+
pip install darker[isort,black]
2828
darker . --check -i -L flake8
2929
3030
python-tests:
@@ -78,7 +78,7 @@ jobs:
7878
7979
- name: Install dependencies
8080
run: |
81-
pip install .
81+
pip install ".[tests]"
8282
8383
- name: Run integration and unit tests
8484
run: ./run-tests.sh --check-pytest

cap/modules/experiments/utils/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _batches(iterable, chunk_size=10):
137137
for _, g in groupby(iterable, lambda _: next(c) // chunk_size):
138138
yield g
139139

140-
if es.indices.exists(prefix_index('{}-v1'.format(alias))):
140+
if es.indices.exists(index=prefix_index('{}-v1'.format(alias))):
141141
old_index, new_index = (
142142
prefix_index('{}-v1'.format(alias)),
143143
prefix_index('{}-v2'.format(alias))
@@ -149,7 +149,7 @@ def _batches(iterable, chunk_size=10):
149149
)
150150

151151
# recreate new index
152-
if es.indices.exists(new_index):
152+
if es.indices.exists(index=new_index):
153153
es.indices.delete(index=new_index)
154154
es.indices.create(index=new_index,
155155
body=dict(mappings=mapping, settings=settings or {}))
@@ -175,5 +175,5 @@ def _batches(iterable, chunk_size=10):
175175
es.indices.put_alias(index=new_index, name=alias)
176176

177177
# remove old index
178-
if es.indices.exists(old_index):
178+
if es.indices.exists(index=old_index):
179179
es.indices.delete(index=old_index)

cap/modules/schemas/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,14 @@ def name_to_es_name(name):
510510
def create_index(index_name, mapping_body, aliases):
511511
"""Create index in opensearch, add under given aliases."""
512512
prefixed_index = prefix_index(index_name)
513-
if not es.indices.exists(prefixed_index):
513+
if not es.indices.exists(index=prefixed_index):
514514
current_search.mappings[prefixed_index] = {} # invenio search needs it
515515

516516
es.indices.create(index=prefixed_index, body=mapping_body, ignore=False)
517517

518518
for alias in aliases:
519519
es.indices.update_aliases(
520-
{'actions': [{'add': {'index': prefixed_index, 'alias': prefix_index(alias)}}]}
520+
body= {'actions': [{'add': {'index': prefixed_index, 'alias': prefix_index(alias)}}]}
521521
)
522522

523523

@@ -564,8 +564,8 @@ def before_delete_schema(mapper, connect, schema):
564564
prefix_index(schema.record_index),
565565
prefix_index(schema.deposit_index)
566566
):
567-
if es.indices.exists(index):
568-
es.indices.delete(index)
567+
if es.indices.exists(index=index):
568+
es.indices.delete(index=index)
569569

570570
# invenio search needs it
571571
mappings_imp = current_app.config.get('SEARCH_GET_MAPPINGS_IMP')

setup.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515

1616
tests_require = [
1717
'check-manifest>=0.35',
18-
# 'coverage>=5.2.1',
19-
# 'isort>=4.3',
20-
# 'mock>=2.0.0',
21-
# 'pydocstyle>=2.0.0',
22-
# 'pytest-cov==2.5.1',
23-
# 'pytest-invenio>=1.0.5,<=1.3.4',
24-
# 'pytest-mock>=1.6.0',
25-
# 'pytest-pep8>=1.0.6',
26-
# 'pytest-random-order>=0.5.4',
27-
# 'pytest==5.3.5',
28-
# 'responses==0.10.6',
2918
'pytest-cov>=3',
3019
'pytest>=7',
3120
'responses>=0.22.0',
@@ -37,15 +26,15 @@
3726
for reqs in extras_require.values():
3827
extras_require['all'].extend(reqs)
3928

40-
extras_require['ldap'] = ['python-ldap>=2.4.39']
29+
extras_require['ldap'] = ['python-ldap>=3.1.0']
4130

4231
# Do not include in all requirement
4332
extras_require['xrootd'] = [
4433
# 'invenio-xrootd>=1.0.0a6',
4534
# 'xrootdpyfs>=0.1.5',
4635
]
4736

48-
setup_requires = ['Babel>=2.4.0', 'pytest-runner>=3.0.0,<5']
37+
setup_requires = ['Babel>=2.4.0']
4938

5039
install_requires = [
5140
# CAP Base
@@ -266,7 +255,6 @@
266255
extras_require=extras_require,
267256
install_requires=install_requires,
268257
setup_requires=setup_requires,
269-
tests_require=tests_require,
270258
classifiers=[
271259
'Environment :: Web Environment',
272260
'Intended Audience :: Developers',

tests/integration/deposits/test_review_deposit.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,23 @@ def test_deposit_review_create_reviewable(
131131

132132
assert resp.status_code == 400
133133

134+
# comment without body should fail
134135
resp = client.post(f'/deposits/{reviewable_id}/actions/review',
135136
data=json.dumps({
136137
"id": review_item_id,
137138
"action": "comment"
138139
}),
139140
headers=default_headers + auth_headers_for_user(owner))
141+
assert resp.status_code == 400
142+
143+
# comment with body should succeed
144+
resp = client.post(f'/deposits/{reviewable_id}/actions/review',
145+
data=json.dumps({
146+
"id": review_item_id,
147+
"action": "comment",
148+
"body": "This is a comment"
149+
}),
150+
headers=default_headers + auth_headers_for_user(owner))
140151
assert resp.status_code == 201
141152

142153
resp = client.post(f'/deposits/{reviewable_id}/actions/review',

tests/integration/repos/test_upload_with_github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def get_file_contents(self, filepath, ref):
806806
body=file_tar,
807807
content_type='text/plain',
808808
headers={
809-
'Content-Length': '18',
809+
'Content-Length': str(len(file_tar)),
810810
'Content-Encoding': 'gzip'
811811
},
812812
stream=True,
@@ -858,7 +858,7 @@ def get_file_contents(self, filepath, ref):
858858
body=file_tar,
859859
content_type='text/plain',
860860
headers={
861-
'Content-Length': '18',
861+
'Content-Length': str(len(file_tar)),
862862
'Content-Encoding': 'gzip'
863863
},
864864
stream=True,

tests/unit/repos/test_repos_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_download_repo_file(deposit, file_tar):
7474
body=file_tar,
7575
content_type='text/plain',
7676
headers={
77-
'Content-Length': '18',
77+
'Content-Length': str(len(file_tar)),
7878
'Content-Encoding': 'gzip'
7979
},
8080
stream=True,
@@ -108,7 +108,7 @@ def test_download_repo_file_when_failed_creates_empty_file_object_with_failed_ta
108108
body=file_tar,
109109
content_type='text/plain',
110110
headers={
111-
'Content-Length': '18',
111+
'Content-Length': str(len(file_tar)),
112112
'Content-Encoding': 'gzip'
113113
},
114114
stream=True,

tests/unit/schemas/test_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ def test_on_save_mapping_is_created_and_index_name_added_to_mappings_map(
260260
)
261261
assert 'records-cms-schema-v1.0.0' in current_search.mappings.keys()
262262

263-
assert es.indices.exists(prefix_index('deposits-records-cms-schema-v1.0.0'))
264-
assert es.indices.exists(prefix_index('records-cms-schema-v1.0.0'))
263+
assert es.indices.exists(index=prefix_index('deposits-records-cms-schema-v1.0.0'))
264+
assert es.indices.exists(index=prefix_index('records-cms-schema-v1.0.0'))
265265

266-
assert es.indices.get_mapping(prefix_index('records-cms-schema-v1.0.0')) == {
266+
assert es.indices.get_mapping(index=prefix_index('records-cms-schema-v1.0.0')) == {
267267
prefix_index('records-cms-schema-v1.0.0'):
268268
{
269269
'mappings': {
@@ -276,7 +276,7 @@ def test_on_save_mapping_is_created_and_index_name_added_to_mappings_map(
276276
}
277277
}
278278

279-
assert es.indices.get_mapping(prefix_index('deposits-records-cms-schema-v1.0.0')) == {
279+
assert es.indices.get_mapping(index=prefix_index('deposits-records-cms-schema-v1.0.0')) == {
280280
prefix_index('deposits-records-cms-schema-v1.0.0'):
281281
{
282282
'mappings':
@@ -293,8 +293,8 @@ def test_on_save_mapping_is_created_and_index_name_added_to_mappings_map(
293293
db.session.delete(schema)
294294
db.session.commit()
295295

296-
assert not es.indices.exists(prefix_index('deposits-records-cms-schema-v1.0.0'))
297-
assert not es.indices.exists(prefix_index('records-cms-schema-v1.0.0'))
296+
assert not es.indices.exists(index=prefix_index('deposits-records-cms-schema-v1.0.0'))
297+
assert not es.indices.exists(index=prefix_index('records-cms-schema-v1.0.0'))
298298

299299
assert 'deposits-records-cms-schema-v1.0.0' not in current_search.mappings.keys(
300300
)

0 commit comments

Comments
 (0)