~matsubara/python-oops-datedir-repo/improve-db-statement-matches

« back to all changes in this revision

Viewing changes to oops_datedir_repo/tests/test_repository.py

  • Committer: Robert Collins
  • Date: 2011-08-16 02:21:20 UTC
  • Revision ID: robertc@robertcollins.net-20110816022120-5hgdf7bvshy3gobw
Bring in a datedir repo object as we extract code from LP.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2010, 2011, Canonical Ltd
 
2
#
 
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.
 
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 Affero General Public License for more details.
 
12
#
 
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).
 
16
 
 
17
"""Tests for the date-directory based repository."""
 
18
 
 
19
__metaclass__ = type
 
20
 
 
21
import datetime
 
22
import os.path
 
23
import stat
 
24
 
 
25
from fixtures import TempDir
 
26
from pytz import utc
 
27
import testtools
 
28
 
 
29
from oops_datedir_repo import DateDirRepo
 
30
from oops_datedir_repo.uniquefileallocator import UniqueFileAllocator
 
31
 
 
32
 
 
33
class TestDateDirRepo(testtools.TestCase):
 
34
 
 
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)
 
40
 
 
41
        # Set up default file creation mode to rwx------ as some restrictive
 
42
        # servers do.
 
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)
 
47
 
 
48
        errorfile = os.path.join(repo.log_namer.output_dir(now), '01800.T1')
 
49
        self.assertTrue(os.path.exists(errorfile))
 
50
 
 
51
        # Check errorfile is set with the correct permission: rw-r--r--
 
52
        st = os.stat(errorfile)
 
53
        wanted_permission = (
 
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)
 
58
 
 
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)