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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#!/usr/bin/env python
import os
import json
import tempfile
import subprocess
import unittest
import shutil
import httplib2
from tests.deployers import DEPLOYER_DIR, DeployerTest
def create_virtual_env():
temp_dir = tempfile.mkdtemp()
subprocess.check_call(['virtualenv', temp_dir])
return temp_dir
def delete_virtual_env(temp_dir):
shutil.rmtree(temp_dir)
def run_virtual_env(temp_dir, args, cwd=None):
if args is 'create':
cwd = os.path.join(os.path.dirname(__file__), '../../cli')
changes = os.path.abspath(os.path.join(
os.path.dirname(__file__),
'../../cli/tests/data/foobar_0.1-1_source.changes'))
args = ('python ubuntu-ci create_ticket -t "New feature" -b 1234 -o '
'someone@example.com -d "This is a cool new feature" -a foo '
'-s %s' % changes)
args = '. %s ; %s' % (os.path.join(temp_dir, 'bin/activate'),
args)
if cwd:
subprocess.check_call([args], cwd=cwd, shell=True)
else:
subprocess.check_call(args, shell=True)
class IntegrationTest(DeployerTest):
"""Integration tests for ticket-system service run on a juju deployment"""
deployer_cfg = os.path.join(DEPLOYER_DIR, 'ticket-system.yaml')
def setUp(self):
super(IntegrationTest, self).setUp()
self.temp_dir = create_virtual_env()
p = os.path.join(os.path.dirname(__file__), '../../ci-utils/setup.py')
args = '%s develop' % p
run_virtual_env(self.temp_dir, args)
p = os.path.join(os.path.dirname(__file__), '../../cli/setup.py')
args = '%s develop' % p
run_virtual_env(self.temp_dir, args)
config_url = 'http://{}:{}'
config_url = config_url.format(*self.get_ip_and_port('ts-django'))
config = os.path.join(os.environ["HOME"], '.ubuntu-ci')
with open(config, 'a') as fp:
fp.write('ci_url: "{}"\n'.format(config_url))
run_virtual_env(self.temp_dir, args='create')
self.addCleanup(delete_virtual_env, self.temp_dir)
def get_server_status_and_content(self, url, service='ts-django'):
final_url = url.format(*self.get_ip_and_port(service))
client = httplib2.Http()
resp, content = client.request(final_url, 'GET')
return resp, content
def test_create_ticket_via_cli(self):
"""
This tests that the CLI can create a ticket and that the ticket shows
up with the proper status when viewed via the API.
"""
url = 'http://{}:{}/api/v1/ticket/1/'
resp, content = self.get_server_status_and_content(url)
content = json.loads(content)
self.assertEqual(resp['status'], '200')
self.assertEqual(content['title'], 'New feature')
self.assertEqual(content['current_workflow_step'], 'Queued')
def test_ticket_in_webui_ticket_list(self):
"""
This tests that the WebUI main page shows the ticket that we created
via the CLI
"""
url = 'http://{}:{}/'
resp, content = self.get_server_status_and_content(
url, service='webui-apache')
self.assertEqual(resp['status'], '200')
self.assertIn('<a href="/" class="first ">Ticket List</a>', content)
if __name__ == "__main__":
unittest.main()
|