Ejemplo n.º 1
0
    def test_courses_with_include_archived(self):
        """
        Verify the endpoint returns the list of available and archived courses if include archived
        is True in catalog.
        """
        url = reverse('api:v1:catalog-courses', kwargs={'id': self.catalog.id})
        Course.objects.all().delete()

        now = datetime.datetime.now(pytz.UTC)
        future = now + datetime.timedelta(days=30)
        past = now - datetime.timedelta(days=30)

        course_run = CourseRunFactory.create(
            course__title='ABC Test Course With Archived', end=future, enrollment_end=future
        )
        SeatFactory.create(course_run=course_run)
        # Create an archived course run
        CourseRunFactory.create(course=course_run.course, end=past)

        response = self.client.get(url)

        assert response.status_code == 200
        # The course appearing in response should have on 1 course run
        assert len(response.data['results'][0]['course_runs']) == 1

        # Mark include archived True in catalog
        self.catalog.include_archived = True
        self.catalog.save()
        response = self.client.get(url)

        assert response.status_code == 200
        # The course appearing in response should include archived course run
        assert len(response.data['results'][0]['course_runs']) == 2
Ejemplo n.º 2
0
    def test_typeahead_authoring_organizations_partial_search(self):
        """ Test typeahead response with partial organization matching. """
        authoring_organizations = OrganizationFactory.create_batch(3)
        course_run = CourseRunFactory.create(course__partner=self.partner)
        program = ProgramFactory.create(partner=self.partner)
        for authoring_organization in authoring_organizations:
            course_run.authoring_organizations.add(authoring_organization)
            program.authoring_organizations.add(authoring_organization)
        course_run.save()
        program.save()
        partial_key = authoring_organizations[0].key[0:5]

        response = self.get_response({'q': partial_key})
        self.assertEqual(response.status_code, 200)

        # This call is flaky in Travis. It is reliable locally, but occasionally in our CI environment,
        # this call won't contain the data for course_runs and programs. Instead of relying on the factories
        # we now explicitly add the authoring organizations to a course_run and program and call .save()
        # in order to update the search indexes.
        expected = {
            'course_runs': [self.serialize_course_run_search(course_run)],
            'programs': [self.serialize_program_search(program)]
        }
        self.assertDictEqual(response.data, expected)