def test_create_org_uses_org_def_email(self, Command): out = b"Successfully created scratch org: ORG_ID, username: USERNAME" Command.return_value = p = mock.Mock( stdout=io.BytesIO(out), stderr=io.BytesIO(b""), returncode=0 ) config = ScratchOrgConfig( { "config_file": "tmp.json", "set_password": True, "email_address": "*****@*****.**", }, "test", ) config.generate_password = mock.Mock() with temporary_dir(): with open("tmp.json", "w") as f: f.write('{"adminEmail": "*****@*****.**"}') config.create_org() p.run.assert_called_once() self.assertEqual(config.config["org_id"], "ORG_ID") self.assertEqual(config.config["username"], "USERNAME") self.assertIn("date_created", config.config) config.generate_password.assert_called_once() self.assertTrue(config.config["created"]) self.assertEqual(config.scratch_org_type, "workspace") self.assertNotIn("*****@*****.**", Command.call_args[0][0])
def test_create_org_command_error(self, Command): Command.return_value = mock.Mock(stdout=io.BytesIO(b""), stderr=io.BytesIO(b"error"), returncode=1) config = ScratchOrgConfig({"config_file": "tmp"}, "test") with self.assertRaises(ScratchOrgException): config.create_org()
def test_create_org_command_error(self, Command): Command.return_value = mock.Mock( stdout=io.BytesIO(b''), stderr=io.BytesIO(b'error'), returncode=1, ) config = ScratchOrgConfig({'config_file': 'tmp'}, 'test') with self.assertRaises(ScratchOrgException): config.create_org()
def test_create_org_command_error(self, Command): Command.return_value = mock.Mock( stdout=io.BytesIO(b""), stderr=io.BytesIO(b"scratcherror"), returncode=1 ) config = ScratchOrgConfig( {"config_file": "tmp.json", "email_address": "*****@*****.**"}, "test" ) with temporary_dir(): with open("tmp.json", "w") as f: f.write("{}") with self.assertRaises(ScratchOrgException) as ctx: config.create_org() self.assertIn("scratcherror", str(ctx.error))
def test_create_org(self, Command): out = b"Successfully created scratch org: ORG_ID, username: USERNAME" Command.return_value = p = mock.Mock(stdout=io.BytesIO(out), stderr=io.BytesIO(b""), returncode=0) config = ScratchOrgConfig({ "config_file": "tmp", "set_password": True }, "test") config.generate_password = mock.Mock() config.create_org() p.run.assert_called_once() self.assertEqual(config.config["org_id"], "ORG_ID") self.assertEqual(config.config["username"], "USERNAME") self.assertIn("date_created", config.config) config.generate_password.assert_called_once() self.assertTrue(config.config["created"]) self.assertEqual(config.scratch_org_type, "workspace")
def test_create_org(self, Command): out = b'Successfully created scratch org: ORG_ID, username: USERNAME' Command.return_value = p = mock.Mock( stdout=io.BytesIO(out), stderr=io.BytesIO(b''), returncode=0, ) config = ScratchOrgConfig({ 'config_file': 'tmp', 'set_password': True, }, 'test') config.generate_password = mock.Mock() config.create_org() p.run.assert_called_once() self.assertEqual(config.config['org_id'], 'ORG_ID') self.assertEqual(config.config['username'], 'USERNAME') self.assertIn('date_created', config.config) config.generate_password.assert_called_once() self.assertTrue(config.config['created']) self.assertEqual(config.scratch_org_type, 'workspace')
def test_create_org_no_config_file(self, Command): config = ScratchOrgConfig({}, "test") self.assertEqual(config.create_org(), None) Command.assert_not_called()
def test_create_org_no_config_file(self, Command): config = ScratchOrgConfig({}, "test") with pytest.raises(ScratchOrgException, match="missing a config_file"): config.create_org() Command.assert_not_called()