Skip to content

Commit bf7aaab

Browse files
committed
Merge branch 'master' into PROD-4437/edx-ingest-getsmarter-data-cron-job
2 parents dfdd168 + e519c28 commit bf7aaab

5 files changed

Lines changed: 55 additions & 118 deletions

File tree

.ci/docker-compose-ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ services:
2929
container_name: memcached
3030
discovery:
3131
# Uncomment this line to use the official course-discovery base image
32-
build:
33-
context: ../.
34-
target: dev
35-
args:
36-
PYTHON_VERSION: "${PYTHON_VERSION}"
32+
# build:
33+
# context: ../.
34+
# target: dev
35+
# args:
36+
# PYTHON_VERSION: "${PYTHON_VERSION}"
37+
image: edxops/discovery-dev:latest
3738
# Uncomment the next two lines to build from a local configuration repo
3839
# build: ../configuration/docker/build/discovery/
3940

.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

Dockerfile

Lines changed: 0 additions & 105 deletions
This file was deleted.

course_discovery/apps/course_metadata/tests/test_utils.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
from course_discovery.apps.course_metadata.utils import (
4646
calculated_seat_upgrade_deadline, clean_html, convert_svg_to_png_from_url, create_missing_entitlement,
4747
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
5050
)
5151

5252

@@ -1173,6 +1173,49 @@ def test_is_fatal_code(self):
11731173
assert not is_fatal_error(HttpClientError(response=response_with_429))
11741174
assert not is_fatal_error(HttpClientError(response=response_with_504))
11751175

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+
11761219
def mock_product_api_call(self):
11771220
"""
11781221
Mock product api with success response.
@@ -1208,7 +1251,8 @@ def test_fetch_getsmarter_products__with_invalid_credentials(self, mock_getsmart
12081251
products = fetch_getsmarter_products()
12091252
mock_logger.assert_called_with(f'Failed to retrieve products from getsmarter API: {exception_message}')
12101253
assert products == []
1211-
1254+
1255+
12121256
@ddt.ddt
12131257
class CourseSlugMethodsTests(TestCase):
12141258
"""

course_discovery/apps/course_metadata/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import backoff
21
import datetime
32
import logging
43
import random
@@ -9,6 +8,7 @@
98
from tempfile import NamedTemporaryFile
109
from urllib.parse import urljoin, urlparse
1110

11+
import backoff
1212
import html2text
1313
import jsonschema
1414
import markdown
@@ -1014,7 +1014,7 @@ def transform_skills_data(skills_data):
10141014
# any requests that failed in both limits are still approaching their max_tries limit.
10151015
@backoff.on_exception(
10161016
backoff.expo,
1017-
(requests.exceptions.Timeout,requests.exceptions.HTTPError),
1017+
(requests.exceptions.Timeout, requests.exceptions.HTTPError),
10181018
factor=60,
10191019
max_tries=4,
10201020
giveup=is_fatal_error,

0 commit comments

Comments
 (0)