|
| 1 | +from os import getenv |
1 | 2 | from jokeapi import Jokes |
| 3 | +from dotenv import load_dotenv |
| 4 | +load_dotenv() |
2 | 5 |
|
3 | 6 | j = Jokes() |
4 | 7 | errors = [] |
| 8 | +token = getenv("token") |
| 9 | + |
5 | 10 |
|
6 | 11 | try: |
7 | 12 | j.get_joke() |
8 | 13 | except Exception as e: |
9 | 14 | errors.append({'Error in': 'blank joke get', 'Error': e}) |
10 | 15 |
|
| 16 | +"""Testing auth tokens""" |
| 17 | +try: |
| 18 | + j.get_joke(auth_token=token) |
| 19 | +except Exception as e: |
| 20 | + auth_token = None |
| 21 | + errors.append({'Error in': 'auth usage', 'Error': e}) |
| 22 | + |
11 | 23 | """Testing for errors in categories""" |
12 | 24 | try: |
13 | | - j.get_joke(category=["programming"]) |
| 25 | + j.get_joke(category=["programming"], auth_token=token) |
14 | 26 | except Exception as e: |
15 | 27 | errors.append({'Error in': 'category programming', 'Error': e}) |
16 | 28 | try: |
17 | | - j.get_joke(category=["miscellaneous"]) |
| 29 | + j.get_joke(category=["miscellaneous"], auth_token=token) |
18 | 30 | except Exception as e: |
19 | 31 | errors.append({'Error in': 'category miscellaneous', 'Error': e}) |
20 | 32 | try: |
21 | | - j.get_joke(category=["dark"]) |
| 33 | + j.get_joke(category=["dark"], auth_token=token) |
22 | 34 | except Exception as e: |
23 | 35 | errors.append({'Error in': 'category dark', 'Error': e}) |
24 | 36 |
|
25 | 37 | """Testing for errors in blacklist""" |
26 | 38 | try: |
27 | | - j.get_joke(blacklist=["nsfw"]) |
| 39 | + j.get_joke(blacklist=["nsfw"], auth_token=token) |
28 | 40 | except Exception as e: |
29 | 41 | errors.append({'Error in': 'blacklist nsfw', 'Error': e}) |
30 | 42 | try: |
31 | | - j.get_joke(blacklist=["religious"]) |
| 43 | + j.get_joke(blacklist=["religious"], auth_token=token) |
32 | 44 | except Exception as e: |
33 | 45 | errors.append({'Error in': 'blacklist religious', 'Error': e}) |
34 | 46 | try: |
35 | | - j.get_joke(blacklist=["political"]) |
| 47 | + j.get_joke(blacklist=["political"], auth_token=token) |
36 | 48 | except Exception as e: |
37 | 49 | errors.append({'Error in': 'blacklist political', 'Error': e}) |
38 | 50 | try: |
39 | | - j.get_joke(blacklist=["racist"]) |
| 51 | + j.get_joke(blacklist=["racist"], auth_token=token) |
40 | 52 | except Exception as e: |
41 | 53 | errors.append({'Error in': 'blacklist political', 'Error': e}) |
42 | 54 | try: |
43 | | - j.get_joke(blacklist=["sexist"]) |
| 55 | + j.get_joke(blacklist=["sexist"], auth_token=token) |
44 | 56 | except Exception as e: |
45 | 57 | errors.append({'Error in': 'blacklist sexist', 'Error': e}) |
46 | 58 |
|
47 | 59 | """Testing for errors in response_format""" |
48 | 60 | try: |
49 | | - j.get_joke(response_format="xml") |
| 61 | + j.get_joke(response_format="xml", auth_token=token) |
50 | 62 | except Exception as e: |
51 | 63 | errors.append({'Error in': 'response_format xml', 'Error': e}) |
52 | 64 | try: |
53 | | - j.get_joke(response_format="yaml") |
| 65 | + j.get_joke(response_format="yaml", auth_token=token) |
54 | 66 | except Exception as e: |
55 | 67 | errors.append({'Error in': 'response_format yaml', 'Error': e}) |
56 | 68 |
|
57 | 69 | """Testing for errors in type""" |
58 | 70 | try: |
59 | | - j.get_joke(type="single") |
| 71 | + j.get_joke(type="single", auth_token=token) |
60 | 72 | except Exception as e: |
61 | 73 | errors.append({'Error in': 'type single', 'Error': e}) |
62 | 74 | try: |
63 | | - j.get_joke(type="twopart") |
| 75 | + j.get_joke(type="twopart", auth_token=token) |
64 | 76 | except Exception as e: |
65 | 77 | errors.append({'Error in': 'type double', 'Error': e}) |
66 | 78 |
|
67 | 79 | """Testing for errors in search_string""" |
68 | 80 | try: |
69 | | - j.get_joke(search_string="search") |
| 81 | + j.get_joke(search_string="search", auth_token=token) |
70 | 82 | # as long as this gets a response, the api wrapper is fine; |
71 | 83 | # it probably doesn't exist in a joke. |
72 | 84 | except Exception as e: |
73 | 85 | errors.append({'Error in': 'search_string', 'Error': e}) |
74 | 86 |
|
75 | 87 | """Testing for errors in id_range""" |
76 | 88 | try: |
77 | | - j.get_joke(id_range=[30, 151]) |
| 89 | + j.get_joke(id_range=[30, 151], auth_token=token) |
78 | 90 | except Exception as e: |
79 | 91 | errors.append({'Error in': 'id_range', 'Error': e}) |
80 | 92 |
|
81 | 93 | if len(errors): |
82 | 94 | for e in errors: |
83 | 95 | print(f"Error in: {e['Error in']}\nError: {e['Error']}") |
84 | | - raise Exception("Errors boii") |
| 96 | + if len(errors) == 1: |
| 97 | + raise Exception("1 error occured") |
| 98 | + |
| 99 | + raise Exception(f"{len(errors)} errors occurred") |
0 commit comments