Exemplo n.º 1
0
 def test_courses_count_if_query_is_incorrect(self):
     """ Verify the method returns the number of courses contained in the Catalog. """
     CourseFactory(title='ABCDEF')
     assert self.catalog_with_incorrect_query.courses_count == 0
Exemplo n.º 2
0
    def test_selected_field_facet(self):
        """ Verify that the response is accurate when a field facet is selected."""
        now = datetime.datetime.now(pytz.UTC)
        current = (now - datetime.timedelta(days=1),
                   now + datetime.timedelta(days=1))
        archived = (now - datetime.timedelta(days=2),
                    now - datetime.timedelta(days=1))

        course = CourseFactory(partner=self.partner)
        run_1 = self.build_courserun(course=course,
                                     start=current[0],
                                     end=current[1],
                                     pacing_type='self_paced')
        run_2 = self.build_courserun(course=course,
                                     start=archived[0],
                                     end=archived[1],
                                     pacing_type='self_paced')
        run_3 = self.build_courserun(course=course,
                                     start=current[0],
                                     end=current[1],
                                     pacing_type='instructor_paced')
        run_4 = self.build_courserun(course=course,
                                     start=archived[0],
                                     end=archived[1],
                                     pacing_type='instructor_paced')
        self.build_program(partner=self.partner)

        response = self.get_response(
            {'selected_facets': 'content_type_exact:courserun'})
        assert response.status_code == 200

        assert response.data['objects']['count'] == 4
        assert response.data['objects']['distinct_count'] == 1
        expected = sorted([run_1.key, run_2.key, run_3.key, run_4.key])
        actual = sorted(
            [record['key'] for record in response.data['objects']['results']])
        assert expected == actual

        pacing_types = {
            facet['text']: facet
            for facet in response.data['fields']['pacing_type']
        }
        assert pacing_types['self_paced']['count'] == 2
        assert pacing_types['self_paced']['distinct_count'] == 1
        expected_query_params = {
            'selected_facets':
            ['content_type_exact:courserun', 'pacing_type_exact:self_paced']
        }
        self.assert_url_path_and_query(
            pacing_types['self_paced']['narrow_url'], self.path,
            expected_query_params)

        availability_current = response.data['queries']['availability_current']
        assert availability_current['count'] == 2
        assert availability_current['distinct_count'] == 1
        expected_query_params = {
            'selected_facets': ['content_type_exact:courserun'],
            'selected_query_facets': ['availability_current'],
        }
        self.assert_url_path_and_query(availability_current['narrow_url'],
                                       self.path, expected_query_params)