def setUpClass(self): """ These steps are carried out before the tests in this class. """ # Make sure no search index if os.path.exists(si): raise SearchIndexException( "Error: no search index %s should exist, but one was found" % (si)) # Create centillion and test client self.app = centillion.webapp.get_flask_app( config_file=os.path.join(HERE, CONFIG_FILE)) # Build search index in the tests/ dir if os.path.abspath(os.getcwd()) != HERE: # not in tests/ self.app.config['INDEX_DIR'] = si else: # in tests/ self.app.config['INDEX_DIR'] = INDEX_DIR self.client = self.app.test_client() self.update_index_all()
def setUpClass(self): """ Set up for unit tests by creating a new centillion Flask app with our testing configuration file. """ # Make sure no search index exists if os.path.exists(si): raise SearchIndexException( "Error: no search index %s should exist, but one was found" % (si)) self.app = centillion.webapp.get_flask_app( config_file=os.path.join(HERE, CONFIG_FILE)) # If we are running this test from # any directory other than tests/, # the search index will be built there. # (Typically this is the behavior we want.) # # The following code forces the # search index to be built in the # tests/ directory. # (Desirable behavior for testing.) if os.path.abspath(os.getcwd()) != HERE: # we are not in tests/, use absolute path self.app.config['INDEX_DIR'] = si else: # we are in tests/, use relative path self.app.config['INDEX_DIR'] = INDEX_DIR self.client = self.app.test_client()
def test_1_searchindex(self): """Check to make sure search index exists """ # Check that the search index exists if not os.path.exists(si): raise SearchIndexException( "Error: search index %s should exist, but nothing was found" % (si))
def tearDownClass(self): """Tear everything down when this test class is finished """ # Clean up test search index directory if os.path.isdir(si): subprocess.call(['rm', '-fr', si]) # Make sure no search index if os.path.exists(si): raise SearchIndexException( "Error: no search index %s should exist at end of test, but one was found" % (si))
def tearDownClass(self): """ These steps are carried out after all tests finish. """ # Clean up test search index directory if os.path.isdir(si): subprocess.call(['rm','-fr',si]) # Make sure no search index if os.path.exists(si): raise SearchIndexException("Error: no search index %s should exist at end of test, but one was found"%(si)) del self.app del self.client
def test_1_update_index(self): """Test the update_index route for all document types """ # Reindex the search index with fake docs r = self.client.get('/update_index/all') if r.status_code == 302: r = self.client.get(r.headers['Location']) # If you don't insert a sleep right here, # the assert below runs before the document # is added to the search index. time.sleep(2) # Check that the search index exists if not os.path.exists(si): raise SearchIndexException( "Error: search index %s should exist, but nothing was found" % (si))