salt/tests/unit/modules/test_sqlite3.py
rallytime 3273bbdab7
Merge branch '2017.7' into '2018.3'
Conflicts:
  - doc/ref/configuration/master.rst
  - doc/ref/modules/all/index.rst
  - doc/topics/grains/index.rst
  - doc/topics/releases/2016.3.4.rst
  - doc/topics/spm/spm_formula.rst
  - doc/topics/tutorials/cron.rst
  - doc/topics/tutorials/index.rst
  - doc/topics/tutorials/stormpath.rst
  - salt/engines/slack.py
  - salt/log/handlers/fluent_mod.py
  - salt/modules/cyg.py
  - salt/modules/junos.py
  - salt/modules/namecheap_dns.py
  - salt/modules/namecheap_domains.py
  - salt/modules/namecheap_ns.py
  - salt/modules/namecheap_ssl.py
  - salt/modules/namecheap_users.py
  - salt/modules/reg.py
  - salt/modules/tomcat.py
  - salt/modules/vault.py
  - salt/modules/win_file.py
  - salt/modules/zpool.py
  - salt/output/highstate.py
  - salt/renderers/pass.py
  - salt/runners/cache.py
  - salt/states/boto_apigateway.py
  - salt/states/boto_iam.py
  - salt/states/boto_route53.py
  - salt/states/msteams.py
  - salt/states/reg.py
  - salt/states/win_iis.py
  - tests/integration/modules/test_cmdmod.py
  - tests/integration/states/test_user.py
  - tests/support/helpers.py
  - tests/unit/cloud/clouds/test_openstack.py
  - tests/unit/fileserver/test_gitfs.py
  - tests/unit/modules/test_junos.py
  - tests/unit/pillar/test_git.py
  - tests/unit/states/test_win_path.py
  - tests/unit/test_pillar.py
  - tests/unit/utils/test_format_call.py
  - tests/unit/utils/test_utils.py
  - tests/unit/utils/test_warnings.py
2018-06-01 14:54:12 -04:00

139 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
'''
# Import Python Libs
from __future__ import absolute_import, unicode_literals, print_function
# Import Salt Testing Libs
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.modules.sqlite3 as sqlite3
class MockSqlite3(object):
'''
Mock sqlite3 class
'''
version = '2.6.0'
sqlite_version = '3.8.2'
def __init__(self):
self.dbase = None
self.isolation_level = None
def connect(self, dbase, isolation_level=None):
'''
Mock connect method
'''
self.dbase = dbase
self.isolation_level = isolation_level
return MockSqlite3()
@staticmethod
def cursor():
'''
Mock connect method
'''
return MockSqlite3()
@staticmethod
def execute(sql):
'''
Mock connect method
'''
return sql
@staticmethod
def fetchall():
'''
Mock connect method
'''
return True
@skipIf(NO_MOCK, NO_MOCK_REASON)
class Sqlite3TestCase(TestCase, LoaderModuleMockMixin):
'''
TestCase for salt.modules.sqlite3
'''
def setup_loader_modules(self):
return {sqlite3: {'sqlite3': MockSqlite3()}}
# 'version' function tests: 1
def test_version(self):
'''
Tests if it return version of pysqlite.
'''
self.assertEqual(sqlite3.version(), '2.6.0')
# 'sqlite_version' function tests: 1
def test_sqlite_version(self):
'''
Tests if it return version of sqlite.
'''
self.assertEqual(sqlite3.sqlite_version(), '3.8.2')
# 'modify' function tests: 1
def test_modify(self):
'''
Tests if it issue an SQL query to sqlite3 (with no return data).
'''
self.assertFalse(sqlite3.modify())
self.assertTrue(sqlite3.modify
('/root/test.db',
'CREATE TABLE test(id INT, testdata TEXT);'))
# 'fetch' function tests: 1
def test_fetch(self):
'''
Tests if it retrieve data from an sqlite3 db
(returns all rows, be careful!)
'''
self.assertFalse(sqlite3.fetch())
self.assertTrue(sqlite3.fetch
('/root/test.db',
'CREATE TABLE test(id INT, testdata TEXT);'))
# 'tables' function tests: 1
def test_tables(self):
'''
Tests if it show all tables in the database.
'''
self.assertFalse(sqlite3.tables())
self.assertTrue(sqlite3.tables('/root/test.db'))
# 'indices' function tests: 1
def test_indices(self):
'''
Tests if it show all indices in the database.
'''
self.assertFalse(sqlite3.indices())
self.assertTrue(sqlite3.indices('/root/test.db'))
# 'indexes' function tests: 1
def test_indexes(self):
'''
Tests if it show all indices in the database,
for people with poor spelling skills
'''
self.assertTrue(sqlite3.indexes('/root/test.db'))