|
13 | 13 |
|
14 | 14 | pytestmark = pytest.mark.asyncio |
15 | 15 |
|
16 | | -async def test_main(): |
| 16 | + |
| 17 | +async def test_blank(): |
| 18 | + j = await Jokes() |
| 19 | + await j.get_joke(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 20 | + |
| 21 | +async def test_auth_tokens(): |
| 22 | + j = await Jokes() |
| 23 | + token = getenv("token") |
| 24 | + await j.get_joke(auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 25 | + |
| 26 | +async def test_categories(): |
| 27 | + j = await Jokes() |
| 28 | + token = getenv("token") |
| 29 | + await j.get_joke(category=["programming"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 30 | + await j.get_joke(category=["misc"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 31 | + await j.get_joke(category=["dark"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 32 | + |
| 33 | +async def test_blacklist(): |
| 34 | + j = await Jokes() |
| 35 | + token = getenv("token") |
| 36 | + await j.get_joke(blacklist=["nsfw"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 37 | + |
| 38 | + await j.get_joke(blacklist=["religious"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 39 | + await j.get_joke(blacklist=["political"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 40 | + await j.get_joke(blacklist=["racist"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 41 | + await j.get_joke(blacklist=["sexist"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 42 | + |
| 43 | +async def test_repsonse_format(): |
| 44 | + j = await Jokes() |
| 45 | + token = getenv("token") |
| 46 | + await j.get_joke(response_format="xml", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 47 | + |
| 48 | + await j.get_joke(response_format="yaml", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 49 | + |
| 50 | +async def test_joke_type(): |
17 | 51 | j = await Jokes() |
18 | | - errors = [] |
19 | 52 | token = getenv("token") |
| 53 | + await j.get_joke(joke_type="single", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 54 | + await j.get_joke(joke_type="twopart", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
20 | 55 |
|
21 | | - try: |
22 | | - await j.get_joke(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
23 | | - except Exception as e: |
24 | | - _, __, exc_traceback = sys.exc_info() |
25 | | - errors.append({"Error in": "blank joke get", "Error": traceback.extract_tb(exc_traceback)}) |
26 | | - |
27 | | - """Testing auth tokens""" |
28 | | - try: |
29 | | - await j.get_joke(auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
30 | | - except Exception as e: |
31 | | - _, __, exc_traceback = sys.exc_info() |
32 | | - auth_token = None |
33 | | - errors.append({"Error in": "auth usage", "Error": traceback.extract_tb(exc_traceback)}) |
34 | | - |
35 | | - """Testing for errors in categories""" |
36 | | - try: |
37 | | - await j.get_joke(category=["programming"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
38 | | - except Exception as e: |
39 | | - _, __, exc_traceback = sys.exc_info() |
40 | | - errors.append({"Error in": "category programming", "Error": traceback.extract_tb(exc_traceback)}) |
41 | | - try: |
42 | | - await j.get_joke(category=["misc"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
43 | | - except Exception as e: |
44 | | - _, __, exc_traceback = sys.exc_info() |
45 | | - errors.append({"Error in": "category miscellaneous", "Error": traceback.extract_tb(exc_traceback)}) |
46 | | - try: |
47 | | - await j.get_joke(category=["dark"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
48 | | - except Exception as e: |
49 | | - _, __, exc_traceback = sys.exc_info() |
50 | | - errors.append({"Error in": "category dark", "Error": traceback.extract_tb(exc_traceback)}) |
51 | | - |
52 | | - """Testing for errors in blacklist""" |
53 | | - try: |
54 | | - await j.get_joke(blacklist=["nsfw"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
55 | | - except Exception as e: |
56 | | - _, __, exc_traceback = sys.exc_info() |
57 | | - errors.append({"Error in": "blacklist nsfw", "Error": traceback.extract_tb(exc_traceback)}) |
58 | | - |
59 | | - try: |
60 | | - await j.get_joke(blacklist=["religious"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
61 | | - except Exception as e: |
62 | | - _, __, exc_traceback = sys.exc_info() |
63 | | - errors.append({"Error in": "blacklist religious", "Error": traceback.extract_tb(exc_traceback)}) |
64 | | - |
65 | | - try: |
66 | | - await j.get_joke(blacklist=["political"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
67 | | - except Exception as e: |
68 | | - _, __, exc_traceback = sys.exc_info() |
69 | | - errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb(exc_traceback)}) |
70 | | - |
71 | | - try: |
72 | | - await j.get_joke(blacklist=["racist"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
73 | | - except Exception as e: |
74 | | - _, __, exc_traceback = sys.exc_info() |
75 | | - errors.append({"Error in": "blacklist political", "Error": traceback.extract_tb(exc_traceback)}) |
76 | | - |
77 | | - try: |
78 | | - await j.get_joke(blacklist=["sexist"], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
79 | | - except Exception as e: |
80 | | - _, __, exc_traceback = sys.exc_info() |
81 | | - errors.append({"Error in": "blacklist sexist", "Error": traceback.extract_tb(exc_traceback)}) |
82 | | - |
83 | | - """Testing for errors in response_format""" |
84 | | - try: |
85 | | - await j.get_joke(response_format="xml", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
86 | | - except Exception as e: |
87 | | - _, __, exc_traceback = sys.exc_info() |
88 | | - errors.append({"Error in": "response_format xml", "Error": traceback.extract_tb(exc_traceback)}) |
89 | | - |
90 | | - try: |
91 | | - await j.get_joke(response_format="yaml", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
92 | | - except Exception as e: |
93 | | - _, __, exc_traceback = sys.exc_info() |
94 | | - errors.append({"Error in": "response_format yaml", "Error": traceback.extract_tb(exc_traceback)}) |
95 | | - |
96 | | - """Testing for errors in type""" |
97 | | - try: |
98 | | - await j.get_joke(joke_type="single", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
99 | | - except Exception as e: |
100 | | - _, __, exc_traceback = sys.exc_info() |
101 | | - errors.append({"Error in": "type single", "Error": traceback.extract_tb(exc_traceback)}) |
102 | | - |
103 | | - try: |
104 | | - await j.get_joke(joke_type="twopart", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
105 | | - except Exception as e: |
106 | | - _, __, exc_traceback = sys.exc_info() |
107 | | - errors.append({"Error in": "type double", "Error": traceback.extract_tb(exc_traceback)}) |
108 | | - |
109 | | - """Testing for errors in search_string""" |
110 | | - try: |
111 | | - await j.get_joke(search_string="search", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 56 | +async def test_search_string(): |
| 57 | + j = await Jokes() |
| 58 | + token = getenv("token") |
| 59 | + await j.get_joke(search_string="search", auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
112 | 60 | # as long as this gets a response, the api wrapper is fine; |
113 | 61 | # it probably doesn't exist in a joke. |
114 | | - except Exception as e: |
115 | | - _, __, exc_traceback = sys.exc_info() |
116 | | - errors.append({"Error in": "search_string", "Error": traceback.extract_tb(exc_traceback)}) |
117 | | - |
118 | | - """Testing for errors in id_range""" |
119 | | - try: |
120 | | - await j.get_joke(id_range=[30, 151], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
121 | | - except Exception as e: |
122 | | - _, __, exc_traceback = sys.exc_info() |
123 | | - errors.append({"Error in": "id_range", "Error": traceback.extract_tb(exc_traceback)}) |
124 | | - |
125 | | - """Testing for errors in safe_mode""" |
126 | | - try: |
127 | | - await j.get_joke(safe_mode=True, auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
128 | | - except Exception as e: |
129 | | - _, __, exc_traceback = sys.exc_info() |
130 | | - errors.append({"Error in": "safe_mode", "Error": traceback.extract_tb(exc_traceback)}) |
131 | | - |
132 | | - """Testing for errors in user agent""" |
133 | | - try: |
134 | | - await j.get_joke(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
135 | | - except Exception as e: |
136 | | - _, __, exc_traceback = sys.exc_info() |
137 | | - errors.append({"Error in": "user agent", "Error": traceback.extract_tb(exc_traceback)}) |
138 | | - |
139 | | - |
140 | | - """ Testing jokeapi.submit_joke() """ |
141 | | - try: |
142 | | - await j.submit_joke("Programming", ["foo", "bar"], {}, dry_run=True) |
143 | | - except Exception as e: |
144 | | - _, __, exc_traceback = sys.exc_info() |
145 | | - errors.append({"Error in": "dry_run", "Error": traceback.extract_tb(exc_traceback)}) |
146 | | - |
147 | | - |
148 | | - if len(errors): |
149 | | - for e in errors: |
150 | | - print(f"Error in: {e['Error in']}\nError: {e['Error']}") |
151 | | - if len(errors) == 1: |
152 | | - raise Exception("1 error occured") |
153 | | - |
154 | | - raise Exception(f"{len(errors)} errors occurred") |
| 62 | + |
| 63 | +async def test_id_range(): |
| 64 | + j = await Jokes() |
| 65 | + token = getenv("token") |
| 66 | + await j.get_joke(id_range=[30, 151], auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 67 | + |
| 68 | +async def test_safe_mode(): |
| 69 | + j = await Jokes() |
| 70 | + token = getenv("token") |
| 71 | + |
| 72 | + await j.get_joke(safe_mode=True, auth_token=token, user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 73 | + |
| 74 | +async def test_user_agent(): |
| 75 | + j = await Jokes() |
| 76 | + token = getenv("token") |
| 77 | + await j.get_joke(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/91.0.4472.164 Safari/537.36") |
| 78 | + |
| 79 | + |
| 80 | +async def test_submit_joke(): |
| 81 | + j = await Jokes() |
| 82 | + token = getenv("token") |
| 83 | + await j.submit_joke("Programming", ["foo", "bar"], {}, dry_run=True) |
0 commit comments