Skip to content

Commit f10f70d

Browse files
committed
Add test coverage for get_raw_token and auth_type assertions
1 parent 356392f commit f10f70d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/test_008_auth.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
import platform
99
import sys
10+
from unittest.mock import patch, MagicMock
1011
from mssql_python.auth import (
1112
AADAuth,
1213
process_auth_parameters,
@@ -82,6 +83,11 @@ def test_get_token_struct(self):
8283
assert isinstance(token_struct, bytes)
8384
assert len(token_struct) > 4
8485

86+
def test_get_raw_token_default(self):
87+
raw_token = AADAuth.get_raw_token("default")
88+
assert isinstance(raw_token, str)
89+
assert raw_token == SAMPLE_TOKEN
90+
8591
def test_get_token_default(self):
8692
token_struct = AADAuth.get_token("default")
8793
assert isinstance(token_struct, bytes)
@@ -333,6 +339,7 @@ def test_process_connection_string_with_default_auth(self):
333339
assert attrs is not None
334340
assert 1256 in attrs
335341
assert isinstance(attrs[1256], bytes)
342+
assert auth_type == "default"
336343

337344
def test_process_connection_string_no_auth(self):
338345
conn_str = "Server=test;Database=testdb;UID=user;PWD=password"
@@ -343,6 +350,7 @@ def test_process_connection_string_no_auth(self):
343350
assert "UID=user" in result_str
344351
assert "PWD=password" in result_str
345352
assert attrs is None
353+
assert auth_type is None
346354

347355
def test_process_connection_string_interactive_non_windows(self, monkeypatch):
348356
monkeypatch.setattr(platform, "system", lambda: "Darwin")
@@ -354,6 +362,7 @@ def test_process_connection_string_interactive_non_windows(self, monkeypatch):
354362
assert attrs is not None
355363
assert 1256 in attrs
356364
assert isinstance(attrs[1256], bytes)
365+
assert auth_type == "interactive"
357366

358367

359368
def test_error_handling():
@@ -368,3 +377,14 @@ def test_error_handling():
368377
# Test non-string input
369378
with pytest.raises(ValueError, match="Connection string must be a string"):
370379
process_connection_string(None)
380+
381+
382+
class TestConnectionAuthType:
383+
@patch("mssql_python.connection.ddbc_bindings.Connection")
384+
def test_auth_type_stored_on_connection(self, mock_ddbc_conn):
385+
mock_ddbc_conn.return_value = MagicMock()
386+
from mssql_python import connect
387+
388+
conn = connect("Server=test;Database=testdb;Authentication=ActiveDirectoryDefault")
389+
assert conn._auth_type == "default"
390+
conn.close()

0 commit comments

Comments
 (0)