Esempio n. 1
0
    def setUp(self):
        """Prep for test case.  Subclass must call this parent method to actually use it.
        """
        MedInfoTestCase.setUp(self)

        if medinfo.db.Env.DB_PARAM["DSN"] == medinfo.db.Env.TEST_DB_PARAM[
                "DSN"]:
            quit(
                "Please use different names for production and test databases!"
            )

        # Override default DB connection params to test DB, but retain links to original
        self.orig_DB_PARAM = dict(medinfo.db.Env.DB_PARAM)

        medinfo.db.Env.DB_PARAM.update(medinfo.db.Env.TEST_DB_PARAM)

        # Create the temporary test database to work with
        try:
            DBUtil.createDatabase(medinfo.db.Env.DB_PARAM)
            self.testDBCreated = True
            # If error on above (e.g., database already exists), will have aborted with a database error before this
        except DBUtil.DB_CONNECTOR_MODULE.ProgrammingError, err:
            # Error on database creation, probably because existing one already there
            # Drop existing database if already there, but beware!
            # Beware of accidentally dropping an existing production database! This may still be necessary to cleanup if accidentally left a test database instance behind
            DBUtil.dropDatabase(medinfo.db.Env.DB_PARAM)
            DBUtil.createDatabase(medinfo.db.Env.DB_PARAM)
            self.testDBCreated = True
Esempio n. 2
0
    def tearDown(self):
        """Restore state after test finishes.  Subclass must call this parent method to actually use it.
        """
        # Drop the temporary test database, but make sure we created it ourselves, so we don't accidentally drop a production database
        if self.testDBCreated:
            DBUtil.dropDatabase(medinfo.db.Env.DB_PARAM);

        medinfo.db.Env.DB_PARAM.update(self.orig_DB_PARAM);

        MedInfoTestCase.tearDown(self)