def tearDown(self):
        # TODO: instead of just manually throwing away DB stuff, add a
        # destroy_project_data function that could be user-accessible in
        # case a user ever wants to throw away their DB and start over.
        try:
            database.drop_database(self.app_id)
            database.drop_user(self.app_id)
        except ProgrammingError:  # probably indicates DB/user doesn't exist
            pass

        # chown cust dir to me so we can delete it
        utils.chown_to_me(self.dir)

        # delete any lingering supervisor conf files
        utils.local("rm -f %s/%s*" % (taskconfig.SUPERVISOR_APP_CONF_DIR, self.app_id))
Esempio n. 2
0
    def test_get_or_create_and_drop(self):
        """
        Create a new DB & user, ensure user can use only that DB, then drop.
        """

        database.lock_down_public_permissions()

        app_id = "test_%d" % random.randint(100, 1000)

        try:
            dbinfo = database.get_or_create_database(app_id)

            for attr in ("just_created", "host", "db_name", "username",
                         "password"):
                self.assertTrue(getattr(dbinfo, attr))

            self.assertTrue(_can_access_db(dbinfo, try_create=True),
                            "Ensure new database can be accessed.")

            cust_nrweb_dbinfo = database.DatabaseInfo(
                host=dbinfo.host, db_name="nrweb",
                username=dbinfo.username, password=dbinfo.password)
            self.assertTrue(not _can_access_db(cust_nrweb_dbinfo),
                            "Ensure cust user CANNOT access nrweb.")

            nrweb_nrweb_dbinfo = database.DatabaseInfo(
                host=dbinfo.host, db_name="nrweb",
                username="******", password="")
            self.assertTrue(_can_access_db(nrweb_nrweb_dbinfo),
                            "Ensure nrweb can access nrweb.")

        finally:
            database.drop_database(dbinfo.db_name)
            database.drop_user(dbinfo.username)

        self.assertTrue(not _can_access_db(dbinfo),
                        "Ensure dropped database can no longer be accessed.")
Esempio n. 3
0
 def tearDown(self):
     super(PostGisTestCase, self).tearDown()
     self.conn.close()
     database.drop_database(self.dbinfo.db_name)
     database.drop_user(self.dbinfo.username)