def test_get_database_url(self): with heroku_cli('▸ No app specified', exit_code=1): with pytest.raises(CommandError) as e: Command.get_database_url(None) assert 'Please provide the correct Heroku app name.' in str(e.value) with heroku_cli(self.pg_url, exit_code=0): assert self.pg_url in Command.get_database_url(None) with heroku_cli(self.pg_url, exit_code=0): assert self.pg_url in Command.get_database_url('ninja')
def test_escaping(self): with heroku_cli(stdout='""; echo "foo"', stderr='""; echo "foo"'): process = subprocess.run(["heroku"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert process.stdout == b'""; echo "foo"\n' assert process.stderr == b'""; echo "foo"\n'
def test_stderr(self): with heroku_cli(stderr="I am Batman"): process = subprocess.run(["heroku"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert process.returncode == 0 assert process.stdout == b"\n" assert process.stderr == b"I am Batman\n"
def test_exit_code(self): with heroku_cli(exit_code=1): process = subprocess.run(["heroku"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert process.returncode == 1 assert process.stdout == b"\n" assert process.stderr == b"\n"
def test_no_args(self): with heroku_cli(): process = subprocess.run(["heroku"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert process.returncode == 0 assert process.stdout == b"\n" assert process.stderr == b"\n"
def test_stderr(self): with heroku_cli(stderr='I am Batman'): process = subprocess.run(['heroku'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert process.returncode == 0 assert process.stdout == b'\n' assert process.stderr == b'I am Batman\n'
def test_call_command(self): os.system('echo \'CREATE SCHEMA IF NOT EXISTS "salesforce";\'' ' | psql -d heroku_connect_test -a') with heroku_cli('postgres://:@localhost:5432/heroku_connect_test', exit_code=0): with StringIO() as sql: call_command('load_remote_schema', stdout=sql) sql.seek(0) assert 'CREATE SCHEMA salesforce;' in sql.read()
def test_call_command(self): self._psql('CREATE SCHEMA IF NOT EXISTS "salesforce"') database_url = ("postgres://" f'{self.db["USER"]}:{self.db["PASSWORD"]}' f'@{self.db["HOST"]}' f':{self.db["PORT"]}' f'/{self.db["NAME"]}') with heroku_cli(database_url, exit_code=0): with StringIO() as sql: call_command("load_remote_schema", stdout=sql) sql.seek(0) assert "CREATE SCHEMA salesforce;" in sql.read()