Esempio n. 1
0
    def test_spotlight_courses_non_empty(self):
        """Test that when spotlight_courses is called wwith documents
            configured then it returns an array with the documents"""
        with patch('es_api.utils.queries.CourseSpotlight.objects') as \
                spotlightObjs, patch('elasticsearch_dsl.Document.mget') as \
                mget:
            doc_1 = {
                "_source": {
                    "test": "val",
                    "test2": "val2"
                },
                "_id": "12312",
                "_index": "test-index"
            }
            doc_2 = {
                "_source": {
                    "test3": "val3",
                    "test4": "val4"
                },
                "_id": "43231",
                "_index": "test-index-2"
            }
            spotlight = CourseSpotlight(course_id=1)
            spotlightObjs.filter.return_value = [spotlight]
            instance_1 = mget.return_value
            mget.return_value = [instance_1, instance_1]
            instance_1.to_dict.side_effect = [doc_1, doc_2]
            query = XSEQueries('test', 'test')
            result = query.spotlight_courses()

            self.assertEqual(len(result), 2)
            self.assertTrue('meta' in result[0])
            self.assertEqual(doc_1["_id"], result[0]["meta"]["id"])
Esempio n. 2
0
    def test_spotlight_courses_empty(self):
        """Test that when spotlight_courses is called wwith no documents
            then it throws an error"""
        with patch('es_api.utils.queries.CourseSpotlight.objects') as \
                spotlightObjs, patch('elasticsearch_dsl.Document.mget') as \
                mget:
            spotlightObjs.filter.return_value = []
            mget.return_value = []
            query = XSEQueries('test', 'test')
            result = query.spotlight_courses()

            self.assertEqual(len(result), 0)