summaryrefslogtreecommitdiff
path: root/vmdb/tags_tests.py
blob: e4d342a61de6df70d708e5b132e0e41530006d9a (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Copyright 2018  Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# =*= License: GPL-3+ =*=


import unittest


import vmdb


class TagsTests(unittest.TestCase):

    def test_lists_not_tags_initally(self):
        tags = vmdb.Tags()
        self.assertEqual(tags.get_tags(), [])

    def test_tells_if_tag_exists(self):
        tags = vmdb.Tags()
        self.assertFalse(tags.has_tag('foo'))
        tags.append('foo')
        self.assertTrue(tags.has_tag('foo'))
        self.assertEqual(tags.get_tags(), ['foo'])

    def test_remembers_order(self):
        tags = vmdb.Tags()
        tags.append('foo')
        tags.append('bar')
        self.assertTrue(tags.get_tags(), ['foo', 'bar'])

    def test_get_dev_raises_error_for_unknown_tag(self):
        tags = vmdb.Tags()
        with self.assertRaises(vmdb.UnknownTag):
            tags.get_dev('does-not-exist')

    def test_get_mount_point_raises_error_for_unknown_tag(self):
        tags = vmdb.Tags()
        with self.assertRaises(vmdb.UnknownTag):
            tags.get_mount_point('does-not-exist')

    def test_raises_error_for_reused_tag(self):
        tags = vmdb.Tags()
        tags.append('tag')
        with self.assertRaises(vmdb.TagInUse):
            tags.append('tag')

    def test_sets_dev(self):
        tags = vmdb.Tags()
        tags.append('first')
        tags.set_dev('first', '/dev/foo')
        self.assertEqual(tags.get_tags(), ['first'])
        self.assertEqual(tags.get_dev('first'), '/dev/foo')
        self.assertEqual(tags.get_mount_point('first'), None)

    def test_adds_mount_point(self):
        tags = vmdb.Tags()
        tags.append('first')
        tags.set_mount_point('first', '/mnt/foo')
        self.assertEqual(tags.get_tags(), ['first'])
        self.assertEqual(tags.get_dev('first'), None)
        self.assertEqual(tags.get_mount_point('first'), '/mnt/foo')

    def test_set_dev_raises_error_for_unknown_tag(self):
        tags = vmdb.Tags()
        with self.assertRaises(vmdb.UnknownTag):
            tags.set_dev('first', '/mnt/foo')

    def test_set_mount_point_raises_error_for_unknown_tag(self):
        tags = vmdb.Tags()
        with self.assertRaises(vmdb.UnknownTag):
            tags.set_mount_point('first', '/mnt/foo')

    def test_set_mount_point_raises_error_for_double_mount(self):
        tags = vmdb.Tags()
        tags.append('first')
        tags.set_mount_point('first', '/mnt/foo')
        with self.assertRaises(vmdb.AlreadyMounted):
            tags.set_mount_point('first', '/mnt/foo')

    def test_set_dev_raises_error_for_double_dev(self):
        tags = vmdb.Tags()
        tags.append('first')
        tags.set_dev('first', '/dev/foo')
        with self.assertRaises(vmdb.AlreadyHasDev):
            tags.set_dev('first', '/dev/foo')