Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila committed Oct 9, 2024
1 parent d0bfa72 commit c324dde
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ class CSVLoaderMixin:
'upgrade_deadline_override_date', 'upgrade_deadline_override_time', 'redirect_url', 'external_identifier',
'lead_capture_form_url', 'organic_url', 'certificate_header', 'certificate_text', 'stat1', 'stat1_text',
'stat2', 'stat2_text', 'organization_logo_override', 'organization_short_code_override', 'variant_id',
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type', 'fixed_price_usd'
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type', 'fixed_price_usd',
'post_submit_url', 'taxi_form_id'
]
# The list of minimal data headers
MINIMAL_CSV_DATA_KEYS_ORDER = [
Expand Down Expand Up @@ -374,6 +375,8 @@ class CSVLoaderMixin:
"meta_title": "SEO Title",
"meta_description": "SEO Description",
"meta_keywords": ["Keyword 1", "Keyword 2"],
"taxi_form_id": "test-form-id",
"post_submit_url": "https://www.getsmarter.com/blog/career-advice"
}

BASE_EXPECTED_COURSE_RUN_DATA = {
Expand Down Expand Up @@ -523,6 +526,8 @@ def _assert_course_data(self, course, expected_data):
) == set(expected_data['meta_keywords'])
assert course.additional_metadata.registration_deadline.isoformat() == expected_data['registration_deadline']
assert course.additional_metadata.certificate_info.heading == expected_data['certificate_info']['heading']
assert course.additional_metadata.taxi_form.form_id == expected_data['taxi_form_id']
assert course.additional_metadata.taxi_form.post_submit_url == expected_data['post_submit_url']
assert expected_data['certificate_info']['blurb'] in course.additional_metadata.certificate_info.blurb
assert sorted([subject.slug for subject in course.subjects.all()]) == sorted(expected_data['subjects'])
assert sorted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3234,7 +3234,9 @@
"meta_keywords": "Keyword 1, Keyword 2",
"slug": "",
'external_course_marketing_type': "short_course",
"fixed_price_usd": "123.4"
"fixed_price_usd": "123.4",
"post_submit_url": "https://www.getsmarter.com/blog/career-advice",
"taxi_form_id": "test-form-id"
}

VALID_MINIMAL_COURSE_AND_COURSE_RUN_CSV_DICT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from course_discovery.apps.course_metadata.data_loaders.tests import mock_data
from course_discovery.apps.course_metadata.data_loaders.tests.mixins import CSVLoaderMixin
from course_discovery.apps.course_metadata.models import (
AdditionalMetadata, Course, CourseEntitlement, CourseRun, CourseType, Seat, Source
AdditionalMetadata, Course, CourseEntitlement, CourseRun, CourseType, Seat, Source, TaxiForm
)
from course_discovery.apps.course_metadata.tests.factories import (
AdditionalMetadataFactory, CourseFactory, CourseRunFactory, CourseTypeFactory, OrganizationFactory, SourceFactory
Expand Down Expand Up @@ -279,6 +279,8 @@ def test_single_valid_row(self, csv_slug, expected_slug, jwt_decode_patch): # p
assert course.active_url_slug == expected_slug
assert course.official_version.active_url_slug == expected_slug

assert TaxiForm.objects.count() == 1

assert loader.get_ingestion_stats() == {
'total_products_count': 1,
'success_count': 1,
Expand Down Expand Up @@ -670,7 +672,7 @@ def test_ingest_flow_for_preexisting_unpublished_course(self, jwt_decode_patch):
)

with NamedTemporaryFile() as csv:
csv = self._write_csv(csv, [{**mock_data.VALID_COURSE_AND_COURSE_RUN_CSV_DICT, "fixed_price_usd": ""}])
csv = self._write_csv(csv, [{**mock_data.VALID_COURSE_AND_COURSE_RUN_CSV_DICT, "fixed_price_usd": "", "taxi_form_id": ""}])
with LogCapture(LOGGER_PATH) as log_capture:
with mock.patch.object(
CSVDataLoader,
Expand All @@ -697,6 +699,7 @@ def test_ingest_flow_for_preexisting_unpublished_course(self, jwt_decode_patch):
# Verify the existence of draft and non-draft
assert Course.everything.count() == 2
assert CourseRun.everything.count() == 2
assert TaxiForm.objects.count() == 0

course = Course.everything.get(key=self.COURSE_KEY, partner=self.partner, draft=True)
course_run = CourseRun.everything.get(course=course, draft=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class TestPopulateExecutiveEducationDataCsv(CSVLoaderMixin, TestCase):
"metaKeywords": "Keyword 1, Keyword 2",
"slug": "csv-course-slug",
"productType": "short_course",
"prospectusUrl": "aHR0cHM6Ly93d3cuZ2V0c21hcnRlci5jb20vYmxvZy9jYXJlZXItYWR2aWNl",
"edxTaxiFormId": "test-form-id",
"variant": {
"id": "00000000-0000-0000-0000-000000000000",
"endDate": "2022-05-06",
Expand Down Expand Up @@ -140,6 +142,7 @@ class TestPopulateExecutiveEducationDataCsv(CSVLoaderMixin, TestCase):
SUCCESS_API_RESPONSE_V2 = copy.deepcopy(SUCCESS_API_RESPONSE)
SUCCESS_API_RESPONSE_V2['products'][0].pop('variant')
SUCCESS_API_RESPONSE_V2["products"][0].update({"variants": [variant_1, variant_2,]})
SUCCESS_API_RESPONSE_V2["products"][0].update({"taxi_form_id": None})

def mock_product_api_call(self, override_product_api_response=None):
"""
Expand Down Expand Up @@ -219,6 +222,8 @@ def test_successful_file_data_population_with_getsmarter_flag_with_multiple_vari
assert data_row['Verified Price'] == str(self.variant_1['finalPrice'])
assert data_row['Restriction Type'] == 'custom-b2b-enterprise'
assert data_row['Fixed Price Usd'] == '3510.0'
assert data_row['Taxi Form Id'] == ''
assert data_row['Post Submit Url'] == 'https://www.getsmarter.com/blog/career-advice'

data_row = next(reader)
assert data_row['Variant Id'] == self.variant_2['id']
Expand All @@ -231,6 +236,8 @@ def test_successful_file_data_population_with_getsmarter_flag_with_multiple_vari
assert data_row['Verified Price'] == str(self.variant_2['finalPrice'])
assert data_row['Restriction Type'] == 'None'
assert data_row['Fixed Price Usd'] == ''
assert data_row['Taxi Form Id'] == ''
assert data_row['Post Submit Url'] == 'https://www.getsmarter.com/blog/career-advice'

log_capture.check_present(
(
Expand Down Expand Up @@ -478,3 +485,5 @@ def _assert_api_response(self, data_row):
assert data_row['Slug'] == 'csv-course-slug'
assert data_row['External Course Marketing Type'] == "short_course"
assert data_row['Fixed Price Usd'] == "333.3"
assert data_row['Taxi Form Id'] == 'test-form-id'
assert data_row['Post Submit Url'] == 'https://www.getsmarter.com/blog/career-advice'

0 comments on commit c324dde

Please sign in to comment.