1
# Copyright (c) 2010, 2011, Canonical Ltd
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero 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.
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 Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
# GNU Affero General Public License version 3 (see the file LICENSE).
17
"""Tests for the date-directory based repository."""
25
from fixtures import TempDir
29
from oops_datedir_repo import DateDirRepo
30
from oops_datedir_repo.uniquefileallocator import UniqueFileAllocator
33
class TestDateDirRepo(testtools.TestCase):
35
def test_publish_permissions(self):
36
errordir = self.useFixture(TempDir()).path
37
repo = DateDirRepo(errordir, 'T')
38
report = {'id': 'OOPS-91T1'}
39
now = datetime.datetime(2006, 04, 01, 00, 30, 00, tzinfo=utc)
41
# Set up default file creation mode to rwx------ as some restrictive
43
umask_permission = stat.S_IRWXG | stat.S_IRWXO
44
old_umask = os.umask(umask_permission)
45
self.addCleanup(os.umask, old_umask)
46
repo.publish(report, now)
48
errorfile = os.path.join(repo.log_namer.output_dir(now), '01800.T1')
49
self.assertTrue(os.path.exists(errorfile))
51
# Check errorfile is set with the correct permission: rw-r--r--
52
st = os.stat(errorfile)
54
stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
55
# Get only the permission bits for this file.
56
file_permission = stat.S_IMODE(st.st_mode)
57
self.assertEqual(file_permission, wanted_permission)
59
def test_sets_log_namer_to_a_UniqueFileAllocator(self):
60
repo = DateDirRepo(self.useFixture(TempDir()).path, 'T')
61
self.assertIsInstance(repo.log_namer, UniqueFileAllocator)