Merge lp:~marcoceppi/charms/precise/wordpress/tests into lp:charms/wordpress

Proposed by Marco Ceppi
Status: Merged
Merged at revision: 78
Proposed branch: lp:~marcoceppi/charms/precise/wordpress/tests
Merge into: lp:charms/wordpress
Diff against target: 167 lines (+141/-0)
5 files modified
tests/00-setup (+5/-0)
tests/01-standard (+53/-0)
tests/02-memcached (+65/-0)
tests/helper.py (+17/-0)
tests/tests.yaml (+1/-0)
To merge this branch: bzr merge lp:~marcoceppi/charms/precise/wordpress/tests
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+240873@code.launchpad.net

Description of the change

Tests for the charm

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'tests'
2=== added file 'tests/00-setup'
3--- tests/00-setup 1970-01-01 00:00:00 +0000
4+++ tests/00-setup 2014-11-06 15:55:47 +0000
5@@ -0,0 +1,5 @@
6+#!/bin/bash
7+
8+sudo add-apt-repository -y ppa:juju/stable
9+sudo apt-get update
10+sudo apt-get install -y amulet python3-requests
11
12=== added file 'tests/01-standard'
13--- tests/01-standard 1970-01-01 00:00:00 +0000
14+++ tests/01-standard 2014-11-06 15:55:47 +0000
15@@ -0,0 +1,53 @@
16+#!/usr/bin/python3
17+
18+import os
19+import amulet
20+import requests
21+
22+import helper
23+
24+d = amulet.Deployment(series='precise')
25+d.add('mysql')
26+d.add('wordpress')
27+d.relate('mysql:db', 'wordpress:db')
28+d.expose('wordpress')
29+
30+try:
31+ # Create the deployment described above, give us 900 seconds to do it
32+ d.setup(timeout=900)
33+ # Setup will only make sure the services are deployed, related, and in a
34+ # "started" state. We can employ the sentries to actually make sure there
35+ # are no more hooks being executed on any of the nodes.
36+ d.sentry.wait()
37+except amulet.helpers.TimeoutError:
38+ amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
39+except:
40+ # Something else has gone wrong, raise the error so we can see it and this
41+ # will automatically "FAIL" the test.
42+ raise
43+
44+# Shorten the names a little to make working with unit data easier
45+wp_unit = d.sentry.unit['wordpress/0']
46+mysql_unit = d.sentry.unit['mysql/0']
47+
48+# WordPress requires user input to "finish" a setup. This code is contained in
49+# the helper.py file found in the lib directory. If it's not able to complete
50+# the WordPress setup we need to quit the test, not as failed per se, but as a
51+# SKIPed test since we can't accurately setup the environment
52+try:
53+ helper.finish_setup(wp_unit.info['public-address'], password='amulet-test')
54+except:
55+ amulet.raise_status(amulet.SKIP, msg="Unable to finish WordPress setup")
56+
57+home_page = requests.get('http://%s/' % wp_unit.info['public-address'], proxies=None)
58+home_page.raise_for_status() # Make sure it's not 5XX error
59+
60+# Fetch the wp-info.php file contents from the unit, then we can attempt to
61+# re-build it from the relation data and insure it's working as expected.
62+wp_cfg = wp_unit.file_contents('/var/www/wp-info.php')
63+
64+# Since relation data is unique per unit per service we don't want to grab
65+# what WordPress sent to MySQL. No, we want the data that MySQL sent to
66+# WordPress. Using this command we say, "get what MySQL sent via the 'db'
67+# relation to WordPress's 'db' relation.
68+relation_data = mysql_unit.relation('db', 'wordpress:db')
69
70=== added file 'tests/02-memcached'
71--- tests/02-memcached 1970-01-01 00:00:00 +0000
72+++ tests/02-memcached 2014-11-06 15:55:47 +0000
73@@ -0,0 +1,65 @@
74+#!/usr/bin/python3
75+
76+import os
77+import amulet
78+import requests
79+
80+import helper
81+
82+d = amulet.Deployment(series='precise')
83+d.add('mysql')
84+d.add('wordpress')
85+d.relate('mysql:db', 'wordpress:db')
86+d.expose('wordpress')
87+d.add('memcached')
88+
89+try:
90+ # Create the deployment described above, give us 900 seconds to do it
91+ d.setup(timeout=900)
92+ # Setup will only make sure the services are deployed, related, and in a
93+ # "started" state. We can employ the sentries to actually make sure there
94+ # are no more hooks being executed on any of the nodes.
95+ d.sentry.wait()
96+except amulet.helpers.TimeoutError:
97+ amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
98+except:
99+ # Something else has gone wrong, raise the error so we can see it and this
100+ # will automatically "FAIL" the test.
101+ raise
102+
103+# Shorten the names a little to make working with unit data easier
104+wp_unit = d.sentry.unit['wordpress/0']
105+mysql_unit = d.sentry.unit['mysql/0']
106+
107+# WordPress requires user input to "finish" a setup. This code is contained in
108+# the helper.py file found in the lib directory. If it's not able to complete
109+# the WordPress setup we need to quit the test, not as failed per se, but as a
110+# SKIPed test since we can't accurately setup the environment
111+try:
112+ helper.finish_setup(wp_unit.info['public-address'], password='amulet-test')
113+except:
114+ amulet.raise_status(amulet.SKIP, msg="Unable to finish WordPress setup")
115+
116+home_page = requests.get('http://%s/' % wp_unit.info['public-address'], proxies=None)
117+home_page.raise_for_status() # Make sure it's not 5XX error
118+
119+d.relate('wordpress:cache', 'memcached:cache')
120+
121+# Since we've changed the schema of our deployment, we need to run setup again
122+
123+try:
124+ # Default timeout should be enough time to get memcached up and related
125+ d.setup()
126+ d.sentry.wait()
127+except amulet.helpers.TimeoutError:
128+ amulet.raise_status(amulet.SKIP, msg="Memcached wasn't stood up in time.")
129+except:
130+ # Incase deployer throws an error
131+ raise
132+
133+# Verify WordPress still responds with a 200
134+home_page = requests.get('http://%s/' % wp_unit.info['public-address'], proxies=None)
135+home_page.raise_for_status()
136+
137+# Verify the WordPress plugin was installed correctly
138+wp_unit.directory('/var/www/wp-content/plugins/wp-ffpc')
139
140=== added file 'tests/__init__.py'
141=== added file 'tests/helper.py'
142--- tests/helper.py 1970-01-01 00:00:00 +0000
143+++ tests/helper.py 2014-11-06 15:55:47 +0000
144@@ -0,0 +1,17 @@
145+import requests
146+
147+
148+def finish_setup(unit, user='admin', password=None):
149+ h = {'User-Agent': 'Mozilla/5.0 Gecko/20100101 Firefox/12.0',
150+ 'Content-Type': 'application/x-www-form-urlencoded',
151+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*',
152+ 'Accept-Encoding': 'gzip, deflate'}
153+
154+ r = requests.post('http://%s/wp-admin/install.php?step=2' % unit,
155+ headers=h, data={'weblog_title': 'Amulet Test %s' % unit,
156+ 'user_name': user, 'admin_password': password,
157+ 'admin_email': 'test@example.tld',
158+ 'admin_password2': password,
159+ 'Submit': 'Install WordPress'}, proxies=None)
160+
161+ r.raise_for_status()
162
163=== added file 'tests/tests.yaml'
164--- tests/tests.yaml 1970-01-01 00:00:00 +0000
165+++ tests/tests.yaml 2014-11-06 15:55:47 +0000
166@@ -0,0 +1,1 @@
167+tests: "0*"

Subscribers

People subscribed via source and target branches

to all changes: