Created
September 1, 2022 20:26
-
-
Save mekarpeles/4772247c8d2dc2ad3f86dbc422ff7d12 to your computer and use it in GitHub Desktop.
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
import requests | |
""" | |
- ✅ Show English editions of each | |
- ✅ Show IA editions of each | |
- ✅ Show most readable edition | |
- ❌ They should be in order of publication | |
- ✅ searching for "chambre des secrets" should | |
- ✅ Show HP2 somewhere | |
- ✅ Show French HP2 edition/title | |
- ✅ Show most readable HP2 edition | |
- ❌ Show HP2 as first result (TODO: Add phrase) | |
- ❌Searching for "Three body problem" should | |
- ❌(3) Show "Three body problem" as first result | |
- ✅ Show English edition | |
- ✅ Show readable edition | |
- Searching for "kleine hobbit" should | |
- ✅* Should show (OL262758W, OL24374464M) in top spot across all user locales | |
- Searching for "heartstopper" should | |
- Should minimize the position of the heartstopper books | |
- ❌ Show them in order | |
- ❌ Show the previewable copies of Volume 1 | |
- ✅ Show the previewable copy of volume 2 | |
""" | |
endpoint = "https://a10c-216-154-29-219.ngrok.io/search.json" | |
def test_harry_potter(): | |
tests = [] | |
r = requests.get(endpoint, params={ | |
"q": "harry potter" | |
}) | |
docs = r.json()['docs'][:7] | |
expected_keys = { | |
"/works/OL82563W","/works/OL82577W","/works/OL82537W", | |
"/works/OL82565W","/works/OL82536W","/works/OL82586W","/works/OL82548W" | |
} | |
actual_keys = set(doc.get('key') for doc in docs) | |
tests.append({ | |
"pass": actual_keys == expected_keys, | |
"desc": f"Search for \"harry potter\" returns all 7 harry potter books" | |
}) | |
tests.append({ | |
"desc": 'All english "harry potter" editions are present', | |
"pass": all("eng" in doc['editions']['docs'][0]['language'] for doc in docs) | |
}) | |
return "test_harry_potter", tests, all(t["pass"] for t in tests) | |
if __name__ == "__main__": | |
tests = [test_harry_potter] | |
states = {True: "✅", False: "❌"} | |
for test in tests: | |
test_name, results, success = test() | |
print(f"{states[success]} {test_name}:") | |
for result in results: | |
print(f" {states[result['pass']]} {result['desc']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment