~ubuntu-test-case-dev/ubuntu-test-cases/desktop

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
#!/usr/bin/python3
#
# Copyright (C) 2013, Canonical Ltd (http://www.canonical.com/)
#
# This file is part of ubuntu-test-cases.
#
# ubuntu-test-cases 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.
#
# ubuntu-test-cases 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 ubuntu-test-cases.  If not, see
# <http://www.gnu.org/licenses/>.

"""Archive location should only match the timezone and not the locale"""

import logging
import unittest


class ArchiveLocationTest(unittest.TestCase):
    SOURCES_FILE = '/etc/apt/sources.list'

    # Timezone is America/Chicago. Hence correct archive is us.archive.ubuntu.com
    # de.archive.ubuntu.com is incorrect even when the locale is de_DE.UTF-8
    RIGHT_LOC = 'us.archive.ubuntu.com'
    WRONG_LOC = 'de.archive.ubuntu.com'

    def test_archive_location(self):
        """Test sources.list contains correct archive settings."""
        logging.info('Reading {!r} file...'.format(self.SOURCES_FILE))
        with open(self.SOURCES_FILE) as f:
            sources = f.read()

        logging.info('Checking that archive location is ({!r})'
                     .format(self.RIGHT_LOC))
        self.assertTrue(self.RIGHT_LOC in sources,
                        'Archive is not US specific')

        logging.info('Checking that archive location is NOT ({!r})'
                     .format(self.WRONG_LOC))
        self.assertTrue(self.WRONG_LOC not in sources,
                        'Archive is set according to locale - German')

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG,
                        format='%(levelname)s: %(message)s')
    unittest.main()