~ubuntu-branches/debian/sid/obnam/sid

« back to all changes in this revision

Viewing changes to obnamlib/bag_store_tests.py

  • Committer: Package Import Robot
  • Author(s): Lars Wirzenius
  • Date: 2015-07-01 18:14:49 UTC
  • Revision ID: package-import@ubuntu.com-20150701181449-taxcvqg9cviw2cxo
Tags: 1.10-1
* New upstream version.
  * Fix "restore to /tmp messes up directory perms" by preventing
    restores to a non-empty directory. (Closes: #760492)
* Add build-dependency on git.
* Drop build-dependency on texlive and building of PDF form of manual.
  Texlive is an insanely large build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2015  Lars Wirzenius
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation, either version 3 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
#
 
16
# =*= License: GPL-3+ =*=
 
17
 
 
18
 
 
19
import shutil
 
20
import tempfile
 
21
import unittest
 
22
 
 
23
import obnamlib
 
24
 
 
25
 
 
26
class BagStoreTests(unittest.TestCase):
 
27
 
 
28
    def setUp(self):
 
29
        self.tempdir = tempfile.mkdtemp()
 
30
        self.fs = obnamlib.LocalFS(self.tempdir)
 
31
        self.store = obnamlib.BagStore()
 
32
        self.store.set_location(self.fs, '.')
 
33
        self.bag = obnamlib.Bag()
 
34
        bag_id = self.store.reserve_bag_id()
 
35
        self.bag.set_id(bag_id)
 
36
 
 
37
    def tearDown(self):
 
38
        shutil.rmtree(self.tempdir)
 
39
 
 
40
    def assertEqualBags(self, a, b):
 
41
        self.assertEqual(a.get_id(), b.get_id())
 
42
        self.assertEqual(len(a), len(b))
 
43
        for i in range(len(a)):
 
44
            self.assertEqual(a[i], b[i])
 
45
 
 
46
    def test_stores_and_retrieves_an_empty_bag(self):
 
47
        self.store.put_bag(self.bag)
 
48
        new_bag = self.store.get_bag(self.bag.get_id())
 
49
        self.assertEqualBags(new_bag, self.bag)
 
50
 
 
51
    def test_stores_and_retrieves_a_full_bag(self):
 
52
        self.bag.append('foo')
 
53
        self.store.put_bag(self.bag)
 
54
        new_bag = self.store.get_bag(self.bag.get_id())
 
55
        self.assertEqualBags(new_bag, self.bag)
 
56
 
 
57
    def test_has_no_bags_initially(self):
 
58
        store = obnamlib.BagStore()
 
59
        store.set_location(self.fs, 'empty')
 
60
        self.assertEqual(list(store.get_bag_ids()), [])
 
61
 
 
62
    def test_has_a_put_bag(self):
 
63
        self.store.put_bag(self.bag)
 
64
        self.assertTrue(self.store.has_bag(self.bag.get_id()))
 
65
 
 
66
    def test_does_not_have_a_removed_bag(self):
 
67
        self.store.put_bag(self.bag)
 
68
        self.store.remove_bag(self.bag.get_id())
 
69
        self.assertFalse(self.store.has_bag(self.bag.get_id()))
 
70
 
 
71
    def test_lists_bag_that_has_been_put(self):
 
72
        self.store.put_bag(self.bag)
 
73
        self.assertEqual(list(self.store.get_bag_ids()), [self.bag.get_id()])
 
74
 
 
75
    def test_removes_bag(self):
 
76
        self.store.put_bag(self.bag)
 
77
        self.store.remove_bag(self.bag.get_id())
 
78
        self.assertEqual(list(self.store.get_bag_ids()), [])