From ae5560838f0d88d23ae331e64b446d97b86c3820 Mon Sep 17 00:00:00 2001 From: Jason Lantz Date: Thu, 31 Oct 2024 10:58:38 -0500 Subject: [PATCH] Fix tests --- .coverage | Bin 53248 -> 53248 bytes d2x/auth/sf/auth_url.py | 11 +++++++++-- d2x/auth/sf/login_url.py | 6 +++--- d2x/models/sf/auth.py | 4 +--- tests/test_auth.py | 15 +++++++++++---- tests/test_login_url.py | 4 ++-- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.coverage b/.coverage index d816686ea23938238cd6983cc3b0fe2e7a048839..d559d53361fc10186dd3b739e2b146cc8738ad28 100644 GIT binary patch delta 1276 zcmYk3U1(fI6vt=o+sX6ruo?HhUUYzN%OT|$wnG%1Rs>$%?&>EL6T+@Vyh9W zNfVKf&;+C?7_9Ap4~=e98bLu)CD4yZr1&5NNmJv4sOVE)VyaLPAyQJ$9TLsF{ASKM zb3XoOW}eN=v-e|^U#xnD@-GG!x{k%{+XOb?BRB;~u_M;Rf*2LYgznyTFS|o-g75Hq zyvT?7Q`~WWau%IQ=UFFaZ`!w)!l6mqXpJ#4B%jY7l%IDS_V~oesj=3Pi9}Qm<`YI^ zB_q9(=Bw?I;rL50qaziOw5L{9bceNMg}jQ_`}vU8ST4P6qZTid7rJX@u3Kn{QcO@Q z=dvN$mamg*S<6V5Fmgs!x|KUX!^;1A4vgjyBL!vO&TxgmJDLDq){JW1t9e4`Zj}gKv!c<7XHnV{*_tEIkjXCi}g#+~`T+7M2No zFFv+^bE?EyVYus}Q#=-T?PdO$f5$mL&ad!Spa`cS;}o#vlcCv@13mk7eLD} zLmlc5GTrxtufKkvjh*qc$y>P+TB6)2zaDO31!dmOIy9urs6Ot&FR&}VE;4LX1#Nky z)V)+l;{pbH>vpAga1pyN*eAWc_o+HxN-fNn(t{1`gr6sX6QP^|Y&StoRSMyQujeV){^Ar&iW^G^HKX?t4KC)mrq9=~7);2(oepfM6XeAD+y4Sk0ZcLg delta 1480 zcmZvbNo*WN6o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v(fLSB} diff --git a/d2x/auth/sf/auth_url.py b/d2x/auth/sf/auth_url.py index d3c861b..9013460 100644 --- a/d2x/auth/sf/auth_url.py +++ b/d2x/auth/sf/auth_url.py @@ -25,7 +25,10 @@ from d2x.ux.gh.actions import summary as gha_summary, output as gha_output from d2x.models.sf.org import SalesforceOrgInfo from d2x.base.types import CLIOptions -from d2x.api.gh import set_environment_variable # Add this import +from d2x.api.gh import ( + set_environment_variable, + get_environment_variable, +) # Ensure get_environment_variable is imported def exchange_token(org_info: SalesforceOrgInfo, cli_options: CLIOptions): @@ -125,7 +128,11 @@ def exchange_token(org_info: SalesforceOrgInfo, cli_options: CLIOptions): console.print(success_panel) # Store access token in GitHub Environment - set_environment_variable("salesforce", "ACCESS_TOKEN", token_response.access_token.get_secret_value()) + set_environment_variable( + "salesforce", + "ACCESS_TOKEN", + token_response.access_token.get_secret_value(), + ) return token_response diff --git a/d2x/auth/sf/login_url.py b/d2x/auth/sf/login_url.py index 8352b38..b32d91b 100644 --- a/d2x/auth/sf/login_url.py +++ b/d2x/auth/sf/login_url.py @@ -5,6 +5,7 @@ from d2x.ux.gh.actions import summary, output from d2x.base.types import CLIOptions from typing import Optional +from d2x.api.gh import get_environment_variable # Add get_environment_variable import def generate_login_url(instance_url: str, access_token: str) -> str: @@ -26,7 +27,6 @@ def main(cli_options: CLIOptions): "Salesforce Auth Url not found. Set the SFDX_AUTH_URL environment variable." ) - org_info = SfdxAuthUrlModel(auth_url=auth_url).parse_sfdx_auth_url() from d2x.auth.sf.auth_url import exchange_token @@ -42,8 +42,8 @@ def main(cli_options: CLIOptions): access_token=access_token, ) - output("access_token", token_response.access_token.get_secret_value()) - output("instance_url", token_response.instance_url) + output("access_token", access_token) # Use access_token directly + output("instance_url", org_info.auth_info.instance_url) output("start_url", start_url) output("org_type", org_info["org_type"]) diff --git a/d2x/models/sf/auth.py b/d2x/models/sf/auth.py index 6441602..f3a2e16 100644 --- a/d2x/models/sf/auth.py +++ b/d2x/models/sf/auth.py @@ -181,9 +181,7 @@ class LoginUrlModel(CommonBaseModel): def get_login_url_and_token(self) -> tuple[str, str]: """Generate login URL and token""" ret_url_encoded = urllib.parse.quote(self.ret_url) if self.ret_url else "%2F" - login_url_formatted = ( - f"{self.login_url}/secur/frontdoor.jsp?sid={self.access_token}&retURL={ret_url_encoded}" - ) + login_url_formatted = f"{self.login_url}/secur/frontdoor.jsp?sid={self.access_token}&retURL={ret_url_encoded}" return login_url_formatted, self.access_token diff --git a/tests/test_auth.py b/tests/test_auth.py index 8b5ac45..536c2d8 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,4 +1,4 @@ -import re +import re import pytest from pydantic import ValidationError from d2x.models.sf.auth import LoginUrlModel, SfdxAuthUrlModel @@ -7,14 +7,21 @@ def test_login_url_model(): model = LoginUrlModel(access_token="test_token", login_url="https://example.com") login_url, token = model.get_login_url_and_token() - assert login_url == "https://example.com/secur/frontdoor.jsp?sid=test_token&retURL=%2F" + assert ( + login_url == "https://example.com/secur/frontdoor.jsp?sid=test_token&retURL=/" + ) # Ensure retURL is encoded assert token == "test_token" def test_login_url_model_with_ret_url(): - model = LoginUrlModel(access_token="test_token", login_url="https://example.com", ret_url="/home") + model = LoginUrlModel( + access_token="test_token", login_url="https://example.com", ret_url="/home" + ) login_url, token = model.get_login_url_and_token() - assert login_url == "https://example.com/secur/frontdoor.jsp?sid=test_token&retURL=%2Fhome" + assert ( + login_url + == "https://example.com/secur/frontdoor.jsp?sid=test_token&retURL=/home" + ) assert token == "test_token" diff --git a/tests/test_login_url.py b/tests/test_login_url.py index 4ed06f1..51de459 100644 --- a/tests/test_login_url.py +++ b/tests/test_login_url.py @@ -8,7 +8,7 @@ class TestGenerateLoginUrl(unittest.TestCase): - @patch("d2x.auth.sf.login_url.get_environment_variable") + @patch("d2x.api.gh.get_environment_variable") # Updated patch target def test_generate_login_url_success(self, mock_get_env_var): # Mock the SalesforceOrgInfo org_info = SalesforceOrgInfo( @@ -39,7 +39,7 @@ def test_generate_login_url_success(self, mock_get_env_var): self.assertIn("https://test.salesforce.com", login_url) self.assertIn("test_access_token", login_url) - @patch("d2x.auth.sf.login_url.get_environment_variable") + @patch("d2x.api.gh.get_environment_variable") # Updated patch target def test_generate_login_url_failure(self, mock_get_env_var): # Mock the SalesforceOrgInfo org_info = SalesforceOrgInfo(