File: test_cmdb.py

package info (click to toggle)
python-hardware 0.32.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,560 kB
  • sloc: python: 6,364; makefile: 24; sh: 6
file content (64 lines) | stat: -rw-r--r-- 2,203 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import unittest

from hardware import cmdb


class TestCmdb(unittest.TestCase):

    def test_update_cmdb_simple(self):
        data = [{'b': 1}]
        var = {'a': 1}
        result = cmdb.update_cmdb(data, var, var, False)
        self.assertTrue(result, cmdb)
        self.assertEqual(data, [{'a': 1, 'b': 1, 'used': 1}])
        self.assertEqual(var, {'a': 1, 'b': 1, 'used': 1})

    def test_update_cmdb_reuse(self):
        data = [{'a': 1, 'used': 1}]
        var = {'a': 1}
        result = cmdb.update_cmdb(data, var, var, False)
        self.assertTrue(result, cmdb)
        self.assertEqual(data, [{'a': 1, 'used': 1}])
        self.assertEqual(var, {'a': 1, 'used': 1})

    def test_update_cmdb_reuse2(self):
        data = [{'a': 1, 'b': 1, 'c': 1, 'used': 1}]
        cmdb_result = [{'a': 1, 'b': 2, 'c': 1, 'used': 1}]
        var = {'a': 1, 'b': 2}
        pref = {'a': 1}
        result = cmdb.update_cmdb(data, var, pref, False)
        self.assertTrue(result, cmdb_result)
        self.assertEqual(data, cmdb_result)
        self.assertEqual(var, {'a': 1, 'b': 2, 'c': 1, 'used': 1})

    def test_update_cmdb_full(self):
        data = [{'a': 2, 'used': 1}]
        var = {'a': 1}
        self.assertRaises(cmdb.CmdbError, cmdb.update_cmdb,
                          data, var, var, False)

    def test_update_cmdb_full2(self):
        data = [{'a': 'ff:ff'}]
        var = {'a': 'FF:FF'}
        self.assertRaises(cmdb.CmdbError, cmdb.update_cmdb,
                          data, var, var, True)


if __name__ == "__main__":
    unittest.main()

# test_cmdb.py ends here