Beispiel #1
0
 def setUp(self):
     super().setUp()
     # Disable marketing site password just to save us from having to mock the responses
     self.partner = factories.PartnerFactory(
         marketing_site_api_password=None)
     self.person = factories.PersonFactory(partner=self.partner,
                                           given_name='Person')
     self.target = factories.PersonFactory(partner=self.partner,
                                           given_name='Target')
     self.instructor1 = factories.PersonFactory(partner=self.partner,
                                                given_name='Instructor1')
     self.instructor2 = factories.PersonFactory(partner=self.partner,
                                                given_name='Instructor2')
     self.instructor3 = factories.PersonFactory(partner=self.partner,
                                                given_name='Instructor3')
     self.position = factories.PositionFactory(person=self.person)
     self.social1 = factories.PersonSocialNetworkFactory(person=self.person)
     self.social2 = factories.PersonSocialNetworkFactory(person=self.person)
     self.endorsement = factories.EndorsementFactory(endorser=self.person)
     self.course = factories.CourseFactory(partner=self.partner)
     self.courserun1 = factories.CourseRunFactory(course=self.course,
                                                  staff=[
                                                      self.instructor1,
                                                      self.person,
                                                      self.instructor2,
                                                      self.instructor3,
                                                  ])
     self.courserun2 = factories.CourseRunFactory(course=self.course,
                                                  staff=[
                                                      self.instructor1,
                                                      self.instructor2,
                                                      self.person,
                                                      self.instructor3,
                                                  ])
     self.program = factories.ProgramFactory(courses=[self.course],
                                             instructor_ordering=[
                                                 self.person,
                                                 self.instructor1,
                                                 self.instructor2,
                                                 self.instructor3,
                                             ])
     self.publisher_course = publisher_factories.CourseFactory()
     self.publisher_courserun1 = publisher_factories.CourseRunFactory(
         course=self.publisher_course,
         staff=[
             self.person,
             self.instructor1,
             self.instructor2,
             self.instructor3,
         ])
     self.publisher_courserun2 = publisher_factories.CourseRunFactory(
         course=self.publisher_course,
         staff=[
             self.instructor1,
             self.instructor2,
             self.instructor3,
             self.person,
         ])
    def setUp(self):
        super(AutoCompletePersonTests, self).setUp()
        self.user = UserFactory(is_staff=True)
        self.client.login(username=self.user.username, password=USER_PASSWORD)
        self.courses = factories.CourseFactory.create_batch(
            3, title='Some random course title')

        for course in self.courses:
            factories.CourseRunFactory(course=course)

        self.organizations = OrganizationFactory.create_batch(3)
        self.organization_extensions = []

        for organization in self.organizations:
            self.organization_extensions.append(
                factories.OrganizationExtensionFactory(
                    organization=organization))

        self.user.groups.add(self.organization_extensions[0].group)
        first_instructor = PersonFactory(given_name="First",
                                         family_name="Instructor")
        second_instructor = PersonFactory(given_name="Second",
                                          family_name="Instructor")
        self.instructors = [first_instructor, second_instructor]

        for instructor in self.instructors:
            PositionFactory(organization=self.organizations[0],
                            title="professor",
                            person=instructor)
Beispiel #3
0
    def test_discovery_counterpart_success(self):
        """
        Verify that CourseRun discovery_counterpart property returns
        corresponding Discovery CourseRun object.
        """
        pacing_type_test_value = 'test_pacing_type_value'

        # create a fresh course run object to avoid issues with caching of discovery_counterpart property
        course_run = factories.CourseRunFactory()
        organization = OrganizationFactory()

        discovery_course = self.create_discovery_course_with_partner(organization.partner)
        discovery_course_run = self.create_discovery_course_run_with_metadata(
            discovery_course,
            {'pacing_type': pacing_type_test_value}
        )

        self.add_organization_to_course(course_run.course, organization)

        # make sure Publisher course key and Course Metadata course key match
        course_run.course.key = discovery_course.key
        # make sure Publisher course run key and Course Metadata course run key match
        course_run.lms_course_id = discovery_course_run.key

        assert course_run.discovery_counterpart == discovery_course_run
Beispiel #4
0
    def setUp(self):
        super(CourseRunWrapperTests, self).setUp()
        organization = OrganizationFactory()
        self.course_run = factories.CourseRunFactory(course__organizations=[organization])
        self.course = self.course_run.course

        self.wrapped_course_run = CourseRunWrapper(self.course_run)
    def test_course_runs(self):
        """ Verify that property returns queryset of course runs. """
        self.assertEqual(self.course.course_runs.count(), 0)

        factories.CourseRunFactory(course=self.course)

        self.assertEqual(self.course.course_runs.count(), 1)
    def test_short_description_override(self):
        """ Verify that the property returns the short_description. """
        self.assertEqual(self.course.short_description, self.course.course_short_description)

        course_run = factories.CourseRunFactory(course=self.course)
        factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
        self.assertEqual(self.course.course_short_description, course_run.short_description_override)
 def test_organization_key(self):
     """ Verify that the wrapper return the organization key. """
     organization = OrganizationFactory()
     course_run = factories.CourseRunFactory(
         course__organizations=[organization])
     wrapped_course_run = CourseRunWrapper(course_run)
     self.assertEqual(wrapped_course_run.organization_key, organization.key)
    def test_title_override(self):
        """ Verify that the property returns the title. """
        self.assertEqual(self.course.title, self.course.course_title)

        course_run = factories.CourseRunFactory(course=self.course)
        factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
        self.assertEqual(self.course.course_title, course_run.title_override)
Beispiel #9
0
    def test_pacing_type_temporary_display(self):
        """
        Verify that pacing_type_temporary display function returns the
        value of the pacing_type field display function.
        """
        # create a fresh course run object to avoid issues with caching of discovery_counterpart property
        course_run = factories.CourseRunFactory()

        assert course_run.get_pacing_type_temporary_display() == course_run.get_pacing_type_display()
Beispiel #10
0
    def test_find_discovery_course(self):
        cm_run1 = cm_factories.CourseRunFactory(
            course__partner=self.course.partner)
        cm_run2 = cm_factories.CourseRunFactory(
            course__partner=self.course.partner)
        pub_run1 = factories.CourseRunFactory(course=self.course,
                                              lms_course_id=cm_run1.key)
        pub_run2 = factories.CourseRunFactory(course=self.course,
                                              lms_course_id=cm_run2.key)
        pub_run_no_id = factories.CourseRunFactory(course=self.course)
        pub_run_no_siblings = factories.CourseRunFactory()

        assert find_discovery_course(pub_run1) == cm_run1.course
        assert find_discovery_course(pub_run2) == cm_run2.course
        assert find_discovery_course(
            pub_run_no_id
        ) == cm_run2.course  # Most recent sibling run's course
        assert find_discovery_course(pub_run_no_siblings) is None
Beispiel #11
0
    def test_end_date_temporary_setter(self):
        """Verify that modifying the end_date_temporary property also modifies the end field."""
        end_date_test_value = FuzzyDateTime(datetime.datetime(2014, 1, 1, tzinfo=UTC))

        # create a fresh course run object to avoid issues with caching of discovery_counterpart property
        course_run = factories.CourseRunFactory()

        course_run.end_date_temporary = end_date_test_value

        assert course_run.end_date_temporary == course_run.end
Beispiel #12
0
    def setUp(self):
        super(CourseRunWrapperTests, self).setUp()
        self.course_run = factories.CourseRunFactory()
        self.course = self.course_run.course
        organization = OrganizationFactory()

        self.course.organizations.add(organization)
        self.course.save()

        self.wrapped_course_run = CourseRunWrapper(self.course_run)
Beispiel #13
0
    def test_pacing_type_temporary_setter(self):
        """
        Verify that modifying the pacing_type_temporary property also modifies the pacing_type field."""
        pacing_type_test_value = 'test_pacing_type_value'

        # create a fresh course run object to avoid issues with caching of discovery_counterpart property
        course_run = factories.CourseRunFactory()

        course_run.pacing_type_temporary = pacing_type_test_value

        assert course_run.pacing_type_temporary == course_run.pacing_type
Beispiel #14
0
    def test_organization_key(self):
        """ Verify that the wrapper return the organization key. """
        course = factories.CourseFactory()
        course_run = factories.CourseRunFactory(course=course)
        wrapped_course_run = CourseRunWrapper(course_run)
        self.assertEqual(wrapped_course_run.organization_key, None)

        organization = OrganizationFactory()
        course.organizations.add(organization)
        wrapped_course_run = CourseRunWrapper(course_run)
        self.assertEqual(wrapped_course_run.organization_key, organization.key)
Beispiel #15
0
    def test_discovery_counterpart_failure_without_course(self):
        """
        Verify that CourseRun discovery_counterpart property returns None if the
        discovery_counterpart does not exist.
        """
        # create a fresh course run object to avoid issues with caching of discovery_counterpart property
        course_run = factories.CourseRunFactory()
        organization = OrganizationFactory()

        self.add_organization_to_course(course_run.course, organization)

        assert course_run.discovery_counterpart is None
Beispiel #16
0
    def setUp(self):
        super(AdminTests, self).setUp()
        self.user = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=self.user.username, password=USER_PASSWORD)
        self.course_run = factories.CourseRunFactory(changed_by=self.user, lms_course_id='')
        self.run_state = factories.CourseRunStateFactory(
            course_run=self.course_run
        )
        self.change_url = reverse('admin:publisher_courserun_add')
        self.form = self.client.get(self.change_url)

        self.assertFalse(CourseRun.objects.filter(lms_course_id__isnull=True).exists())
Beispiel #17
0
    def setUp(self):
        super(StudioInstanceCreatedEmailTests, self).setUp()
        self.user = UserFactory()

        self.group = factories.GroupFactory()
        self.user.groups.add(self.group)

        self.course_run = factories.CourseRunFactory()

        assign_perm(Course.VIEW_PERMISSION, self.group, self.course_run.course)

        UserAttributeFactory(user=self.user, enable_email_notification=True)

        toggle_switch('enable_publisher_email_notifications', True)
Beispiel #18
0
    def test_update_course_key_with_duplicate(self):
        """
        Test that api returns error if course key already exist.
        """
        lms_course_id = 'course-v1:edxTest+TC12+2050Q1'
        factories.CourseRunFactory(lms_course_id=lms_course_id)

        response = self.client.patch(self.update_course_run_url,
                                     data=json.dumps(
                                         {'lms_course_id': lms_course_id}),
                                     content_type=JSON_CONTENT_TYPE)

        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.data.get('lms_course_id'),
                         ['CourseRun with this lms course id already exists.'])
Beispiel #19
0
    def test_discovery_counterpart_failure_without_course_run(self):
        """
        Verify that CourseRun discovery_counterpart property returns None if the
        discovery_counterpart course has no course run associated with it.
        """
        # create a fresh course run object to avoid issues with caching of discovery_counterpart property
        course_run = factories.CourseRunFactory()
        organization = OrganizationFactory()

        discovery_course = self.create_discovery_course_with_partner(organization.partner)

        self.add_organization_to_course(course_run.course, organization)

        # make sure Publisher course key and Course Metadata course key match
        course_run.course.key = discovery_course.key

        assert course_run.discovery_counterpart is None
Beispiel #20
0
    def setUp(self):
        super(CourseCreatedEmailTests, self).setUp()
        self.user = UserFactory()
        self.course_run = factories.CourseRunFactory()

        # add user in course-user-role table
        factories.CourseUserRoleFactory(
            course=self.course_run.course,
            role=PublisherUserRole.ProjectCoordinator,
            user=self.user)

        self.course_team = UserFactory()
        factories.CourseUserRoleFactory(course=self.course_run.course,
                                        role=PublisherUserRole.CourseTeam,
                                        user=self.course_team)

        UserAttributeFactory(user=self.user, enable_email_notification=True)
    def setUp(self):
        super(StudioInstanceCreatedEmailTests, self).setUp()
        self.user = UserFactory()
        self.course_run = factories.CourseRunFactory(
            lms_course_id='course-v1:edX+DemoX+Demo_Course')

        # add user in course-user-role table
        factories.CourseUserRoleFactory(
            course=self.course_run.course,
            role=PublisherUserRole.ProjectCoordinator,
            user=self.user)

        self.course_team = UserFactory()
        factories.CourseUserRoleFactory(course=self.course_run.course,
                                        role=PublisherUserRole.CourseTeam,
                                        user=self.course_team)

        UserAttributeFactory(user=self.user, enable_email_notification=True)

        toggle_switch('enable_publisher_email_notifications', True)
    def test_course_image_url(self):
        """ Verify that the property returns the course image url. """
        self.assertIsNone(self.course.course_image_url)

        # Create a published course-run with card_image_url.
        course_run = factories.CourseRunFactory(course=self.course)
        factories.CourseRunStateFactory(course_run=course_run,
                                        name=CourseRunStateChoices.Published)
        course_run.card_image_url = 'http://example.com/test.jpg'
        course_run.save()

        # Verify that property returns card_image_url of course-run.
        self.assertEqual(self.course.course_image_url,
                         course_run.card_image_url)

        # Create a course image.
        self.course.image = make_image_file('test_banner1.jpg')
        self.course.save()

        # Verify that property returns course image field url.
        self.assertEqual(self.course.course_image_url, self.course.image.url)
Beispiel #23
0
    def setUp(self):
        super(UpdateCourseRunsTests, self).setUp()

        self.update_command_name = 'update_publisher_course_runs'
        # create multiple course-runs against course.

        self.metadata_course_runs = []
        self.publisher_runs = []
        # add metadata course-runs and add publisher course runs
        for i in range(1, 3):
            course_run = CourseRunFactory(
                short_description_override='short description {}'.format(i),
                full_description_override='full description {}'.format(i),
                title_override='title {}'.format(i)
            )

            self.metadata_course_runs.append(course_run)
            self.publisher_runs.append(factories.CourseRunFactory(lms_course_id=course_run.key))

        self.command_args = [
            '--start_id={}'.format(self.publisher_runs[0].id), '--end_id={}'.format(self.publisher_runs[-1].id)
        ]
    def setUp(self):
        super(UpdateCourseRunViewTests, self).setUp()
        self.course_run = factories.CourseRunFactory()
        self.user = UserFactory()
        self.user.groups.add(Group.objects.get(name=INTERNAL_USER_GROUP_NAME))

        self.organization_extension = factories.OrganizationExtensionFactory()
        self.course_run.course.organizations.add(self.organization_extension.organization)

        self.update_course_run_url = reverse(
            'publisher:api:update_course_run', kwargs={'pk': self.course_run.id}
        )

        factories.CourseUserRoleFactory(
            role=PublisherUserRole.ProjectCoordinator,
            course=self.course_run.course,
            user=self.user
        )

        factories.UserAttributeFactory(user=self.user, enable_email_notification=True)
        toggle_switch('enable_publisher_email_notifications', True)
        self.client.login(username=self.user.username, password=USER_PASSWORD)
Beispiel #25
0
    def setUpClass(cls):
        super().setUpClass()
        cls.user = UserFactory(is_staff=True)
        cls.courses = factories.CourseFactory.create_batch(
            3, title='Some random course title')

        first_instructor = PersonFactory(given_name="First",
                                         family_name="Instructor")
        second_instructor = PersonFactory(given_name="Second",
                                          family_name="Instructor")
        cls.instructors = [first_instructor, second_instructor]

        cls.organizations = OrganizationFactory.create_batch(3)
        cls.organization_extensions = []

        for instructor in cls.instructors:
            PositionFactory(organization=cls.organizations[0],
                            title="professor",
                            person=instructor)

        cls.course_runs = [
            factories.CourseRunFactory(course=course) for course in cls.courses
        ]

        for organization in cls.organizations:
            cls.organization_extensions.append(
                factories.OrganizationExtensionFactory(
                    organization=organization))

        disco_course = CourseFactory(
            authoring_organizations=[cls.organizations[0]])
        disco_course2 = CourseFactory(
            authoring_organizations=[cls.organizations[1]])
        CourseRunFactory(course=disco_course, staff=[first_instructor])
        CourseRunFactory(course=disco_course2, staff=[second_instructor])

        cls.user.groups.add(cls.organization_extensions[0].group)
Beispiel #26
0
    def test_end_date_temporary(self):
        """Verify that end_date_temporary property returns the value of the end field."""
        # create a fresh course run object to avoid issues with caching of discovery_counterpart property
        course_run = factories.CourseRunFactory()

        assert course_run.end_date_temporary == course_run.end
 def setUpClass(cls):
     super(CourseRunTests, cls).setUpClass()
     cls.course_run = factories.CourseRunFactory()
 def test_get_absolute_url(self):
     course_run = factories.CourseRunFactory()
     expected = reverse('publisher:publisher_course_run_detail', kwargs={'pk': course_run.id})
     assert course_run.get_absolute_url() == expected