@@ -193,6 +193,22 @@ def read_json(file_path):
193193 )
194194
195195
196+ @pytest .fixture
197+ def mitpe_offeror_and_topics (mocker ):
198+ """Create the MIT Professional Education offeror and 2 topics"""
199+ offeror = LearningResourceOfferorFactory .create (code = "mitpe" )
200+ LearningResourceTopicMappingFactory .create (
201+ offeror = offeror ,
202+ topic = LearningResourceTopicFactory .create (name = "Product Innovation" ),
203+ topic_name = "Technology Innovation" ,
204+ )
205+ LearningResourceTopicMappingFactory .create (
206+ offeror = offeror ,
207+ topic = LearningResourceTopicFactory .create (name = "Data Science" ),
208+ topic_name = "Data Science" ,
209+ )
210+
211+
196212@pytest .mark .parametrize ("prof_ed_api_url" , ["http://pro_edd_api.com" , None ])
197213def test_extract (settings , mock_fetch_data , prof_ed_api_url ):
198214 """Test extract function"""
@@ -213,23 +229,22 @@ def test_extract(settings, mock_fetch_data, prof_ed_api_url):
213229
214230
215231@pytest .mark .django_db
216- def test_transform (mock_fetch_data ):
232+ def test_transform (mock_fetch_data , mitpe_offeror_and_topics ):
217233 """Test transform function, and effectively most other functions"""
218- offeror = LearningResourceOfferorFactory .create (code = "mitpe" )
219- LearningResourceTopicMappingFactory .create (
220- offeror = offeror ,
221- topic = LearningResourceTopicFactory .create (name = "Product Innovation" ),
222- topic_name = "Technology Innovation" ,
223- )
224- LearningResourceTopicMappingFactory .create (
225- offeror = offeror ,
226- topic = LearningResourceTopicFactory .create (name = "Data Science" ),
227- topic_name = "Data Science" ,
228- )
229234 extracted = mitpe .extract ()
230235 assert len (extracted ) == 3
231236 courses , programs = mitpe .transform (extracted )
232237 assert_json_equal (
233238 sorted (courses , key = lambda course : course ["readable_id" ]), EXPECTED_COURSES
234239 )
235240 assert_json_equal (programs , EXPECTED_PROGRAMS )
241+
242+
243+ @pytest .mark .django_db
244+ def test_transform__course_no_run_ids (mock_fetch_data , mitpe_offeror_and_topics ):
245+ """Resources with no run IDs should not be published"""
246+ extracted = mitpe .extract ()
247+ assert len (extracted ) == 3
248+ for resource in extracted :
249+ resource ["run__readable_id" ] = ""
250+ assert mitpe .transform (extracted ) == ([], [])
0 commit comments