Exemplo n.º 1
0
 def setUp(self):
     super(PostGisTestCase, self).setUp()
     self.app_id = "test_pgis_%d" % random.randint(100, 1000)
     self.dbinfo = database.get_or_create_database(self.app_id)
     conn_string = (("dbname=%(db_name)s user=%(username)s "
                     "password=%(password)s host=%(host)s") %
                    self.dbinfo)
     self.conn = psycopg2.connect(conn_string)
     self.conn.set_isolation_level(
         psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
Exemplo 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.")
Exemplo n.º 3
0
def setup_database_for_app(app_id):
    return database.get_or_create_database(app_id)