def test_update_fails_with_multiple_errors(self, course_data, expected_error_message): course = CourseFactory(partner=self.partner, key='Org/Course/Number') url = reverse('api:v1:course-detail', kwargs={'key': course.uuid}) mode1 = SeatTypeFactory(name='Mode1') SeatTypeFactory(name='Mode2') CourseEntitlementFactory(course=course, mode=mode1, sku=None) response = self.client.patch(url, course_data, format='json') self.assertEqual(response.status_code, 400) self.assertEqual(response.data, expected_error_message)
def test_update_existing_program_type(self): fixture = json_serializer.Serializer().serialize([ self.organization, self.seat_type_verified, self.program_type_masters, self.program, ]) self._mock_fixture_response(fixture) self.reset_db_state() # set DB to have a conflicting program type on load seat_type = SeatTypeFactory( name='Something', slug='something', ) existing_program_type = ProgramTypeFactory( name='Masters', slug='masters', applicable_seat_types=[seat_type]) self._call_load_program_fixture([str(self.program.uuid)]) stored_program = Program.objects.get(uuid=self.program.uuid) # assert existing DB value is used stored_program_type = stored_program.type self.assertEqual(stored_program_type, existing_program_type) # assert existing DB value is updated to match fixture stored_seat_types = list( stored_program_type.applicable_seat_types.all()) self.assertEqual(len(stored_seat_types), 1) self.assertEqual(stored_seat_types[0].name, self.seat_type_verified.name)
def setUp(self): super().setUp() self.pk_generator = itertools.count(1) stored_site, created = Site.objects.get_or_create( # pylint: disable=unused-variable domain='example.com') self.default_partner = Partner.objects.create(site=stored_site, name='edX', short_code='edx') SeatType.objects.all().delete() ProgramType.objects.all().delete() self.partner = PartnerFactory(name='Test') self.organization = OrganizationFactory(partner=self.partner) self.seat_type_verified = SeatTypeFactory(name='Verified', slug='verified') self.program_type_masters = ProgramTypeFactory( name='Masters', name_t='Masters', slug='masters', applicable_seat_types=[self.seat_type_verified]) self.program_type_masters_translation = self.program_type_masters.translations.all( )[0] self.program_type_mm = ProgramTypeFactory( name='MicroMasters', name_t='MicroMasters', slug='micromasters', applicable_seat_types=[self.seat_type_verified]) self.program_type_mm_translation = self.program_type_mm.translations.all( )[0] self.course = CourseFactory( partner=self.partner, authoring_organizations=[self.organization]) self.course_run = CourseRunFactory(course=self.course) self.program = ProgramFactory( type=self.program_type_masters, partner=self.partner, authoring_organizations=[self.organization]) self.course_mm = CourseFactory( partner=self.partner, authoring_organizations=[self.organization]) self.course_run_mm = CourseRunFactory(course=self.course) self.program_mm = ProgramFactory( type=self.program_type_mm, partner=self.partner, authoring_organizations=[self.organization], courses=[self.course_mm]) self.curriculum = CurriculumFactory(program=self.program) self.curriculum_course_membership = CurriculumCourseMembershipFactory( course=self.course, curriculum=self.curriculum) self.curriculum_program_membership = CurriculumProgramMembershipFactory( program=self.program_mm, curriculum=self.curriculum) self.program_2 = ProgramFactory( type=self.program_type_masters, partner=self.partner, authoring_organizations=[self.organization]) self._mock_oauth_request()
def setUp(self): super().setUp() self.user = UserFactory() self.staff = UserFactory(username='******', is_staff=True) seat_type = SeatTypeFactory(name="TestSeatType") self.program_type = ProgramTypeFactory( name="TestProgramType", slug="test-program-type", applicable_seat_types=[seat_type], )
def _set_up_masters_program_type(self): """ Set DB to have a conflicting program type on load. """ seat_type = SeatTypeFactory( name='Something', slug='something', ) existing_program_type = ProgramTypeFactory( name='Masters', name_t='Masters', slug='masters', applicable_seat_types=[seat_type]) return existing_program_type