示例#1
0
    def test_build_index(self):
        elastic_index.clear()

        # Populate the database
        self._load_and_assert_success(Category, 'load_categories')
        self._load_and_assert_success(Resource, 'load_resources',
                                      ResourceCategory, 'resource')
        self._load_and_assert_success(Event, 'load_events', ResourceCategory,
                                      'event')
        self._load_and_assert_success(Location, 'load_locations',
                                      ResourceCategory, 'location')
        self._load_and_assert_success(Study, 'load_studies', StudyCategory)

        # Build the index
        data_loader.DataLoader().build_index()

        # Get the number of items in the database
        num_db_resources = db.session.query(Resource).filter(
            Resource.type == 'resource').count()
        num_db_events = db.session.query(Resource).filter(
            Resource.type == 'event').count()
        num_db_locations = db.session.query(Resource).filter(
            Resource.type == 'location').count()
        num_db_studies = db.session.query(Study).count()

        # Get the number of items in the search index
        es_resources = elastic_index.search(
            Search(types=[Resource.__tablename__]))
        es_events = elastic_index.search(Search(types=[Event.__tablename__]))
        es_locations = elastic_index.search(
            Search(types=[Location.__tablename__]))
        es_studies = elastic_index.search(Search(types=[Study.__tablename__]))

        # Verify that the number of items in the database match the number of items in the search index
        self.assertEqual(num_db_resources, es_resources.hits.total)
        self.assertEqual(num_db_events, es_events.hits.total)
        self.assertEqual(num_db_locations, es_locations.hits.total)
        self.assertEqual(num_db_studies, es_studies.hits.total)

        # Assure there are not age related categories.
        self.assertEqual(
            0,
            db.session.query(Category).filter(
                Category.name == 'Age Range').count())
        self.assertEqual(
            0,
            db.session.query(Category).filter(
                Category.name == 'Pre-K (0 - 5 years)').count())
示例#2
0
 def setUp(self):
     self.ctx.push()
     clean_db(db)
     elastic_index.clear()
     self.auths = {}
示例#3
0
 def tearDownClass(cls):
     db.drop_all()
     db.session.remove()
     elastic_index.clear()
示例#4
0
 def tearDown(self):
     self.ctx.pop()
     db.drop_all()
     elastic_index.clear()
     pass
示例#5
0
 def clear_index(self):
     print("Clearing the index")
     elastic_index.clear()