Skip to content

Commit

Permalink
fix: Fix Source matching query does not exist error (#4195)
Browse files Browse the repository at this point in the history
fix: fix quality issue and reviewer feedback

fix: broken test

fix: broken test

fix: broken test

fix: broken test

chore: reviewer feedback
  • Loading branch information
ziafazal authored Nov 27, 2023
1 parent 62cd7e6 commit 239c80d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion course_discovery/apps/course_metadata/data_loaders/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ class CoursesApiDataLoader(AbstractDataLoader):

def __init__(self, partner, api_url=None, max_workers=None, is_threadsafe=False, enable_api=True):
super().__init__(partner, api_url, max_workers, is_threadsafe, enable_api)
self.default_product_source = Source.objects.get(slug=settings.DEFAULT_PRODUCT_SOURCE_SLUG)
self.default_product_source, __ = Source.objects.get_or_create(
name=settings.DEFAULT_PRODUCT_SOURCE_NAME,
slug=settings.DEFAULT_PRODUCT_SOURCE_SLUG
)

def ingest(self):
logger.info('Refreshing Courses and CourseRuns from %s...', self.partner.courses_api_url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class CoursesApiDataLoaderTests(DataLoaderTestMixin, TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.default_product_source = SourceFactory(slug=settings.DEFAULT_PRODUCT_SOURCE_SLUG)
cls.non_default_product_source = SourceFactory(slug="not-default-product-source")

@property
Expand Down Expand Up @@ -181,7 +180,11 @@ def test_ingest(self, partner_uses_publisher, on_new_publisher, mock_logger):
course = Course.everything.get(key=f"{datum['org']}+{datum['number']}", draft=False)
mock_logger.info.assert_any_call(f"Course created with uuid {str(course.uuid)} and key {course.key}")
self.assert_course_run_loaded(datum, partner_uses_publisher, new_pub=on_new_publisher)
assert course.product_source == self.default_product_source
default_product_source = SourceFactory.create(
slug=settings.DEFAULT_PRODUCT_SOURCE_SLUG,
name=settings.DEFAULT_PRODUCT_SOURCE_NAME,
)
assert course.product_source.slug == default_product_source.slug

# Verify multiple calls to ingest data do NOT result in data integrity errors.
self.loader.ingest()
Expand Down
3 changes: 2 additions & 1 deletion course_discovery/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,8 @@
'INPUT_TAB_ID': '',
}

DEFAULT_PRODUCT_SOURCE_SLUG = ''
DEFAULT_PRODUCT_SOURCE_NAME = 'edX'
DEFAULT_PRODUCT_SOURCE_SLUG = 'edx'
EXTERNAL_PRODUCT_SOURCE_SLUG = ''

CONTENTFUL_SPACE_ID = None
Expand Down
1 change: 1 addition & 0 deletions course_discovery/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
'PRODUCTS_DETAILS_URL' : 'https://test-getsmarter.com/api/v1/products?detail=2',
}

DEFAULT_PRODUCT_SOURCE_NAME = 'Test Source'
DEFAULT_PRODUCT_SOURCE_SLUG = 'test-source'
EXTERNAL_PRODUCT_SOURCE_SLUG = 'external-test-source'

Expand Down

0 comments on commit 239c80d

Please sign in to comment.