Merge lp:~cjohnston/ubuntu-ci-services-itself/TS-integration-tests into lp:ubuntu-ci-services-itself

Proposed by Chris Johnston
Status: Merged
Approved by: Evan
Approved revision: 242
Merged at revision: 295
Proposed branch: lp:~cjohnston/ubuntu-ci-services-itself/TS-integration-tests
Merge into: lp:ubuntu-ci-services-itself
Diff against target: 103 lines (+98/-0)
1 file modified
tests/integration/test.py (+98/-0)
To merge this branch: bzr merge lp:~cjohnston/ubuntu-ci-services-itself/TS-integration-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Andy Doan (community) Approve
Chris Johnston (community) Needs Resubmitting
Evan (community) Approve
Review via email: mp+206160@code.launchpad.net

Commit message

Test that after the TS is deployed, we can create a ticket, then that the TS displays that ticket via API.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:238
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/193/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/193/rebuild

review: Approve (continuous-integration)
Revision history for this message
Evan (ev) wrote :

Hm, why wasn't this done on top of Amulet like the other integration tests? We won't know if something is broken in the link between the ticket system, gunicorn, and the Apache frontend. I ran into just such an issue before we put Apache in front of gunicorn where gunicorn's braindead URL parsing broke "http://ticket_system//api/v1/..."

review: Needs Information
Revision history for this message
Evan (ev) wrote :

D'oh. I need more coffee. I now see that you're just using virtualenv for the CLI.

Revision history for this message
Vincent Ladeuil (vila) wrote :

61 +
62 + def tearDown(self):
63 + delete_virtual_env(self.temp_dir)

This miss the upcall to tearDown but you completely avoid tearDown itself by doing:

   self.addCleanup(delete_virtual_env, self.temp_dir)

in setUp()

Since we already have a venv set to run the unit tests (and plan to also use it to run the other integration tests), I would rather make it a requirement that these tests should run under the venv than creating a new one each time. This is a costly operation which also have known failures which in this case will fail the test for the wrong reason.

65 + def get_server_status_and_content(self, url, service='ts-django'):

86 + resp, content = self.get_server_status_and_content(url)

98 + resp, content = self.get_server_status_and_content(
99 + url, service='webui-apache')

It would be more consistent to have no default value in get_server_status_and_content (unless there is a good reason for that which in this case is worth documenting).

88 + self.assertEqual(resp['status'], '200')
89 + self.assertEqual(content['title'], 'New feature')
90 + self.assertEqual(content['current_workflow_step'], 'Queued')

All other integration tests use expected, actual, let's not add more inconsistency, thanks ;)

101 + self.assertEqual(resp['status'], '200')
102 + self.assertIn('<a href="/" class="first ">Ticket List</a>', content)

especially with assertIn also using expected, actual

Revision history for this message
Andy Doan (doanac) wrote :

25 +def delete_virtual_env(temp_dir):
26 + remove = ('rm -rf %s' % temp_dir)
27 + subprocess.check_call([remove], shell=True)

Is there a reason shutil.rmtree isn't being used here instead?

//massive bikeshedding, but a style suggestion for the future:
55 + args = ('%s develop' % os.path.join(
56 + os.path.dirname(__file__), '../../ci-utils/setup.py'))

could be:

    p = os.path.join(os.path.dirname(__file__), '../../ci-utils/setup.py'))
    args = '%s develop' % p

and then you don't get weird multi-line parentheses to match with your eyes.

92 + def test_ticket_in_webui_ticket_list(self):

This method only works when "test_create_ticket_via_cli" is called first. Its probably smarter if you move the ticket creation logic from "test_create_ticket_via_cli" into your setUp method and then just let your 2 test methods assert that both the ticket-system and webui are displaying what we expect.

Revision history for this message
Evan (ev) wrote :

Other than the issues already raised, this looks good. +1

review: Approve
Revision history for this message
Chris Johnston (cjohnston) wrote :

On Thu, Feb 20, 2014 at 11:31 AM, Andy Doan <email address hidden>wrote:

> 25 +def delete_virtual_env(temp_dir):
> 26 + remove = ('rm -rf %s' % temp_dir)
> 27 + subprocess.check_call([remove], shell=True)
>
> Is there a reason shutil.rmtree isn't being used here instead?
>

r241

> //massive bikeshedding, but a style suggestion for the future:
> 55 + args = ('%s develop' % os.path.join(
> 56 + os.path.dirname(__file__), '../../ci-utils/setup.py'))
>
> could be:
>
> p = os.path.join(os.path.dirname(__file__), '../../ci-utils/setup.py'))
> args = '%s develop' % p
>
> and then you don't get weird multi-line parentheses to match with your
> eyes.
>

r239

>
> 92 + def test_ticket_in_webui_ticket_list(self):
>
> This method only works when "test_create_ticket_via_cli" is called first.
> Its probably smarter if you move the ticket creation logic from
> "test_create_ticket_via_cli" into your setUp method and then just let your
> 2 test methods assert that both the ticket-system and webui are displaying
> what we expect.
>

r240

239. By Chris Johnston

Fix formatting for args strings

240. By Chris Johnston

Move create ticket into setUp

241. By Chris Johnston

use shutil

Revision history for this message
Chris Johnston (cjohnston) :
review: Needs Resubmitting
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:241
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/200/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/200/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Andy Doan (doanac) wrote :

solves my complaints

review: Approve
242. By Chris Johnston

Switch to using self.addCleanup

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:242
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/259/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/259/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'tests/integration'
2=== added file 'tests/integration/test.py'
3--- tests/integration/test.py 1970-01-01 00:00:00 +0000
4+++ tests/integration/test.py 2014-02-28 20:55:47 +0000
5@@ -0,0 +1,98 @@
6+#!/usr/bin/env python
7+
8+import os
9+import json
10+import tempfile
11+import subprocess
12+import unittest
13+import shutil
14+
15+import httplib2
16+
17+from tests.deployers import DEPLOYER_DIR, DeployerTest
18+
19+
20+def create_virtual_env():
21+ temp_dir = tempfile.mkdtemp()
22+ subprocess.check_call(['virtualenv', temp_dir])
23+ return temp_dir
24+
25+
26+def delete_virtual_env(temp_dir):
27+ shutil.rmtree(temp_dir)
28+
29+
30+def run_virtual_env(temp_dir, args, cwd=None):
31+ if args is 'create':
32+ cwd = os.path.join(os.path.dirname(__file__), '../../cli')
33+ changes = os.path.abspath(os.path.join(
34+ os.path.dirname(__file__),
35+ '../../cli/tests/data/foobar_0.1-1_source.changes'))
36+ args = ('python ubuntu-ci create_ticket -t "New feature" -b 1234 -o '
37+ 'someone@example.com -d "This is a cool new feature" -r baz '
38+ '-s %s' % changes)
39+ args = '. %s ; %s' % (os.path.join(temp_dir, 'bin/activate'),
40+ args)
41+ if cwd:
42+ subprocess.check_call([args], cwd=cwd, shell=True)
43+ else:
44+ subprocess.check_call(args, shell=True)
45+
46+
47+class IntegrationTest(DeployerTest):
48+ """Integration tests for ticket-system service run on a juju deployment"""
49+
50+ deployer_cfg = os.path.join(DEPLOYER_DIR, 'ticket-system.yaml')
51+
52+ def setUp(self):
53+ super(IntegrationTest, self).setUp()
54+ self.temp_dir = create_virtual_env()
55+ p = os.path.join(os.path.dirname(__file__), '../../ci-utils/setup.py')
56+ args = '%s develop' % p
57+ run_virtual_env(self.temp_dir, args)
58+ p = os.path.join(os.path.dirname(__file__), '../../cli/setup.py')
59+ args = '%s develop' % p
60+ run_virtual_env(self.temp_dir, args)
61+ config_url = 'http://{}:{}'
62+ config_url = config_url.format(*self.get_ip_and_port('ts-django'))
63+ config = os.path.join(os.environ["HOME"], '.ubuntu-ci')
64+ with open(config, 'a') as fp:
65+ fp.write('ci_url: "{}"\n'.format(config_url))
66+
67+ run_virtual_env(self.temp_dir, args='create')
68+ self.addCleanup(delete_virtual_env, self.temp_dir)
69+
70+ def get_server_status_and_content(self, url, service='ts-django'):
71+ final_url = url.format(*self.get_ip_and_port(service))
72+
73+ client = httplib2.Http()
74+ resp, content = client.request(final_url, 'GET')
75+ return resp, content
76+
77+ def test_create_ticket_via_cli(self):
78+ """
79+ This tests that the CLI can create a ticket and that the ticket shows
80+ up with the proper status when viewed via the API.
81+ """
82+
83+ url = 'http://{}:{}/api/v1/ticket/1/'
84+ resp, content = self.get_server_status_and_content(url)
85+ content = json.loads(content)
86+ self.assertEqual(resp['status'], '200')
87+ self.assertEqual(content['title'], 'New feature')
88+ self.assertEqual(content['current_workflow_step'], 'Queued')
89+
90+ def test_ticket_in_webui_ticket_list(self):
91+ """
92+ This tests that the WebUI main page shows the ticket that we created
93+ via the CLI
94+ """
95+ url = 'http://{}:{}/'
96+ resp, content = self.get_server_status_and_content(
97+ url, service='webui-apache')
98+
99+ self.assertEqual(resp['status'], '200')
100+ self.assertIn('<a href="/" class="first ">Ticket List</a>', content)
101+
102+if __name__ == "__main__":
103+ unittest.main()

Subscribers

People subscribed via source and target branches