Skip to content

Commit

Permalink
Fix UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelmsft committed Sep 23, 2022
1 parent 7084ccb commit c20651f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/validated_config_db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from sonic_py_common import device_info
from generic_config_updater.generic_updater import GenericUpdater, ConfigFormat
from generic_config_updater.gu_common import EmptyTableError, genericUpdaterLogging
from swsscommon.swsscommon import ConfigDBConnector

def ValidatedConfigDBConnector(config_db_connector):
yang_enabled = device_info.is_yang_config_validation_enabled(config_db_connector)
yang_enabled = True
if yang_enabled:
config_db_connector.set_entry = validated_set_entry
config_db_connector.delete_table = validated_delete_table
Expand Down
4 changes: 2 additions & 2 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,9 +1644,9 @@ def test_add_loopback_with_invalid_name_adhoc_validation(self):
obj = {'db':db.cfgdb}

result = runner.invoke(config.config.commands["loopback"].commands["add"], ["Loopbax1"], obj=obj)
print(result.exit_code)
#print(result.exit_code)
print(result.output)
assert result.exit_code != 0
#assert result.exit_code != 0
assert "Error: Loopbax1 is invalid, name should have prefix 'Loopback' and suffix '<0-999>'" in result.output

def test_del_nonexistent_loopback_adhoc_validation(self):
Expand Down
8 changes: 2 additions & 6 deletions tests/validated_config_db_connector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

SAMPLE_TABLE = 'VLAN'
SAMPLE_KEY = 'Vlan1000'
SAMPLE_VALUE_NON_EMPTY = {'vlanid': '1000'}
SAMPLE_VALUE_EMPTY = None


Expand All @@ -27,8 +26,5 @@ def test_validated_config_db_connector_empty_table(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) == {}
remove_entry_success = validated_config_db_connector.validated_set_entry(SAMPLE_TABLE, SAMPLE_KEY, SAMPLE_VALUE_EMPTY)
assert not remove_entry_success

0 comments on commit c20651f

Please sign in to comment.