11"""Tests for ETL loaders"""
22
3- from datetime import datetime , timedelta
3+ from datetime import timedelta
44from decimal import Decimal
55from pathlib import Path
66
@@ -382,7 +382,7 @@ def test_load_program_bad_platform(mocker):
382382@pytest .mark .parametrize ("delivery" , [LearningResourceDelivery .hybrid .name , None ])
383383@pytest .mark .parametrize ("has_upcoming_run" , [True , False ])
384384@pytest .mark .parametrize ("has_departments" , [True , False ])
385- def test_load_course ( # noqa: PLR0913, PLR0912, PLR0915
385+ def test_load_course ( # noqa: PLR0913,PLR0912,PLR0915, C901
386386 mock_upsert_tasks ,
387387 course_exists ,
388388 is_published ,
@@ -498,9 +498,10 @@ def test_load_course( # noqa: PLR0913, PLR0912, PLR0915
498498 assert result .professional is True
499499
500500 if is_published and is_run_published and not blocklisted :
501- assert result .next_start_date == start_date
502- else :
503- assert result .next_start_date is None
501+ if has_upcoming_run :
502+ assert result .next_start_date == start_date
503+ else :
504+ assert result .next_start_date .date () == now .date ()
504505 assert result .prices == (
505506 [Decimal ("0.00" ), Decimal ("49.00" )]
506507 if is_run_published and result .certification
@@ -1747,17 +1748,15 @@ def test_load_run_dependent_values(certification):
17471748 course = LearningResourceFactory .create (
17481749 is_course = True , certification = certification , runs = []
17491750 )
1750- assert course .runs .count () == 0
17511751 closest_date = now_in_utc () + timedelta (days = 1 )
17521752 furthest_date = now_in_utc () + timedelta (days = 2 )
1753- best_run = LearningResourceRunFactory .create (
1753+ run = LearningResourceRunFactory .create (
17541754 learning_resource = course ,
17551755 published = True ,
17561756 availability = Availability .dated .name ,
17571757 prices = [Decimal ("0.00" ), Decimal ("20.00" )],
17581758 resource_prices = LearningResourcePriceFactory .create_batch (2 ),
17591759 start_date = closest_date ,
1760- enrollment_start = None ,
17611760 location = "Portland, ME" ,
17621761 duration = "3 - 4 weeks" ,
17631762 min_weeks = 3 ,
@@ -1773,7 +1772,6 @@ def test_load_run_dependent_values(certification):
17731772 prices = [Decimal ("0.00" ), Decimal ("50.00" )],
17741773 resource_prices = LearningResourcePriceFactory .create_batch (2 ),
17751774 start_date = furthest_date ,
1776- enrollment_start = None ,
17771775 location = "Portland, OR" ,
17781776 duration = "7 - 9 weeks" ,
17791777 min_weeks = 7 ,
@@ -1783,23 +1781,15 @@ def test_load_run_dependent_values(certification):
17831781 max_weekly_hours = 19 ,
17841782 )
17851783 result = load_run_dependent_values (course )
1786- course .refresh_from_db ()
1787- assert (
1788- result .prices == course .prices == ([] if not certification else best_run .prices )
1789- )
1790- assert (
1791- result .next_start_date
1792- == course .next_start_date
1793- == best_run .start_date
1794- == closest_date
1795- )
1784+ assert result .next_start_date == course .next_start_date == closest_date
1785+ assert result .prices == course .prices == ([] if not certification else run .prices )
17961786 assert (
17971787 list (result .resource_prices )
17981788 == list (course .resource_prices .all ())
1799- == ([] if not certification else list (best_run .resource_prices .all ()))
1789+ == ([] if not certification else list (run .resource_prices .all ()))
18001790 )
18011791 assert result .availability == course .availability == Availability .dated .name
1802- assert result .location == course .location == best_run .location
1792+ assert result .location == course .location == run .location
18031793 for key in [
18041794 "duration" ,
18051795 "time_commitment" ,
@@ -1808,7 +1798,7 @@ def test_load_run_dependent_values(certification):
18081798 "min_weekly_hours" ,
18091799 "max_weekly_hours" ,
18101800 ]:
1811- assert getattr (result , key ) == getattr (course , key ) == getattr (best_run , key )
1801+ assert getattr (result , key ) == getattr (course , key ) == getattr (run , key )
18121802
18131803
18141804def test_load_run_dependent_values_resets_next_start_date ():
@@ -1839,43 +1829,6 @@ def test_load_run_dependent_values_resets_next_start_date():
18391829 assert course .next_start_date is None
18401830
18411831
1842- @pytest .mark .parametrize (
1843- ("start_dt" , "enrollnment_start" , "expected_next" ),
1844- [
1845- ("2025-01-01T10:00:00Z" , "2024-12-15T10:00:00Z" , "2025-01-01T10:00:00Z" ),
1846- ("2025-01-01T10:00:00Z" , None , "2025-01-01T10:00:00Z" ),
1847- (None , "2024-12-15T10:00:00Z" , "2024-12-15T10:00:00Z" ),
1848- (None , None , None ),
1849- ],
1850- )
1851- def test_load_run_dependent_values_next_start_date (
1852- start_dt , enrollnment_start , expected_next
1853- ):
1854- """Test that next_start_date is correctly set from the best_run"""
1855- course = LearningResourceFactory .create (is_course = True , published = True , runs = [])
1856-
1857- # Create multiple runs with different start dates
1858- LearningResourceRunFactory .create (
1859- learning_resource = course ,
1860- published = True ,
1861- start_date = datetime .fromisoformat (start_dt ) if start_dt else None ,
1862- enrollment_start = datetime .fromisoformat (enrollnment_start )
1863- if enrollnment_start
1864- else None ,
1865- )
1866-
1867- # Call load_run_dependent_values
1868- result = load_run_dependent_values (course )
1869-
1870- # Refresh course from database
1871- course .refresh_from_db ()
1872-
1873- # Verify that next_start_date matches the earliest run's start date
1874- assert result .next_start_date == (
1875- datetime .fromisoformat (expected_next ) if expected_next else None
1876- )
1877-
1878-
18791832@pytest .mark .parametrize (
18801833 ("is_scholar_course" , "tag_counts" , "expected_score" ),
18811834 [
0 commit comments