|
| 1 | +from jokeapi import Jokes |
| 2 | + |
| 3 | +j = Jokes() |
| 4 | +errors = [] |
| 5 | + |
| 6 | +try: |
| 7 | + j.get_joke() |
| 8 | +except Exception as e: |
| 9 | + errors.append({'Error in': 'blank joke get', 'Error':e}) |
| 10 | + |
| 11 | +"""Testing for errors in categories""" |
| 12 | +try: j.get_joke(category=["programming"]) |
| 13 | +except Exception as e: errors.append({'Error in': 'category programming','Error':e}) |
| 14 | +try: j.get_joke(category=["miscellaneous"]) |
| 15 | +except Exception as e: errors.append({'Error in': 'category miscellaneous','Error':e}) |
| 16 | +try: j.get_joke(category=["dark"]) |
| 17 | +except Exception as e: errors.append({'Error in': 'category dark','Error':e}) |
| 18 | + |
| 19 | +"""Testing for errors in blacklist""" |
| 20 | +try: j.get_joke(blacklist=["nsfw"]) |
| 21 | +except Exception as e: errors.append({'Error in': 'blacklist nsfw','Error':e}) |
| 22 | +try: j.get_joke(blacklist=["religious"]) |
| 23 | +except Exception as e: errors.append({'Error in': 'blacklist religious','Error':e}) |
| 24 | +try: j.get_joke(blacklist=["political"]) |
| 25 | +except Exception as e: errors.append({'Error in': 'blacklist political','Error':e}) |
| 26 | +try: j.get_joke(blacklist=["racist"]) |
| 27 | +except Exception as e: errors.append({'Error in': 'blacklist political','Error':e}) |
| 28 | +try: j.get_joke(blacklist=["sexist"]) |
| 29 | +except Exception as e: errors.append({'Error in': 'blacklist sexist', 'Error':e}) |
| 30 | + |
| 31 | +"""Testing for errors in response_format""" |
| 32 | +try: j.get_joke(response_format="xml") |
| 33 | +except Exception as e: errors.append({'Error in': 'response_format xml','Error':e}) |
| 34 | +try: j.get_joke(response_format="yaml") |
| 35 | +except Exception as e: errors.append({'Error in': 'response_format yaml','Error':e}) |
| 36 | + |
| 37 | +"""Testing for errors in type""" |
| 38 | +try: j.get_joke(type="single") |
| 39 | +except Exception as e: errors.append({'Error in': 'type single','Error':e}) |
| 40 | +try: j.get_joke(type="twopart") |
| 41 | +except Exception as e: errors.append({'Error in': 'type double','Error':e}) |
| 42 | + |
| 43 | +"""Testing for errors in search_string""" |
| 44 | +try: j.get_joke(search_string="search") #as long as this gets a response, the api wrapper is fine; it probably doesn't exist in a joke |
| 45 | +except Exception as e: errors.append({'Error in':'search_string','Error':e}) |
| 46 | + |
| 47 | +"""Testing for errors in id_range""" |
| 48 | +try: j.get_joke(id_range=[30,151]) |
| 49 | +except Exception as e: errors.append({'Error in':'id_range','Error':e}) |
| 50 | + |
| 51 | +if len(errors): |
| 52 | + for e in errors: |
| 53 | + print(f"Error in: {e['Error in']}\nError:{e['Error']}") |
| 54 | + raise Exception("Errors boii") |
0 commit comments