-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
BaseSalesforceOrg
model and its subclasses
* Test field validation and enum usage * Add tests for `exchange_token` function using `BaseSalesforceOrg` model * Test simple-salesforce integration for creating scratch orgs and exchanging auth codes * Add tests for CLI commands related to creating scratch orgs and exchanging auth codes * Test command execution and output
- Loading branch information
Showing
3 changed files
with
222 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from click.testing import CliRunner | ||
from d2x.cli.main import d2x_cli | ||
from d2x.models.sf.org import ScratchOrg | ||
from d2x.models.sf.auth import AuthInfo | ||
from d2x.base.types import CLIOptions | ||
|
||
|
||
class TestCLICommands(unittest.TestCase): | ||
@patch("d2x.cli.main.create_scratch_org") | ||
def test_create_scratch_org_command(self, mock_create_scratch_org): | ||
runner = CliRunner() | ||
result = runner.invoke(d2x_cli, ["sf", "org", "create"]) | ||
|
||
self.assertEqual(result.exit_code, 0) | ||
mock_create_scratch_org.assert_called_once() | ||
|
||
@patch("d2x.cli.main.exchange_token") | ||
def test_exchange_token_command(self, mock_exchange_token): | ||
runner = CliRunner() | ||
result = runner.invoke(d2x_cli, ["sf", "org", "exchange"]) | ||
|
||
self.assertEqual(result.exit_code, 0) | ||
mock_exchange_token.assert_called_once() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import unittest | ||
from pydantic import ValidationError | ||
from d2x.models.sf.org import ( | ||
BaseSalesforceOrg, | ||
ProductionOrg, | ||
TrialOrg, | ||
SandboxOrg, | ||
ScratchOrg, | ||
OrgType, | ||
DomainType, | ||
) | ||
|
||
|
||
class TestBaseSalesforceOrg(unittest.TestCase): | ||
def test_production_org(self): | ||
org = ProductionOrg( | ||
org_type=OrgType.PRODUCTION, | ||
domain_type=DomainType.POD, | ||
full_domain="example.salesforce.com", | ||
instance_url="https://example.salesforce.com", | ||
created_date="2021-01-01", | ||
last_modified_date="2021-01-02", | ||
status="Active", | ||
) | ||
self.assertEqual(org.org_type, OrgType.PRODUCTION) | ||
self.assertEqual(org.domain_type, DomainType.POD) | ||
self.assertEqual(org.full_domain, "example.salesforce.com") | ||
self.assertEqual(org.instance_url, "https://example.salesforce.com") | ||
self.assertEqual(org.created_date, "2021-01-01") | ||
self.assertEqual(org.last_modified_date, "2021-01-02") | ||
self.assertEqual(org.status, "Active") | ||
|
||
def test_trial_org(self): | ||
org = TrialOrg( | ||
org_type=OrgType.DEMO, | ||
domain_type=DomainType.POD, | ||
full_domain="example.salesforce.com", | ||
instance_url="https://example.salesforce.com", | ||
created_date="2021-01-01", | ||
last_modified_date="2021-01-02", | ||
status="Active", | ||
) | ||
self.assertEqual(org.org_type, OrgType.DEMO) | ||
self.assertEqual(org.domain_type, DomainType.POD) | ||
self.assertEqual(org.full_domain, "example.salesforce.com") | ||
self.assertEqual(org.instance_url, "https://example.salesforce.com") | ||
self.assertEqual(org.created_date, "2021-01-01") | ||
self.assertEqual(org.last_modified_date, "2021-01-02") | ||
self.assertEqual(org.status, "Active") | ||
|
||
def test_sandbox_org(self): | ||
org = SandboxOrg( | ||
org_type=OrgType.SANDBOX, | ||
domain_type=DomainType.POD, | ||
full_domain="example.salesforce.com", | ||
instance_url="https://example.salesforce.com", | ||
created_date="2021-01-01", | ||
last_modified_date="2021-01-02", | ||
status="Active", | ||
) | ||
self.assertEqual(org.org_type, OrgType.SANDBOX) | ||
self.assertEqual(org.domain_type, DomainType.POD) | ||
self.assertEqual(org.full_domain, "example.salesforce.com") | ||
self.assertEqual(org.instance_url, "https://example.salesforce.com") | ||
self.assertEqual(org.created_date, "2021-01-01") | ||
self.assertEqual(org.last_modified_date, "2021-01-02") | ||
self.assertEqual(org.status, "Active") | ||
|
||
def test_scratch_org(self): | ||
org = ScratchOrg( | ||
org_type=OrgType.SCRATCH, | ||
domain_type=DomainType.POD, | ||
full_domain="example.salesforce.com", | ||
instance_url="https://example.salesforce.com", | ||
created_date="2021-01-01", | ||
last_modified_date="2021-01-02", | ||
status="Active", | ||
) | ||
self.assertEqual(org.org_type, OrgType.SCRATCH) | ||
self.assertEqual(org.domain_type, DomainType.POD) | ||
self.assertEqual(org.full_domain, "example.salesforce.com") | ||
self.assertEqual(org.instance_url, "https://example.salesforce.com") | ||
self.assertEqual(org.created_date, "2021-01-01") | ||
self.assertEqual(org.last_modified_date, "2021-01-02") | ||
self.assertEqual(org.status, "Active") | ||
|
||
def test_invalid_org_type(self): | ||
with self.assertRaises(ValidationError): | ||
ProductionOrg( | ||
org_type="invalid_org_type", | ||
domain_type=DomainType.POD, | ||
full_domain="example.salesforce.com", | ||
instance_url="https://example.salesforce.com", | ||
created_date="2021-01-01", | ||
last_modified_date="2021-01-02", | ||
status="Active", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |