Skip to content

Commit 91b57a7

Browse files
committed
Updated unit authentication tests
1 parent 339953b commit 91b57a7

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

Diff for: src/codeflare_sdk/cluster/auth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def login(self) -> str:
111111
client.AuthenticationApi(api_client).get_api_group()
112112
config_path = None
113113
return "Logged into %s" % self.server
114-
except client.ApiException:
114+
except client.ApiException: # pragma: no cover
115115
api_client = None
116116
print("Authentication Error please provide the correct token + server")
117117

@@ -148,7 +148,7 @@ def load_kube_config(self):
148148
api_client = None
149149
config.load_kube_config(config_path)
150150
response = "Loaded user config file at path %s" % self.kube_config_path
151-
except config.ConfigException:
151+
except config.ConfigException: # pragma: no cover
152152
config_path = None
153153
raise Exception("Please specify a config file path")
154154
return response

Diff for: tests/unit_test.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,23 @@ def att_side_effect(self):
9090

9191
def test_token_auth_creation():
9292
try:
93-
token_auth = TokenAuthentication("token", "server")
94-
assert token_auth.token == "token"
95-
assert token_auth.server == "server"
96-
assert token_auth.skip_tls == False
97-
98-
token_auth = TokenAuthentication("token", server="server")
99-
assert token_auth.token == "token"
100-
assert token_auth.server == "server"
101-
assert token_auth.skip_tls == False
102-
10393
token_auth = TokenAuthentication(token="token", server="server")
10494
assert token_auth.token == "token"
10595
assert token_auth.server == "server"
10696
assert token_auth.skip_tls == False
97+
assert token_auth.ca_cert_path == None
10798

10899
token_auth = TokenAuthentication(token="token", server="server", skip_tls=True)
109100
assert token_auth.token == "token"
110101
assert token_auth.server == "server"
111102
assert token_auth.skip_tls == True
103+
assert token_auth.ca_cert_path == None
112104

113105
token_auth = TokenAuthentication(token="token", server="server", skip_tls=False)
114106
assert token_auth.token == "token"
115107
assert token_auth.server == "server"
116108
assert token_auth.skip_tls == False
109+
assert token_auth.ca_cert_path == None
117110

118111
token_auth = TokenAuthentication(
119112
token="token", server="server", skip_tls=False, ca_cert_path="path/to/cert"
@@ -130,7 +123,9 @@ def test_token_auth_creation():
130123
def test_token_auth_login_logout(mocker):
131124
mocker.patch.object(client, "ApiClient")
132125

133-
token_auth = TokenAuthentication(token="testtoken", server="testserver:6443")
126+
token_auth = TokenAuthentication(
127+
token="testtoken", server="testserver:6443", skip_tls=False, ca_cert_path=None
128+
)
134129
assert token_auth.login() == ("Logged into testserver:6443")
135130
assert token_auth.logout() == ("Successfully logged out of testserver:6443")
136131

@@ -139,11 +134,11 @@ def test_token_auth_login_tls(mocker):
139134
mocker.patch.object(client, "ApiClient")
140135

141136
token_auth = TokenAuthentication(
142-
token="testtoken", server="testserver:6443", skip_tls=True
137+
token="testtoken", server="testserver:6443", skip_tls=True, ca_cert_path=None
143138
)
144139
assert token_auth.login() == ("Logged into testserver:6443")
145140
token_auth = TokenAuthentication(
146-
token="testtoken", server="testserver:6443", skip_tls=False
141+
token="testtoken", server="testserver:6443", skip_tls=False, ca_cert_path=None
147142
)
148143
assert token_auth.login() == ("Logged into testserver:6443")
149144
token_auth = TokenAuthentication(
@@ -156,11 +151,12 @@ def test_token_auth_login_tls(mocker):
156151

157152

158153
def test_load_kube_config(mocker):
159-
kube_config_auth = KubeConfigFileAuthentication()
160-
kube_config_auth.kube_config_path = "/path/to/your/config"
161154
mocker.patch.object(config, "load_kube_config")
162-
155+
kube_config_auth = KubeConfigFileAuthentication(
156+
kube_config_path="/path/to/your/config"
157+
)
163158
response = kube_config_auth.load_kube_config()
159+
164160
assert (
165161
response
166162
== "Loaded user config file at path %s" % kube_config_auth.kube_config_path

0 commit comments

Comments
 (0)