Skip to content

Commit

Permalink
Merge pull request SFDO-Tooling#891 from SFDO-Tooling/feature/capture…
Browse files Browse the repository at this point in the history
…-scratch-create-stderr

Capture stderr from scratch org creation
  • Loading branch information
David Glick authored Nov 26, 2018
2 parents 1841471 + 88f5739 commit 2c39da9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
32 changes: 24 additions & 8 deletions cumulusci/core/config/ScratchOrgConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def scratch_info(self):

self.logger.info("Getting scratch org info from Salesforce DX")

username = self.config.get("username")
if not username:
raise ScratchOrgException(
"Created scratch org but unable to capture username"
)

# Call force:org:display and parse output to get instance_url and
# access_token
command = sarge.shell_format(
Expand Down Expand Up @@ -177,25 +183,35 @@ def create_org(self):
**options
)
self.logger.info("Creating scratch org with command {}".format(command))
p = sarge.Command(command, stdout=sarge.Capture(buffer_size=-1), shell=True)
p = sarge.Command(
command,
stdout=sarge.Capture(buffer_size=-1),
stderr=sarge.Capture(buffer_size=-1),
shell=True,
)
p.run()

stderr = [line.strip() for line in io.TextIOWrapper(p.stderr)]
stdout = [line.strip() for line in io.TextIOWrapper(p.stdout)]

if p.returncode:
message = "{}: \n{}\n{}".format(
FAILED_TO_CREATE_SCRATCH_ORG, "\n".join(stdout), "\n".join(stderr)
)
raise ScratchOrgException(message)

re_obj = re.compile("Successfully created scratch org: (.+), username: (.+)")
stdout = []
for line in io.TextIOWrapper(p.stdout):
for line in stdout:
match = re_obj.search(line)
if match:
self.config["org_id"] = match.group(1)
self.config["username"] = match.group(2)
stdout.append(line)
self.logger.info(line)
for line in stderr:
self.logger.error(line)

self.config["date_created"] = datetime.datetime.now()

if p.returncode:
message = "{}: \n{}".format(FAILED_TO_CREATE_SCRATCH_ORG, "".join(stdout))
raise ScratchOrgException(message)

if self.config.get("set_password"):
self.generate_password()

Expand Down
15 changes: 13 additions & 2 deletions cumulusci/core/tests/test_config_expensive.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ def test_scratch_info_command_error(self, Command):
else:
self.fail("Expected ScratchOrgException")

def test_scratch_info_username_not_found(self, Command):
Command.return_value = mock.Mock(
stderr=io.BytesIO(b"error"), stdout=io.BytesIO(b"out"), returncode=0
)

config = ScratchOrgConfig({"config_file": "tmp"}, "test")

with self.assertRaises(ScratchOrgException):
config.scratch_info

def test_scratch_info_password_from_config(self, Command):
result = b"""{
"result": {
Expand Down Expand Up @@ -435,12 +445,13 @@ def test_create_org_no_config_file(self, Command):

def test_create_org_command_error(self, Command):
Command.return_value = mock.Mock(
stdout=io.BytesIO(b""), stderr=io.BytesIO(b"error"), returncode=1
stdout=io.BytesIO(b""), stderr=io.BytesIO(b"scratcherror"), returncode=1
)

config = ScratchOrgConfig({"config_file": "tmp"}, "test")
with self.assertRaises(ScratchOrgException):
with self.assertRaises(ScratchOrgException) as ctx:
config.create_org()
self.assertIn("scratcherror", str(ctx.error))

def test_generate_password(self, Command):
p = mock.Mock(
Expand Down
3 changes: 3 additions & 0 deletions cumulusci/robotframework/Salesforce.robot
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ${DEBUG} ${false}
${CHROME_BINARY} ${empty}
${ORG} ${empty}
${IMPLICIT_WAIT} 7.0
${INITIAL_TIMEOUT} 180.0
${TIMEOUT} 30.0

*** Keywords ***
Expand All @@ -29,7 +30,9 @@ Open Test Browser
... ELSE IF '${BROWSER}' == 'headlesschrome' Open Test Browser Chrome ${login_url}
... ELSE IF '${BROWSER}' == 'headlessfirefox' Open Test Browser Headless Firefox ${login_url}
... ELSE Open Browser ${login_url} ${BROWSER}
Set Selenium Timeout ${INITIAL_TIMEOUT}
Wait Until Loading Is Complete
Set Selenium Timeout ${TIMEOUT}

Open Test Browser Chrome
[Arguments] ${login_url}
Expand Down

0 comments on commit 2c39da9

Please sign in to comment.