Skip to content

Commit 65e1923

Browse files
author
Emanuel Winblad
committed
Adjustment in Client constructor to allow for better mocking during testing.
1 parent 6dcb8cf commit 65e1923

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,14 @@ except vilfo.exceptions.AuthenticationException:
7777

7878
The `vilfo-api-client` library defines a set of exceptions that can be used to handle errors. These exception classes are located under `vilfo.exceptions`.
7979

80-
*Additional information about the exceptions will be added and exception and error handling will be improved further.*
80+
*Additional information about the exceptions will be added and exception and error handling will be improved further.*
81+
82+
## Changelog
83+
84+
### Version 0.3.1
85+
86+
Minor adjustment in Client constructor to allow for better mocking during testing.
87+
88+
### Version 0.3
89+
90+
Initial stable release.

vilfo/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def __init__(self, host, token, ssl=False):
2525
# MAC address not resolved yet
2626
self.mac = None
2727
self._mac_resolution_failed = False
28+
self._cached_mac = None
2829

2930
try:
30-
self.resolve_mac_address()
31+
self.mac = self.resolve_mac_address()
3132
except vilfo.exceptions.VilfoException:
3233
pass
3334

@@ -64,8 +65,8 @@ def resolve_mac_address(self, force_retry=False):
6465
Raises:
6566
- vilfo.exception.VilfoException: if the resolution failed
6667
"""
67-
if (self.mac or self._mac_resolution_failed) and not force_retry:
68-
return self.mac
68+
if (self._cached_mac or self._mac_resolution_failed) and not force_retry:
69+
return self._cached_mac
6970

7071
resolved_mac = None
7172
host_is_hostname = False
@@ -94,7 +95,7 @@ def resolve_mac_address(self, force_retry=False):
9495
raise vilfo.exceptions.VilfoException
9596

9697
self._mac_resolution_failed = False
97-
self.mac = resolved_mac
98+
self._cached_mac = resolved_mac
9899

99100
return resolved_mac
100101

0 commit comments

Comments
 (0)