|
45 | 45 | from course_discovery.apps.course_metadata.utils import ( |
46 | 46 | calculated_seat_upgrade_deadline, clean_html, convert_svg_to_png_from_url, create_missing_entitlement, |
47 | 47 | download_and_save_course_image, download_and_save_program_image, ensure_draft_world, fetch_getsmarter_products, |
48 | | - generate_sku, is_google_drive_url, serialize_entitlement_for_ecommerce_api, serialize_seat_for_ecommerce_api, |
49 | | - transform_skills_data, validate_slug_format, is_fatal_error |
| 48 | + generate_sku, is_fatal_error, is_google_drive_url, serialize_entitlement_for_ecommerce_api, |
| 49 | + serialize_seat_for_ecommerce_api, transform_skills_data, validate_slug_format |
50 | 50 | ) |
51 | 51 |
|
52 | 52 |
|
@@ -1173,6 +1173,49 @@ def test_is_fatal_code(self): |
1173 | 1173 | assert not is_fatal_error(HttpClientError(response=response_with_429)) |
1174 | 1174 | assert not is_fatal_error(HttpClientError(response=response_with_504)) |
1175 | 1175 |
|
| 1176 | + def test_is_fatal_code_error(self): |
| 1177 | + # Success codes (2xx) should not be fatal error |
| 1178 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=201))) |
| 1179 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=204))) |
| 1180 | + |
| 1181 | + # Redirect codes (3xx) should not be fatal error |
| 1182 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=301))) |
| 1183 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=302))) |
| 1184 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=307))) |
| 1185 | + |
| 1186 | + # Retryable client error (429 Too Many Requests) already covered |
| 1187 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=429))) |
| 1188 | + |
| 1189 | + # Retryable server errors (5xx) should not be fatal |
| 1190 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=500))) |
| 1191 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=502))) |
| 1192 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=503))) |
| 1193 | + assert not is_fatal_error(HttpClientError(response=HttpResponse(status=504))) |
| 1194 | + |
| 1195 | + def test_is_fatal_code_positive(self): |
| 1196 | + # Client errors (4xx) that should be fatal |
| 1197 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=400))) # Bad Request |
| 1198 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=401))) # Unauthorized |
| 1199 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=403))) # Forbidden |
| 1200 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=404))) # Not Found |
| 1201 | + |
| 1202 | + # Other 4xx codes |
| 1203 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=410))) # Gone |
| 1204 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=422))) # Unprocessable Entity |
| 1205 | + |
| 1206 | + def test_is_fatal_code_additional(self): |
| 1207 | + # More client errors (4xx) that should be fatal |
| 1208 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=405))) # Method Not Allowed |
| 1209 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=406))) # Not Acceptable |
| 1210 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=407))) # Proxy Authentication Required |
| 1211 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=408))) # Request Timeout |
| 1212 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=409))) # Conflict |
| 1213 | + |
| 1214 | + # Validation-related errors |
| 1215 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=415))) # Unsupported Media Type |
| 1216 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=417))) # Expectation Failed |
| 1217 | + assert is_fatal_error(HttpClientError(response=HttpResponse(status=451))) # Unavailable For Legal Reason |
| 1218 | + |
1176 | 1219 | def mock_product_api_call(self): |
1177 | 1220 | """ |
1178 | 1221 | Mock product api with success response. |
@@ -1208,7 +1251,8 @@ def test_fetch_getsmarter_products__with_invalid_credentials(self, mock_getsmart |
1208 | 1251 | products = fetch_getsmarter_products() |
1209 | 1252 | mock_logger.assert_called_with(f'Failed to retrieve products from getsmarter API: {exception_message}') |
1210 | 1253 | assert products == [] |
1211 | | - |
| 1254 | + |
| 1255 | + |
1212 | 1256 | @ddt.ddt |
1213 | 1257 | class CourseSlugMethodsTests(TestCase): |
1214 | 1258 | """ |
|
0 commit comments