def test_parse_course_atomic(self): """ Test that parsing a course is atomic. """ data = dict(self.COURSE1_DATA) data.update(course_runs=[{}]) with self.assertRaises(KeyError): parse_course(self.site, data) self.assertEqual(Course.objects.all().count(), 0) self.assertEqual(CourseRun.objects.all().count(), 0) self.assertEqual(Organization.objects.all().count(), 0)
def test_parse_program(self, data, vals, org_keys_expected, run_keys_expected, err): """ Test parsing a single program with one course/run. """ if err: with self.assertRaises(err): parse_course(self.site, data) else: program = parse_program(self.site, data) self.assertEqual(Program.objects.all().count(), 1) self.assertEqual(program, Program.objects.get(site=self.site, **vals)) # Check runs run_keys = [c.key for c in program.course_runs.all()] self.assertListEqual(run_keys, run_keys_expected) self.assertEqual(CourseRun.objects.all().count(), len(run_keys)) # Check orgs org_keys = [o.key for o in program.authoring_organizations.all()] self.assertListEqual(org_keys, org_keys_expected) self.assertEqual(Organization.objects.all().count(), len(org_keys))
def test_parse_course(self, data, vals, org_keys_expected, run_keys_expected, err): """ Test parsing a single course with a course run. """ if err: with self.assertRaises(err): parse_course(self.site, data) else: course, course_runs = parse_course(self.site, data) self.assertEqual(Course.objects.all().count(), 1) self.assertEqual(course, Course.objects.get(site=self.site, **vals)) # Check runs run_keys = [c.key for c in course.course_runs.all()] self.assertListEqual(run_keys, run_keys_expected) self.assertEqual(CourseRun.objects.all().count(), len(run_keys)) self.assertListEqual(list(course.course_runs.all()), course_runs) # Check orgs org_keys = [o.key for o in course.owners.all()] self.assertListEqual(org_keys, org_keys_expected) self.assertEqual(Organization.objects.all().count(), len(org_keys))