Skip to content

Commit 46cb46a

Browse files
committed
add some unit tests
1 parent cec1775 commit 46cb46a

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

tests/test_credentials.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,70 @@ def test_update_ini_new_profile(self):
244244

245245
# Check that existing profile was not modified
246246
assert mock_config["existing"]["username"] == "existing_user"
247+
248+
def test_from_available_with_custom_profile(self):
249+
"""Test that from_available uses custom profile when specified."""
250+
ini_content = """
251+
[default]
252+
username = default_user
253+
password = default_pass
254+
client_id = default_client_id
255+
client_secret = default_secret
256+
login_url = https://default.login.url
257+
258+
[custom_profile]
259+
username = custom_user
260+
password = custom_pass
261+
client_id = custom_client_id
262+
client_secret = custom_secret
263+
login_url = https://custom.login.url
264+
"""
265+
266+
with (
267+
patch("datacustomcode.credentials.INI_FILE", "fake_path"),
268+
patch("os.path.exists", return_value=True),
269+
patch("builtins.open", mock_open(read_data=ini_content)),
270+
):
271+
# Mock the configparser behavior for reading the file
272+
mock_config = configparser.ConfigParser()
273+
mock_config.read_string(ini_content)
274+
275+
with patch.object(configparser, "ConfigParser", return_value=mock_config):
276+
# Test default profile
277+
creds_default = Credentials.from_available()
278+
assert creds_default.username == "default_user"
279+
assert creds_default.login_url == "https://default.login.url"
280+
281+
# Test custom profile
282+
creds_custom = Credentials.from_available(profile="custom_profile")
283+
assert creds_custom.username == "custom_user"
284+
assert creds_custom.password == "custom_pass"
285+
assert creds_custom.client_id == "custom_client_id"
286+
assert creds_custom.client_secret == "custom_secret"
287+
assert creds_custom.login_url == "https://custom.login.url"
288+
289+
def test_from_available_fallback_to_default(self):
290+
"""Test that from_available falls back to default when no profile specified."""
291+
ini_content = """
292+
[default]
293+
username = default_user
294+
password = default_pass
295+
client_id = default_client_id
296+
client_secret = default_secret
297+
login_url = https://default.login.url
298+
"""
299+
300+
with (
301+
patch("datacustomcode.credentials.INI_FILE", "fake_path"),
302+
patch("os.path.exists", return_value=True),
303+
patch("builtins.open", mock_open(read_data=ini_content)),
304+
):
305+
# Mock the configparser behavior for reading the file
306+
mock_config = configparser.ConfigParser()
307+
mock_config.read_string(ini_content)
308+
309+
with patch.object(configparser, "ConfigParser", return_value=mock_config):
310+
# Test that no profile parameter defaults to "default"
311+
creds = Credentials.from_available()
312+
assert creds.username == "default_user"
313+
assert creds.login_url == "https://default.login.url"

0 commit comments

Comments
 (0)