~jamesodhunt/click/add-utf8-test

« back to all changes in this revision

Viewing changes to click/tests/integration/test_install.py

  • Committer: CI bot
  • Author(s): Daniel Holbach, Michael Vogt, Colin Watson
  • Date: 2014-09-09 10:00:56 UTC
  • mfrom: (425.1.91 devel)
  • Revision ID: ps-jenkins@lists.canonical.com-20140909100056-zsdxby5edojqfr9a
Click 0.4.32: test improvements/cleanup, re-enable signature checking, optionally call click-review after build. Fixes: 1324853, 1330770
Approved by: PS Jenkins bot, Colin Watson

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""Integration tests for the click install feature."""
17
17
 
18
 
import os
19
18
import subprocess
20
 
import unittest
21
19
 
22
 
from .helpers import ClickTestCase
 
20
from .helpers import (
 
21
    require_root,
 
22
    ClickTestCase,
 
23
)
23
24
 
24
25
 
25
26
def add_user(name):
31
32
    subprocess.check_call(["userdel", "-r", name])
32
33
 
33
34
 
34
 
@unittest.skipIf(
35
 
    os.getuid() != 0, "This tests needs to run as root")
36
35
class TestClickInstall(ClickTestCase):
37
36
 
38
37
    @classmethod
39
38
    def setUpClass(cls):
40
39
        super(TestClickInstall, cls).setUpClass()
 
40
        require_root()
41
41
        cls.USER_1 = add_user("click-test-user-1")
42
42
        cls.USER_2 = add_user("click-test-user-2")
43
43
 
47
47
        del_user(cls.USER_1)
48
48
        del_user(cls.USER_2)
49
49
 
50
 
    def click_unregister(self, username, click_name):
51
 
        if username == "@all":
52
 
            user = "--all-users"
53
 
        else:
54
 
            user = "--user=%s" % username
55
 
        subprocess.check_call(
56
 
            [self.click_binary, "unregister", user, click_name])
57
 
 
58
50
    def test_install_for_single_user(self):
59
 
        click_pkg = self._make_click(name="foo-1", framework="")
 
51
        name = "foo-1"
 
52
        click_pkg = self._make_click(name=name, framework="")
60
53
        # install it
61
 
        subprocess.check_call([
62
 
            self.click_binary, "install", "--user=%s" % self.USER_1,
63
 
            "--allow-unauthenticated",
64
 
            click_pkg], universal_newlines=True)
65
 
        self.addCleanup(self.click_unregister, self.USER_1, "foo-1")
 
54
        self.click_install(click_pkg, name, self.USER_1)
66
55
        # ensure that user-1 has it
67
56
        output = subprocess.check_output([
68
57
            "sudo", "-u", self.USER_1,
69
58
            self.click_binary, "list"], universal_newlines=True)
70
 
        self.assertEqual(output, "foo-1\t1.0\n")
 
59
        self.assertEqual(output, "%s\t1.0\n" % name)
71
60
        # but not user-2
72
61
        output = subprocess.check_output([
73
62
            "sudo", "-u", self.USER_2,
77
66
        output = subprocess.check_output(
78
67
            [self.click_binary, "list", "--user=%s" % self.USER_1],
79
68
            universal_newlines=True)
80
 
        self.assertEqual(output, "foo-1\t1.0\n")
 
69
        self.assertEqual(output, "%s\t1.0\n" % name)
 
70
 
 
71
    def test_install_for_single_user_and_register(self):
 
72
        name = "foo-1"
 
73
        click_pkg = self._make_click(name=name, framework="")
 
74
        self.click_install(click_pkg, name, self.USER_1)
 
75
        # not available for user2
 
76
        output = subprocess.check_output([
 
77
            "sudo", "-u", self.USER_2,
 
78
            self.click_binary, "list"], universal_newlines=True)
 
79
        self.assertEqual(output, "")
 
80
        # register it
 
81
        subprocess.check_call(
 
82
            [self.click_binary, "register", "--user=%s" % self.USER_2,
 
83
             name, "1.0", ])
 
84
        self.addCleanup(self.click_unregister, name, self.USER_2)
 
85
        # and ensure its available for user2
 
86
        output = subprocess.check_output([
 
87
            "sudo", "-u", self.USER_2,
 
88
            self.click_binary, "list"], universal_newlines=True)
 
89
        self.assertEqual(output, "%s\t1.0\n" % name)
81
90
 
82
91
    def test_install_for_all_users(self):
83
 
        click_pkg = self._make_click(name="foo-2", framework="")
84
 
        # install it
85
 
        subprocess.check_call(
86
 
            [self.click_binary, "install", "--all-users",
87
 
            "--allow-unauthenticated", click_pkg],
88
 
            universal_newlines=True)
89
 
        self.addCleanup(self.click_unregister, "@all", "foo-2")
 
92
        name = "foo-2"
 
93
        click_pkg = self._make_click(name=name, framework="")
 
94
        self.click_install(click_pkg, name, "@all")
90
95
        # ensure all users see it
91
96
        for user in (self.USER_1, self.USER_2):
92
97
            output = subprocess.check_output(
93
98
                ["sudo", "-u", user, self.click_binary, "list"],
94
99
                universal_newlines=True)
95
 
            self.assertEqual(output, "foo-2\t1.0\n")
 
100
            self.assertEqual(output, "%s\t1.0\n" % name)
96
101
 
97
102
    def test_pkgdir_after_install(self):
98
 
        click_pkg = self._make_click(name="foo-2", version="1.2", framework="")
99
 
        subprocess.check_call(
100
 
            [self.click_binary, "install", "--all-users",
101
 
            "--allow-unauthenticated", click_pkg],
102
 
            universal_newlines=True)
103
 
        self.addCleanup(self.click_unregister, "@all", "foo-2")
 
103
        name = "foo-3"
 
104
        click_pkg = self._make_click(name=name, version="1.2", framework="")
 
105
        self.click_install(click_pkg, name, "@all")
104
106
        # from the path
105
107
        output = subprocess.check_output(
106
108
            [self.click_binary, "pkgdir",
107
 
             "/opt/click.ubuntu.com/foo-2/1.2/README"],
 
109
             "/opt/click.ubuntu.com/%s/1.2/README" % name],
108
110
            universal_newlines=True).strip()
109
 
        self.assertEqual(output, "/opt/click.ubuntu.com/foo-2/1.2")
 
111
        self.assertEqual(output, "/opt/click.ubuntu.com/%s/1.2" % name)
110
112
        # now test from the click package name
111
113
        output = subprocess.check_output(
112
 
            [self.click_binary, "pkgdir", "foo-2"],
 
114
            [self.click_binary, "pkgdir", name],
113
115
            universal_newlines=True).strip()
114
116
        # note that this is different from above
115
117
        self.assertEqual(
116
 
            output, "/opt/click.ubuntu.com/.click/users/@all/foo-2")
 
118
            output, "/opt/click.ubuntu.com/.click/users/@all/%s" % name)