2012-12-06 17:29:32 -08:00
|
|
|
import os
|
2012-12-18 08:54:38 -08:00
|
|
|
from testtools import TestCase
|
2012-12-06 17:29:32 -08:00
|
|
|
from reddwarfclient import utils
|
|
|
|
from reddwarfclient import versions
|
|
|
|
|
|
|
|
|
2012-12-18 08:54:38 -08:00
|
|
|
class UtilsTest(TestCase):
|
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
def test_add_hookable_mixin(self):
|
|
|
|
def func():
|
|
|
|
pass
|
2012-12-18 08:54:38 -08:00
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
hook_type = "hook_type"
|
|
|
|
mixin = utils.HookableMixin()
|
|
|
|
mixin.add_hook(hook_type, func)
|
|
|
|
self.assertTrue(hook_type in mixin._hooks_map)
|
|
|
|
self.assertTrue(func in mixin._hooks_map[hook_type])
|
2012-12-18 08:54:38 -08:00
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
def test_run_hookable_mixin(self):
|
|
|
|
def func():
|
|
|
|
pass
|
2012-12-18 08:54:38 -08:00
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
hook_type = "hook_type"
|
|
|
|
mixin = utils.HookableMixin()
|
|
|
|
mixin.add_hook(hook_type, func)
|
|
|
|
mixin.run_hooks(hook_type)
|
2012-12-18 08:54:38 -08:00
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
def test_environment(self):
|
|
|
|
self.assertEqual('', utils.env())
|
|
|
|
self.assertEqual('passing', utils.env(default='passing'))
|
2012-12-18 08:54:38 -08:00
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
os.environ['test_abc'] = 'passing'
|
|
|
|
self.assertEqual('passing', utils.env('test_abc'))
|
|
|
|
self.assertEqual('', utils.env('test_abcd'))
|
2012-12-18 08:54:38 -08:00
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
def test_slugify(self):
|
|
|
|
import unicodedata
|
2012-12-18 08:54:38 -08:00
|
|
|
|
2012-12-06 17:29:32 -08:00
|
|
|
self.assertEqual('not_unicode', utils.slugify('not_unicode'))
|
|
|
|
self.assertEqual('unicode', utils.slugify(unicode('unicode')))
|
|
|
|
self.assertEqual('slugify-test', utils.slugify('SLUGIFY% test!'))
|