Skip to content

Commit

Permalink
add validated_config_db_connector_test
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelmsft committed Sep 18, 2022
1 parent 201f005 commit 9b37211
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/validated_config_db_connector_test.py
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) == {}


0 comments on commit 9b37211

Please sign in to comment.