Skip to content

Commit

Permalink
Fix unit test for device_info
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrallen committed May 13, 2021
1 parent 19b0314 commit a305336
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_chassis_info():

try:
# Init statedb connection
db = swsscommon.SonicV2Connector()
db = SonicV2Connector()
db.connect(db.STATE_DB)
table = CHASSIS_INFO_TABLE.format(1)

Expand Down
10 changes: 5 additions & 5 deletions src/sonic-py-common/tests/device_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from sonic_py_common import device_info

from . import mock_swsssdk
from .mock_swsssdk import SonicV2Connector

# TODO: Remove this if/else block once we no longer support Python 2
if sys.version_info.major == 3:
Expand Down Expand Up @@ -71,11 +71,11 @@ def test_get_platform(self):
assert result == "x86_64-mlnx_msn2700-r0"

def test_get_chassis_info(self):
with mock.patch("device_info.swsssdk", new=mock_swsssdk):
with mock.patch("sonic_py_common.device_info.SonicV2Connector", new=SonicV2Connector):
result = device_info.get_chassis_info()
truth = {"serial": self.TEST_SERIAL,
"model": self.TEST_MODEL,
"revision": self.TEST_REV}
truth = {"serial": SonicV2Connector.TEST_SERIAL,
"model": SonicV2Connector.TEST_MODEL,
"revision": SonicV2Connector.TEST_REV}
assert result == truth

@classmethod
Expand Down
5 changes: 4 additions & 1 deletion src/sonic-py-common/tests/mock_swsssdk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class SonicV2Connector:
TEST_SERIAL = "MT1822K07815"
TEST_MODEL = "MSN2700-CS2FO"
TEST_REV = "A1"

def __init__(self):
self.STATE_DB = 'STATE_DB'
Expand All @@ -10,4 +13,4 @@ def connect(self, db):
pass

def get(self, db, table, field):
self.data.get(field, "N/A")
return self.data.get(field, "N/A")

0 comments on commit a305336

Please sign in to comment.