mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Merge pull request #43842 from vernondcole/unit-test-sdb
provide a unit test for the sdb utility
This commit is contained in:
commit
1ff27a4b2b
1 changed files with 64 additions and 0 deletions
64
tests/unit/utils/test_sdb.py
Normal file
64
tests/unit/utils/test_sdb.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
:codeauthor: :email:`Vernon Cole <vernondcole@gmail.com>`
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Import Python Libs
|
||||||
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Import Salt Testing Libs
|
||||||
|
from tests.support.runtests import RUNTIME_VARS
|
||||||
|
from tests.support.mixins import LoaderModuleMockMixin
|
||||||
|
from tests.support.unit import TestCase, skipIf
|
||||||
|
from tests.support.mock import (
|
||||||
|
NO_MOCK,
|
||||||
|
NO_MOCK_REASON
|
||||||
|
)
|
||||||
|
|
||||||
|
# Import Salt Libs
|
||||||
|
import salt.utils.sdb as sdb
|
||||||
|
|
||||||
|
TEMP_DATABASE_FILE = os.path.join(RUNTIME_VARS.TMP, 'test_sdb.sqlite')
|
||||||
|
|
||||||
|
SDB_OPTS = {
|
||||||
|
'extension_modules': '',
|
||||||
|
'test_sdb_data': {
|
||||||
|
'driver': 'sqlite3',
|
||||||
|
'database': TEMP_DATABASE_FILE,
|
||||||
|
'table': 'sdb',
|
||||||
|
'create_table': True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
class SdbTestCase(TestCase, LoaderModuleMockMixin):
|
||||||
|
'''
|
||||||
|
Test cases for salt.modules.sdb
|
||||||
|
'''
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
try:
|
||||||
|
os.unlink(TEMP_DATABASE_FILE)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setup_loader_modules(self):
|
||||||
|
return {sdb: {}}
|
||||||
|
|
||||||
|
# test with SQLite database key not presest
|
||||||
|
|
||||||
|
def test_sqlite_get_not_found(self):
|
||||||
|
what = sdb.sdb_get(
|
||||||
|
'sdb://test_sdb_data/thisKeyDoesNotExist', SDB_OPTS)
|
||||||
|
self.assertEqual(what, None)
|
||||||
|
|
||||||
|
# test with SQLite database write and read
|
||||||
|
|
||||||
|
def test_sqlite_get_found(self):
|
||||||
|
expected = {b'name': b'testone', b'number': 46}
|
||||||
|
sdb.sdb_set('sdb://test_sdb_data/test1', expected, SDB_OPTS)
|
||||||
|
resp = sdb.sdb_get('sdb://test_sdb_data/test1', SDB_OPTS)
|
||||||
|
self.assertEqual(resp, expected)
|
Loading…
Add table
Reference in a new issue