1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
19
from nova import clean
20
from nova import exception
27
class CleanTestCase(test.TrialTestCase):
28
def assertAllPass(self, func, values):
30
self.assertEqual(func(v), v)
32
def assertAllFail(self, func, values):
34
self.assertRaises(AssertionError, func, v)
36
def test_cleaner(self):
37
cleaner = clean.Cleaner(lowerkey=lower)
39
out = cleaner({'lowerkey': 'DUDE',
41
self.assertEqual(out['lowerkey'], 'dude')
42
self.assertEqual(out['ignorekey'], 'FOO')
44
def test_cleaner_error(self):
45
cleaner = clean.Cleaner(errorkey=self.assert_)
47
self.assertRaises(exception.ApiError, cleaner, {'errorkey': False})
49
def test_key_pair_name(self):
50
good = ['asdf', 'FOO', '1234', 'a_d2- ']
51
bad = ['a*d', 'a' * 256, '[][]]']
53
self.assertAllPass(clean.key_pair_name, good)
54
self.assertAllFail(clean.key_pair_name, bad)