2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-06-27 10:56:18 +00:00
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-03-28 05:45:49 +00:00
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class DataModuleTest(ModuleCase):
|
2012-03-28 05:45:49 +00:00
|
|
|
'''
|
|
|
|
Validate the data module
|
|
|
|
'''
|
|
|
|
def _clear_db(self):
|
|
|
|
'''
|
|
|
|
Clear out the database
|
|
|
|
'''
|
|
|
|
self.run_function('data.clear')
|
|
|
|
|
|
|
|
def test_load_dump(self):
|
|
|
|
'''
|
|
|
|
data.load
|
|
|
|
data.dump
|
|
|
|
'''
|
|
|
|
self._clear_db()
|
|
|
|
self.assertTrue(self.run_function('data.dump', ['{"foo": "bar"}']))
|
|
|
|
self.assertEqual(self.run_function('data.load'), {'foo': 'bar'})
|
|
|
|
self._clear_db()
|
|
|
|
|
|
|
|
def test_get_update(self):
|
|
|
|
'''
|
2016-02-10 17:22:08 +00:00
|
|
|
data.get
|
2012-03-28 05:45:49 +00:00
|
|
|
data.update
|
|
|
|
'''
|
|
|
|
self._clear_db()
|
2016-02-10 17:22:08 +00:00
|
|
|
self.assertTrue(self.run_function('data.update', ['spam', 'eggs']))
|
2016-02-10 18:40:41 +00:00
|
|
|
self.assertEqual(self.run_function('data.get', ['spam']), 'eggs')
|
2016-02-10 17:22:08 +00:00
|
|
|
|
|
|
|
self.assertTrue(self.run_function('data.update', ['unladen', 'swallow']))
|
2016-02-10 18:40:41 +00:00
|
|
|
self.assertEqual(self.run_function('data.get', ['["spam", "unladen"]']), ['eggs', 'swallow'])
|
2012-03-28 05:45:49 +00:00
|
|
|
self._clear_db()
|
|
|
|
|
2015-03-30 21:01:28 +00:00
|
|
|
def test_cas_update(self):
|
|
|
|
'''
|
|
|
|
data.update
|
|
|
|
data.cas
|
2016-02-10 17:22:08 +00:00
|
|
|
data.get
|
2015-03-30 21:01:28 +00:00
|
|
|
'''
|
|
|
|
self._clear_db()
|
2016-02-10 17:22:08 +00:00
|
|
|
self.assertTrue(self.run_function('data.update', ['spam', 'eggs']))
|
|
|
|
self.assertTrue(self.run_function('data.cas', ['spam', 'green', 'eggs']))
|
2016-02-10 18:40:41 +00:00
|
|
|
self.assertEqual(self.run_function('data.get', ['spam']), 'green')
|