File: test_shortcuts.py

package info (click to toggle)
software-properties 0.96.20.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,364 kB
  • ctags: 683
  • sloc: python: 5,125; makefile: 19; sh: 18
file content (54 lines) | stat: -rw-r--r-- 1,814 bytes parent folder | download | duplicates (3)
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/python

import apt

import unittest
import sys
sys.path.insert(0, "..")

from softwareproperties.SoftwareProperties import shortcut_handler
from softwareproperties.ppa import HTTPError
from mock import patch


class ShortcutsTestcase(unittest.TestCase):

    def setUp(self):
        # avoid polution from other tests
        apt.apt_pkg.config.set("Dir", "/")
        apt.apt_pkg.config.set("Dir::Etc", "etc/apt")
        apt.apt_pkg.config.set("Dir::Etc::sourcelist", "sources.list")
        apt.apt_pkg.config.set("Dir::Etc::sourceparts", "sources.list.d")

    def test_shortcut_none(self):
        line = "deb http://ubuntu.com/ubuntu trusty main"
        handler = shortcut_handler(line)
        self.assertEqual((line, None), handler.expand())

    def test_shortcut_ppa(self):
        line = "ppa:mvo"
        handler = shortcut_handler(line)
        self.assertEqual(
            ('deb http://ppa.launchpad.net/mvo/ppa/ubuntu trusty main',
             '/etc/apt/sources.list.d/mvo-ubuntu-ppa-trusty.list'),
            handler.expand("trusty", distro="ubuntu"))

    def test_shortcut_cloudarchive(self):
        line = "cloud-archive:folsom"
        handler = shortcut_handler(line)
        self.assertEqual(
            ('deb http://ubuntu-cloud.archive.canonical.com/ubuntu '\
             'precise-updates/folsom main',
             '/etc/apt/sources.list.d/cloudarchive-folsom.list'),
            handler.expand("precise", distro="ubuntu"))

    def test_shortcut_exception(self):
        with patch('softwareproperties.ppa.get_ppa_info_from_lp',
                   side_effect=HTTPError):
            with patch('softwareproperties.ppa.print_exc') as mock:
                shortcut_handler("ppa:mvo")
        self.assertTrue(mock.called)


if __name__ == "__main__":
    unittest.main()