16
16
"""Integration tests for the click CLI interface."""
31
@contextlib.contextmanager
39
class TestCase(unittest.TestCase):
43
cls.click_binary = "/usr/bin/click"
45
def _make_click(self, name=None, version=1.0):
47
name = "com.ubuntu.%s" % "".join(
48
random.choice(string.ascii_lowercase) for i in range(10))
49
tmpdir = tempfile.mkdtemp()
50
self.addCleanup(lambda: shutil.rmtree(tmpdir))
51
clickdir = os.path.join(tmpdir, name)
53
with open(os.path.join(clickdir, "manifest.json"), "w") as f:
57
"maintainer": "Foo Bar <foo@example.org>",
58
"title": "test title",
59
"framework": "ubuntu-sdk-13.10"
60
}""" % (name, version))
61
with open(os.path.join(clickdir, "README"), "w") as f:
62
f.write("hello world!")
63
with chdir(tmpdir), open(os.devnull, "w") as devnull:
64
subprocess.call(["click", "build", clickdir], stdout=devnull)
65
generated_clicks = glob.glob(os.path.join(tmpdir, "*.click"))
66
self.assertEqual(len(generated_clicks), 1)
67
return generated_clicks[0]
24
from .helpers import TestCase
70
27
class TestBuild(TestCase):
101
58
universal_newlines=True)
102
59
self.assertTrue(re.search(
103
60
r'-rw-r[-w]-r-- root/root\s+[0-9]+\s+[0-9-]+ [0-9:]+ ./README', output))
107
os.getuid() != 0, "This tests needs to run as root")
110
["ping", "-c1", "archive.ubuntu.com"]) != 0, "Need network")
111
class TestChroot(TestCase):
115
super(TestChroot, cls).setUpClass()
116
cls.arch = subprocess.check_output(
117
["dpkg", "--print-architecture"], universal_newlines=True).strip()
118
subprocess.check_call([
120
"chroot", "-a", cls.arch,
124
def tearDownClass(cls):
125
subprocess.check_call([
127
"chroot", "-a", cls.arch,
130
def test_upgrade(self):
131
subprocess.check_call([
132
self.click_binary, "chroot", "-a", self.arch,
135
def test_install(self):
136
subprocess.check_call([
137
self.click_binary, "chroot", "-a", self.arch,
138
"install", "apt-utils"])
141
output = subprocess.check_output([
142
self.click_binary, "chroot", "-a", self.arch,
143
"run", "echo", "hello world"], universal_newlines=True)
144
self.assertEqual(output, "hello world\n")
146
def test_maint(self):
147
output = subprocess.check_output([
148
self.click_binary, "chroot", "-a", self.arch,
149
"maint", "id"], universal_newlines=True)
150
self.assertEqual(output, "uid=0(root) gid=0(root) groups=0(root)\n")