Skip to content

Commit

Permalink
Merge pull request #27 from eddybl/fix-empty-search
Browse files Browse the repository at this point in the history
Fix empty search bug
  • Loading branch information
simongregorebner authored Apr 19, 2021
2 parents e9a0d27 + 69a8c54 commit e5789b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions elog/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ def search(self, search_term, n_results=20, scope="subtext"):
params.update(search_term)
else:
params.update({scope: search_term})

# Remove empty entries from params, since ELog will redirect such requests
# and remove them anyway, but the redirect leads to unexpected results
keys = list(params.keys())
for key in keys:
if params[key] == "":
params.pop(key)

try:
response = requests.get(self._url, params=params, headers=request_headers,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def test_search(self):
logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/')
ids = logbook.search("Powersupply")
print(ids)

def test_search_empty(self):
logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/')
ids = logbook.search("")
print(ids)

def test_search_dict(self):
logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/')
ids = logbook.search({"subtext": "Powersupply"})
print(ids)


if __name__ == '__main__':
Expand Down

0 comments on commit e5789b1

Please sign in to comment.