-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored code to make names consistent
- Loading branch information
Showing
10 changed files
with
67 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,48 +2,69 @@ | |
def test_search_saving(as_admin, data_builder): | ||
|
||
# Try posting a malformed search | ||
r = as_admin.post('/savesearch', json={"not-label":"random-string"}) | ||
r = as_admin.post('/savesearches', json={"not-label":"random-string"}) | ||
assert r.status_code == 400 | ||
|
||
# Try getting a non-existent saved search | ||
r = as_admin.get('/savesearch/000000000000000000000000') | ||
r = as_admin.get('/savesearches/000000000000000000000000') | ||
assert r.status_code == 404 | ||
|
||
# Save a search | ||
r = as_admin.post('/savesearch', json={'label': 'search1', 'search': {'return_type': 'session'}}) | ||
r = as_admin.post('/savesearches', json={'label': 'search1', 'search': {'return_type': 'session'}}) | ||
assert r.ok | ||
search = r.json()['_id'] | ||
|
||
# Get all searched user has access to | ||
r = as_admin.get('/savesearch') | ||
r = as_admin.get('/savesearches') | ||
assert r.ok | ||
|
||
# Get the saved search by id | ||
r = as_admin.get('/savesearch/' + search) | ||
r = as_admin.get('/savesearches/' + search) | ||
assert r.ok | ||
assert r.json()['label'] == 'search1' | ||
|
||
# Malformed search replace | ||
payload = {'label': 'good-label', 'search' : { 'not-return-type' : 'not-container'}} | ||
r = as_admin.post('/savesearch/' + search, json=payload) | ||
r = as_admin.post('/savesearches/' + search, json=payload) | ||
assert r.status_code == 400 | ||
|
||
# Replace search | ||
r = as_admin.get('/savesearch/' + search) | ||
r = as_admin.get('/savesearches/' + search) | ||
assert r.ok | ||
assert r.json()['label'] == 'search1' | ||
payload = r.json() | ||
payload['label'] = 'newSearch' | ||
r = as_admin.post('/savesearch/' + search, json=payload) | ||
r = as_admin.post('/savesearches/' + search, json=payload) | ||
assert r.ok | ||
assert r.json()['_id'] == search | ||
r = as_admin.get('/savesearch/' + search) | ||
r = as_admin.get('/savesearches/' + search) | ||
assert r.ok | ||
assert r.json()['label'] == 'newSearch' | ||
|
||
# Add permission to search | ||
r = as_admin.post('/savesearches/' + search + '/permissions', json={'access': 'admin', '_id': '[email protected]'}) | ||
assert r.ok | ||
r = as_admin.get('/savesearches/' + search) | ||
assert r.ok | ||
assert r.json()['permissions'][1]['_id'] == '[email protected]' | ||
|
||
# Modify permission | ||
r = as_admin.put('/savesearches/' + search + '/permissions/[email protected]', json={'access': 'ro'}) | ||
assert r.ok | ||
r = as_admin.get('/savesearches/' + search) | ||
assert r.ok | ||
assert r.json()['permissions'][1]['access'] == 'ro' | ||
|
||
# Remove permission | ||
r = as_admin.delete('/savesearches/' + search + '/permissions/[email protected]') | ||
assert r.ok | ||
r = as_admin.get('/savesearches/' + search) | ||
assert r.ok | ||
assert len(r.json()['permissions']) == 1 | ||
|
||
# Delete saved search | ||
r = as_admin.delete('/savesearch/' + search) | ||
r = as_admin.delete('/savesearches/' + search) | ||
assert r.ok | ||
r = as_admin.get('/savesearch') | ||
r = as_admin.get('/savesearches') | ||
assert r.ok | ||
assert len(r.json()) == 0 |