~mvo/click/frameworks.json

« back to all changes in this revision

Viewing changes to tests/integration/test_integration.py

  • Committer: Colin Watson
  • Date: 2014-06-16 12:53:31 UTC
  • mfrom: (466.1.4 more-tests2)
  • Revision ID: cjwatson@canonical.com-20140616125331-7gqsci02gdjqn8vm
Refactor the integration tests to be more modular.  Add installation
integration tests based on
https://wiki.ubuntu.com/Process/Merges/TestPlan/click.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""Integration tests for the click CLI interface."""
17
17
 
18
 
import contextlib
19
 
import glob
20
18
import json
21
19
import os
22
 
import random
23
20
import re
24
 
import shutil
25
 
import string
26
21
import subprocess
27
 
import tempfile
28
 
import unittest
29
 
 
30
 
 
31
 
@contextlib.contextmanager
32
 
def chdir(target):
33
 
    curdir = os.getcwd()
34
 
    os.chdir(target)
35
 
    yield
36
 
    os.chdir(curdir)
37
 
 
38
 
 
39
 
class TestCase(unittest.TestCase):
40
 
 
41
 
    @classmethod
42
 
    def setUpClass(cls):
43
 
        cls.click_binary = "/usr/bin/click"
44
 
 
45
 
    def _make_click(self, name=None, version=1.0):
46
 
        if name is None:
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)
52
 
        os.makedirs(clickdir)
53
 
        with open(os.path.join(clickdir, "manifest.json"), "w") as f:
54
 
            f.write("""{
55
 
            "name": "%s",
56
 
            "version": "%s",
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]
 
22
 
 
23
 
 
24
from .helpers import TestCase
68
25
 
69
26
 
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))
104
 
 
105
 
 
106
 
@unittest.skipIf(
107
 
    os.getuid() != 0, "This tests needs to run as root")
108
 
@unittest.skipIf(
109
 
    subprocess.call(
110
 
        ["ping", "-c1", "archive.ubuntu.com"]) != 0, "Need network")
111
 
class TestChroot(TestCase):
112
 
 
113
 
    @classmethod
114
 
    def setUpClass(cls):
115
 
        super(TestChroot, cls).setUpClass()
116
 
        cls.arch = subprocess.check_output(
117
 
            ["dpkg", "--print-architecture"], universal_newlines=True).strip()
118
 
        subprocess.check_call([
119
 
            cls.click_binary,
120
 
            "chroot", "-a", cls.arch,
121
 
            "create"])
122
 
 
123
 
    @classmethod
124
 
    def tearDownClass(cls):
125
 
        subprocess.check_call([
126
 
            cls.click_binary,
127
 
            "chroot", "-a", cls.arch,
128
 
            "destroy"])
129
 
 
130
 
    def test_upgrade(self):
131
 
        subprocess.check_call([
132
 
            self.click_binary, "chroot", "-a", self.arch,
133
 
            "upgrade"])
134
 
 
135
 
    def test_install(self):
136
 
        subprocess.check_call([
137
 
            self.click_binary, "chroot", "-a", self.arch,
138
 
            "install", "apt-utils"])
139
 
 
140
 
    def test_run(self):
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")
145
 
 
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")