forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validated_config_db_connector_test
- Loading branch information
1 parent
201f005
commit 9b37211
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import imp | ||
import os | ||
import mock | ||
|
||
imp.load_source('validated_config_db_connector', \ | ||
os.path.join(os.path.dirname(__file__), '..', 'config', 'validated_config_db_connector.py')) | ||
import validated_config_db_connector | ||
|
||
from unittest import TestCase | ||
from mock import patch | ||
from generic_config_updater.gu_common import EmptyTableError | ||
from utilities_common.db import Db | ||
|
||
SAMPLE_TABLE = 'VLAN' | ||
SAMPLE_KEY = 'Vlan1000' | ||
SAMPLE_VALUE_NON_EMPTY = {'vlanid': '1000'} | ||
SAMPLE_VALUE_EMPTY = None | ||
|
||
|
||
class TestValidatedConfigDBConnector(TestCase): | ||
''' | ||
Test Class for validated_config_db_connector.py | ||
''' | ||
def test_validated_config_db_connector(self): | ||
mock_generic_updater = mock.Mock() | ||
mock_generic_updater.apply_patch = mock.Mock(side_effect=EmptyTableError) | ||
with mock.patch('validated_config_db_connector.GenericUpdater', return_value=mock_generic_updater): | ||
db = Db() | ||
db.cfgdb.set_entry(SAMPLE_TABLE, SAMPLE_KEY, SAMPLE_VALUE_NON_EMPTY) | ||
with mock.patch('validated_config_db_connector.ConfigDBConnector', return_value=db.cfgdb): | ||
validated_config_db_connector.validated_set_entry(SAMPLE_TABLE, SAMPLE_KEY, SAMPLE_VALUE_EMPTY) | ||
assert db.cfgdb.get_entry(SAMPLE_TABLE, SAMPLE_KEY) == {} | ||
|
||
|