Skip to content

Commit 510c942

Browse files
committed
Testing and bug fixes
1 parent 0b36b7f commit 510c942

File tree

12 files changed

+111
-85
lines changed

12 files changed

+111
-85
lines changed

apache/syftorium.wsgi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
22
sys.path.append('/opt/lifemapper/')
33

4-
from flask_app.application import create_app
4+
from flask_app.application import create_app # noqa: E402
55
application = create_app()

flask_app/resolver/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Solr configuration parameters."""
2-
import os
2+
33

44
SOLR_SERVER = 'http://localhost'
55
SOLR_PORT = 8983

flask_app/resolver/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Models for Resolver."""
22

3+
34
# .....................................................................................
45
class Ark:
56
"""Class containing Ark information."""

flask_app/sp_cache/process_dwca.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def post_results(post_recs, collection_id, mod_time):
5757
these records.
5858
mod_time (tuple): A tuple of year, month, day modification time.
5959
"""
60-
solr_response = controller.update_collection_occurrences(collection_id, post_recs)
60+
_ = controller.update_collection_occurrences(collection_id, post_recs)
6161
resolver_recs = []
6262
for rec in post_recs:
6363
url = '{}api/v1/sp_cache/collection/{}/specimens/{}'.format(
@@ -218,7 +218,7 @@ def process_dwca_directory(in_directory, out_directory):
218218
process_dwca(dwca_filename, collection_id)
219219
shutil.move(
220220
dwca_filename,
221-
os.path.join(out_directory,os.path.basename(dwca_filename))
221+
os.path.join(out_directory, os.path.basename(dwca_filename))
222222
)
223223
except Exception as err:
224224
print('Failed to process {}, {}'.format(dwca_filename, err))

flask_app/sp_cache/routes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def collection_occurrences_modify(collection_id):
8787
8888
Args:
8989
collection_id (str): An identifier associated with these specimens.
90+
91+
Returns:
92+
tuple: Tuple of empty string and 204 indicating successful delete.
9093
"""
9194
if request.method.lower() in ['post', 'put']:
9295
# Write data to file system for another process to pick up and handle

flask_app/sp_cache/solr_controller.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def delete_collection_occurrences(collection_id, identifiers):
110110
"""
111111
sp_solr = get_specimen_solr()
112112
sp_solr.delete(
113-
q=['collection_id:{}'.format(collection_id),'identiifer:{}'.format(identifier)]
113+
q=[
114+
'collection_id:{}'.format(collection_id),
115+
'identiifer:{}'.format(identifiers)
116+
]
114117
)
115118

116119

@@ -127,7 +130,10 @@ def get_specimen(collection_id, identifier):
127130
"""
128131
sp_solr = get_specimen_solr()
129132
rec = sp_solr.search(
130-
q=['collection_id:{}'.format(collection_id),'identiifer:{}'.format(identifier)]
133+
q=[
134+
'collection_id:{}'.format(collection_id),
135+
'identiifer:{}'.format(identifier)
136+
]
131137
)
132138
if rec.hits > 0:
133139
return SpecimenRecord(rec.docs[0])

lm_tests/sp_cache_tests.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,29 @@ def __init__(self, collection_values_json, collection_endpoint):
2525

2626
# .............................
2727
def __repr__(self):
28-
"""Return a string representation of this test."""
28+
"""Return a string representation of this test.
29+
30+
Returns:
31+
str: A string representation of the instance.
32+
"""
2933
return self.test_name
3034

3135
# .............................
3236
def run_test(self):
33-
"""Run the test."""
37+
"""Run the test.
38+
39+
Raises:
40+
LmTestFailure: Raised if a collection exists when it shouldn't.
41+
"""
3442
collection_id = self.collection_config['collection_id']
3543
# Make sure that the collection doesn't exist
36-
try:
37-
requests.get('{}/{}'.format(self.collection_endpoint, collection_id))
38-
raise ValueError(
39-
'Found collection: {} when it should not exist (1)'.format(
44+
req = requests.get('{}/{}'.format(self.collection_endpoint, collection_id))
45+
if req.status_code != 404:
46+
raise test_base.LmTestFailure(
47+
'Found collection: {} when it should not exist (before_post)'.format(
4048
collection_id
4149
)
4250
)
43-
except requests.NotFound:
44-
pass
4551

4652
# POST the collection
4753
requests.post(self.collection_endpoint, json=self.collection_config)
@@ -50,20 +56,22 @@ def run_test(self):
5056
collection_get_response = requests.get(
5157
'{}/{}'.format(self.collection_endpoint, collection_id)
5258
)
59+
if collection_get_response.status_code != 200:
60+
raise test_base.LmTestFailure(
61+
'Collection {} not found when expected.'.format(collection_id)
62+
)
5363

5464
# DELETE the collection
5565
requests.delete('{}/{}'.format(self.collection_endpoint, collection_id))
5666

5767
# Make sure that the collection is gone again
58-
try:
59-
requests.get('{}/{}'.format(self.collection_endpoint, collection_id))
60-
raise ValueError(
61-
'Found collection: {} when it should not exist (2)'.format(
68+
req = requests.get('{}/{}'.format(self.collection_endpoint, collection_id))
69+
if req.status_code != 404:
70+
raise test_base.LmTestFailure(
71+
'Found collection: {} when it should not exist (after delete)'.format(
6272
collection_id
6373
)
6474
)
65-
except requests.NotFound:
66-
pass
6775

6876

6977
# .....................................................................................
@@ -87,12 +95,20 @@ def __init__(self, dwca_filename, occurrence_endpoint):
8795

8896
# .............................
8997
def __repr__(self):
90-
"""Return a string representation of this test."""
98+
"""Return a string representation of this test.
99+
100+
Returns:
101+
str: A string representation of the instance.
102+
"""
91103
return self.test_name
92104

93105
# .............................
94106
def run_test(self):
95-
"""Run the test."""
107+
"""Run the test.
108+
109+
Raises:
110+
LmTestFailure: Raised if the data cannot be posted successfully.
111+
"""
96112
with open(self.dwca_filename, mode='rb') as dwca_file:
97113
data = dwca_file.read()
98114
resp = requests.post(self.occurrence_endpoint, data=data)

lm_tests/spcache_collection_lmtest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"public_key": "blah blah blah"
1414
}
1515
}
16-
}
16+
}

lm_tests/spcache_collection_occurrences_lmtest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"occurrence_endpoint": "https://notyeti-195.lifemapper.org/api/v1/sp_cache/collection/test_collection/occurrences/",
66
"dwca_filename": "/DATA/envs/lmtest/test_data/dwc_update.zip"
77
}
8-
}
8+
}

solr_cores/spcoco/conf/schema.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<schema name="spcoco" version="0.1">
3-
4-
3+
4+
55
<!-- =========================================== -->
66
<!-- Recommended fields for Solr -->
77
<!-- =========================================== -->
@@ -11,20 +11,20 @@
1111
<!-- Specify resolver fields -->
1212
<!-- =========================================== -->
1313
<field name="dataset_guid" type="string" indexed="true" stored="true" />
14-
14+
1515
<!-- ARK metadata -->
1616
<!-- similar to DC Creator, Contributor, Publisher -->
1717
<!-- DWC institutionCode -->
1818
<field name="who" type="string" indexed="true" stored="true" />
19-
19+
2020
<!-- similar to DC Title -->
2121
<!-- DWC basisOfRecord -->
2222
<field name="what" type="string" indexed="true" stored="true" />
23-
23+
2424
<!-- similar to DC Date -->
2525
<!-- DWC yyyy-mm-dd (concatenated fields) -->
2626
<field name="when" type="string" indexed="true" stored="true" />
27-
27+
2828
<!-- similar to DC Identifier, optional as this is the ARK -->
2929
<!-- ARK pointing to Specify resolver -->
3030
<field name="where" type="string" indexed="true" stored="true" />
@@ -33,11 +33,11 @@
3333
<!-- redirection URL -->
3434
<!-- URL pointing to Specify API -->
3535
<field name="url" type="string" indexed="true" stored="true" />
36-
36+
3737
<!-- =========================================== -->
3838
<!-- Recommended fields for Solr -->
3939
<!-- =========================================== -->
40-
<uniqueKey>id</uniqueKey>
40+
<uniqueKey>id</uniqueKey>
4141

4242
<!-- =========================================== -->
4343
<!-- Field types -->
@@ -49,7 +49,7 @@
4949
<fieldType name="multistring" class="solr.StrField" sortMissingLast="true" />
5050
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0" />
5151
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0" />
52-
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0" />
52+
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0" />
5353
<fieldType name="boolean" class="solr.BoolField" omitNorms="true" />
5454

5555
</schema>

0 commit comments

Comments
 (0)