-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow deleting tables before updating
Add table_delete to mod_config in the ConfigDBPipeConnector to allow table cleanup as part of transaction Add unittest for ConfigDBConnector
- Loading branch information
1 parent
92991f0
commit b2b16ab
Showing
3 changed files
with
41 additions
and
1 deletion.
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
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
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,31 @@ | ||
import os | ||
import sys | ||
|
||
from unittest import mock | ||
|
||
from unittest import TestCase | ||
|
||
modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
sys.path.insert(0, os.path.join(modules_path, 'src')) | ||
|
||
import swsssdk | ||
import fakeredis | ||
|
||
|
||
class TestConfigDB(TestCase): | ||
def test__configdb_pipe(self): | ||
|
||
s_db = swsssdk.ConfigDBPipeConnector() | ||
#Use fakeredis to mock redis db | ||
r_db = fakeredis.FakeStrictRedis(version=5) | ||
s_db.get_redis_client = lambda db_name: r_db | ||
s_db.db_name = "CONFIG_DB" | ||
|
||
s_db.mod_config({'TABLE_NAME': { 'row_key': {'column_key1': 'valueA1', 'column_key2': 'valueB1'}}}) | ||
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key1'), b'valueA1') | ||
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key2'), b'valueB1') | ||
s_db.mod_config({'TABLE_NAME': { 'row_key': {'column_key1': 'valueA2'}}}, table_delete='TABLE_NAME') | ||
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key1'), b'valueA2') | ||
self.assertEqual(r_db.hget('TABLE_NAME|row_key', 'column_key2'), None) | ||
|
||
|