summaryrefslogtreecommitdiff
path: root/obnamlib/chunkid_token_map_tests.py
blob: b97734feb4d3f18b250b98b58b25943a67cf7ed6 (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
# Copyright (C) 2015  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/>.


import unittest

import obnamlib


class ChunkIdTokenMapTests(unittest.TestCase):

    def setUp(self):
        self.map = obnamlib.ChunkIdTokenMap()

    def test_is_empty_initially(self):
        self.assertEqual(list(self.map), [])

    def test_adds_a_pair(self):
        chunk_id = '123'
        token = 'foobar'
        self.map.add(chunk_id, token)
        self.assertEqual(list(self.map), [(chunk_id, token)])

    def test_contains_added_token(self):
        chunk_id = '123'
        token = 'foobar'
        self.map.add(chunk_id, token)
        self.assertIn(token, self.map)

    def test_adds_second_chunk_id_with_same_token(self):
        chunk_id_1 = '123'
        chunk_id_2 = '456'
        token = 'foobar'
        self.map.add(chunk_id_1, token)
        self.map.add(chunk_id_2, token)
        self.assertEqual(
            sorted(self.map),
            sorted([(chunk_id_1, token), (chunk_id_2, token)]))

    def test_returns_empty_list_for_unadded_token(self):
        self.assertEqual(self.map.get('abc'), [])

    def test_gets_added_token(self):
        chunk_id = '123'
        token = 'foobar'
        self.map.add(chunk_id, token)
        self.assertEqual(self.map.get(token), [chunk_id])

    def test_clears_itself(self):
        chunk_id = '123'
        token = 'foobar'
        self.map.add(chunk_id, token)
        self.map.clear()
        self.assertEqual(list(self.map), [])