16
16
"""Integration tests for the click CLI interface."""
33
@contextlib.contextmanager
41
class TestCase(unittest.TestCase):
45
cls.click_binary = os.path.abspath(
46
os.path.join(sys.argv[0], "..", "bin", "click"))
49
self.saved_env = copy.copy(os.environ)
50
os.environ["PYTHONPATH"] = os.path.abspath(
51
os.path.join(sys.argv[0], ".."))
54
os.environ = self.saved_env
56
def _make_click(self, name=None, version=1.0):
58
name = "com.ubuntu.%s" % "".join(
59
random.choice(string.ascii_lowercase) for i in range(10))
60
tmpdir = tempfile.mkdtemp()
61
self.addCleanup(lambda: shutil.rmtree(tmpdir))
62
clickdir = os.path.join(tmpdir, name)
64
with open(os.path.join(clickdir, "manifest.json"), "w") as f:
68
"maintainer": "Foo Bar <foo@example.org>",
69
"title": "test title",
70
"framework": "ubuntu-sdk-13.10"
71
}""" % (name, version))
72
with open(os.path.join(clickdir, "README"), "w") as f:
73
f.write("hello world!")
74
with chdir(tmpdir), open(os.devnull, "w") as devnull:
75
subprocess.call(["click", "build", clickdir], stdout=devnull)
76
generated_clicks = glob.glob(os.path.join(tmpdir, "*.click"))
77
self.assertEqual(len(generated_clicks), 1)
78
return generated_clicks[0]
27
from .helpers import (
81
33
class TestBuild(TestCase):
113
65
self.assertTrue(re.search(
114
66
r'-rw-r[-w]-r-- root/root\s+[0-9]+\s+[0-9-]+ [0-9:]+ ./README', output))
118
os.getuid() != 0, "This tests needs to run as root")
121
["ping", "-c1", "archive.ubuntu.com"]) != 0, "Need network")
122
class TestChroot(TestCase):
126
super(TestChroot, cls).setUpClass()
127
cls.arch = subprocess.check_output(
128
["dpkg", "--print-architecture"], universal_newlines=True).strip()
129
subprocess.check_call([
131
"chroot", "-a", cls.arch,
135
def tearDownClass(cls):
136
subprocess.check_call([
138
"chroot", "-a", cls.arch,
141
def test_upgrade(self):
142
subprocess.check_call([
143
self.click_binary, "chroot", "-a", self.arch,
146
def test_install(self):
147
subprocess.check_call([
148
self.click_binary, "chroot", "-a", self.arch,
149
"install", "apt-utils"])
152
output = subprocess.check_output([
153
self.click_binary, "chroot", "-a", self.arch,
154
"run", "echo", "hello world"], universal_newlines=True)
155
self.assertEqual(output, "hello world\n")
157
def test_maint(self):
158
output = subprocess.check_output([
159
self.click_binary, "chroot", "-a", self.arch,
160
"maint", "id"], universal_newlines=True)
161
self.assertEqual(output, "uid=0(root) gid=0(root) groups=0(root)\n")
69
(not os.path.exists("/usr/share/click/frameworks") or
70
not os.listdir("/usr/share/click/frameworks")),
71
"Please install ubuntu-sdk-libs")
72
class TestFrameworks(TestCase):
73
def test_framework_list(self):
74
output = subprocess.check_output([
75
self.click_binary, "framework", "list"], universal_newlines=True)
76
self.assertTrue("ubuntu-sdk-" in output)
79
class TestBuildSource(TestCase):
80
def test_buildsource(self):
81
temp_dir = tempfile.mkdtemp()
82
self.addCleanup(shutil.rmtree, temp_dir)
84
with open(os.path.join(temp_dir, "README"), "w") as f:
85
f.write("I'm a source package")
86
os.mkdir(os.path.join(temp_dir, ".git"))
87
os.mkdir(os.path.join(temp_dir, ".bzr"))
88
os.mkdir(os.path.join(temp_dir, ".normal"))
89
self._create_manifest(os.path.join(temp_dir, "manifest.json"),
90
"srcfoo", "1.2", "ubuntu-sdk-13.10")
91
subprocess.check_call(
92
[self.click_binary, "buildsource", temp_dir],
93
universal_newlines=True)
94
# ensure we have the content we expect
95
source_file = "srcfoo_1.2.tar.gz"
96
tar = tarfile.open(source_file)
98
sorted(tar.getnames()),
99
sorted([".", "./.normal", "./manifest.json", "./README"]))