def test_main(self):
        """Test the high level environment initialization logic."""
        self.mox.StubOutWithMock(initalize_environment, 'create_user')
        self.mox.StubOutWithMock(initalize_environment, 'create_db_engine')
        self.mox.StubOutWithMock(initalize_environment, 'get_env_config')
        self.mox.StubOutWithMock(initalize_environment, 'create_db')
        self.mox.StubOutWithMock(initalize_environment, 'create_db_lang')
        self.mox.StubOutWithMock(initalize_environment, 'install_postgis')
        self.mox.StubOutWithMock(database, 'init_db')

        mock_connection = MockDBConnection()
        mock_engine = MockEngine(mock_connection)

        initalize_environment.create_user(DATABASE_USER,
            DATABASE_PASSWORD).AndReturn(None)
        initalize_environment.create_db_engine(DATABASE_USER,
            DATABASE_PASSWORD).AndReturn(mock_engine)
        initalize_environment.get_env_config().AndReturn(TEST_CONFIG_SETTINGS)
        initalize_environment.create_db(mock_connection,
            DATABASE_NAME).AndReturn(None)
        initalize_environment.create_db_lang(DATABASE_NAME).AndReturn(None)
        initalize_environment.install_postgis(DATABASE_NAME).AndReturn(None)
        database.init_db().AndReturn(mock_connection)

        self.mox.ReplayAll()
        initalize_environment.main(DATABASE_TYPE)
    def test_create_user(self):
        """Test creating a new user on the local PostgreSQL server."""
        expected_elements = ['psql', '-c', EXPECTED_ROLE_COMMAND]
        self.mox.StubOutWithMock(subprocess, 'call')

        subprocess.call(expected_elements).AndReturn(0)

        self.mox.ReplayAll()
        initalize_environment.create_user(DATABASE_USER, DATABASE_PASSWORD)