Ejemplo n.º 1
0
    def test_search(self):
        """ Verify the method returns query results from the data store. """
        prefix = 'test'
        query = {
            'query': {
                'bool': {
                    'must': [
                        {
                            'wildcard': {
                                'course.name': prefix + '*'
                            }
                        }
                    ]
                }
            }
        }
        courses = []
        for i in range(3):
            courses.append(CourseFactory.create(name=prefix + str(i)))
            CourseFactory.create()

        courses.sort(key=lambda course: course.id.lower())
        self.refresh_index()

        expected = {
            'limit': 10,
            'offset': 0,
            'total': len(courses),
            'results': courses,
        }
        self.assertEqual(Course.search(query), expected)
Ejemplo n.º 2
0
    def contains(self, course_ids):  # pylint: disable=unused-argument
        """ Determines if the given courses are contained in this catalog.

        Arguments:
            course_ids (str[]): List of course IDs

        Returns:
            dict: Mapping of course IDs to booleans indicating if course is
                  contained in this catalog.
        """
        query = self.query_as_dict['query']

        # Create a filtered query that includes that uses the catalog's query against a
        # collection of courses filtered using the passed in course IDs.
        filtered_query = {
            "query": {
                "filtered": {
                    "query": query,
                    "filter": {
                        "ids": {
                            "values": course_ids
                        }
                    }
                }
            }
        }

        contains = {course_id: False for course_id in course_ids}
        courses = Course.search(filtered_query)['results']
        for course in courses:
            contains[course.id] = True

        return contains
Ejemplo n.º 3
0
    def test_search(self):
        """ Verify the method returns query results from the data store. """
        prefix = 'test'
        query = {
            'query': {
                'bool': {
                    'must': [{
                        'wildcard': {
                            'course.name': prefix + '*'
                        }
                    }]
                }
            }
        }
        courses = []
        for i in range(3):
            courses.append(CourseFactory.create(name=prefix + str(i)))
            CourseFactory.create()

        courses.sort(key=lambda course: course.id.lower())
        self.refresh_index()

        expected = {
            'limit': 10,
            'offset': 0,
            'total': len(courses),
            'results': courses,
        }
        self.assertEqual(Course.search(query), expected)
Ejemplo n.º 4
0
    def contains(self, course_ids):  # pylint: disable=unused-argument
        """ Determines if the given courses are contained in this catalog.

        Arguments:
            course_ids (str[]): List of course IDs

        Returns:
            dict: Mapping of course IDs to booleans indicating if course is
                  contained in this catalog.
        """
        query = self.query_as_dict['query']

        # Create a filtered query that includes that uses the catalog's query against a
        # collection of courses filtered using the passed in course IDs.
        filtered_query = {
            "query": {
                "filtered": {
                    "query": query,
                    "filter": {
                        "ids": {
                            "values": course_ids
                        }
                    }
                }
            }
        }

        contains = {course_id: False for course_id in course_ids}
        courses = Course.search(filtered_query)['results']
        for course in courses:
            contains[course.id] = True

        return contains
Ejemplo n.º 5
0
    def courses(self):
        """ Returns the list of courses contained within this catalog.

        Returns:
            Course[]
        """

        return Course.search(self.query_as_dict)['results']
Ejemplo n.º 6
0
    def courses(self):
        """ Returns the list of courses contained within this catalog.

        Returns:
            Course[]
        """

        return Course.search(self.query_as_dict)['results']
Ejemplo n.º 7
0
    def get_data(self, limit, offset):
        """ Return all courses. """
        query = self.request.GET.get('q', None)

        if query:
            query = json.loads(query)
            return Course.search(query, limit=limit, offset=offset)
        else:
            return Course.all(limit=limit, offset=offset)
Ejemplo n.º 8
0
    def get_data(self, limit, offset):
        """ Return all courses. """
        query = self.request.GET.get('q', None)

        if query:
            query = json.loads(query)
            return Course.search(query, limit=limit, offset=offset)
        else:
            return Course.all(limit=limit, offset=offset)