Skip to content

Commit b4e1bd5

Browse files
committed
define Session.hostname and Session.__str__
1 parent 0f07281 commit b4e1bd5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/sasctl/core.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ def add_stderr_logger(self, level=logging.INFO):
334334
def username(self):
335335
return self._settings.get('username')
336336

337+
@property
338+
def hostname(self):
339+
return self._settings.get('domain')
340+
341+
337342
def send(self, request, **kwargs):
338343
if self.message_log.isEnabledFor(logging.DEBUG):
339344
r = copy.deepcopy(request)
@@ -567,6 +572,14 @@ def __exit__(self, exc_type, exc_val, exc_tb):
567572

568573
super(Session, self).__exit__()
569574

575+
def __str__(self):
576+
return ("{class_}(hostname='{hostname}', username='{username}', "
577+
"protocol='{protocol}', verify_ssl={verify})".format(
578+
class_=type(self).__name__,
579+
hostname=self.hostname,
580+
username=self.username,
581+
protocol=self._settings.get('protocol'),
582+
verify=self.verify))
570583

571584
def is_uuid(id):
572585
try:

tests/unit/test_session.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_new_session(missing_packages):
2424
with mock.patch('sasctl.core.Session.get_token'):
2525
s = Session(HOST, USERNAME, PASSWORD)
2626
assert USERNAME == s.username
27-
assert HOST == s._settings['domain']
27+
assert HOST == s.hostname
2828
assert 'https' == s._settings['protocol']
2929
assert USERNAME == s._settings['username']
3030
assert PASSWORD == s._settings['password']
@@ -270,3 +270,16 @@ def test_authentication_failure():
270270
with pytest.raises(AuthenticationError):
271271
Session('hostname', 'username', 'password')
272272

273+
274+
def test_str():
275+
import os
276+
277+
# Remove any environment variables disabling SSL verification
278+
_ = os.environ.pop('SSLREQCERT')
279+
280+
with mock.patch('sasctl.core.Session.get_token', return_value='token'):
281+
282+
s = Session('hostname', 'username', 'password')
283+
284+
assert str(s) == "Session(hostname='hostname', username='username', " \
285+
"protocol='https', verify_ssl=True)"

0 commit comments

Comments
 (0)