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
=== added directory 'tests'
=== added file 'tests/00-setup'
--- tests/00-setup 1970-01-01 00:00:00 +0000
+++ tests/00-setup 2014-11-06 15:55:47 +0000
@@ -0,0 +1,5 @@
1#!/bin/bash
2
3sudo add-apt-repository -y ppa:juju/stable
4sudo apt-get update
5sudo apt-get install -y amulet python3-requests
06
=== added file 'tests/01-standard'
--- tests/01-standard 1970-01-01 00:00:00 +0000
+++ tests/01-standard 2014-11-06 15:55:47 +0000
@@ -0,0 +1,53 @@
1#!/usr/bin/python3
2
3import os
4import amulet
5import requests
6
7import helper
8
9d = amulet.Deployment(series='precise')
10d.add('mysql')
11d.add('wordpress')
12d.relate('mysql:db', 'wordpress:db')
13d.expose('wordpress')
14
15try:
16 # Create the deployment described above, give us 900 seconds to do it
17 d.setup(timeout=900)
18 # Setup will only make sure the services are deployed, related, and in a
19 # "started" state. We can employ the sentries to actually make sure there
20 # are no more hooks being executed on any of the nodes.
21 d.sentry.wait()
22except amulet.helpers.TimeoutError:
23 amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
24except:
25 # Something else has gone wrong, raise the error so we can see it and this
26 # will automatically "FAIL" the test.
27 raise
28
29# Shorten the names a little to make working with unit data easier
30wp_unit = d.sentry.unit['wordpress/0']
31mysql_unit = d.sentry.unit['mysql/0']
32
33# WordPress requires user input to "finish" a setup. This code is contained in
34# the helper.py file found in the lib directory. If it's not able to complete
35# the WordPress setup we need to quit the test, not as failed per se, but as a
36# SKIPed test since we can't accurately setup the environment
37try:
38 helper.finish_setup(wp_unit.info['public-address'], password='amulet-test')
39except:
40 amulet.raise_status(amulet.SKIP, msg="Unable to finish WordPress setup")
41
42home_page = requests.get('http://%s/' % wp_unit.info['public-address'], proxies=None)
43home_page.raise_for_status() # Make sure it's not 5XX error
44
45# Fetch the wp-info.php file contents from the unit, then we can attempt to
46# re-build it from the relation data and insure it's working as expected.
47wp_cfg = wp_unit.file_contents('/var/www/wp-info.php')
48
49# Since relation data is unique per unit per service we don't want to grab
50# what WordPress sent to MySQL. No, we want the data that MySQL sent to
51# WordPress. Using this command we say, "get what MySQL sent via the 'db'
52# relation to WordPress's 'db' relation.
53relation_data = mysql_unit.relation('db', 'wordpress:db')
054
=== added file 'tests/02-memcached'
--- tests/02-memcached 1970-01-01 00:00:00 +0000
+++ tests/02-memcached 2014-11-06 15:55:47 +0000
@@ -0,0 +1,65 @@
1#!/usr/bin/python3
2
3import os
4import amulet
5import requests
6
7import helper
8
9d = amulet.Deployment(series='precise')
10d.add('mysql')
11d.add('wordpress')
12d.relate('mysql:db', 'wordpress:db')
13d.expose('wordpress')
14d.add('memcached')
15
16try:
17 # Create the deployment described above, give us 900 seconds to do it
18 d.setup(timeout=900)
19 # Setup will only make sure the services are deployed, related, and in a
20 # "started" state. We can employ the sentries to actually make sure there
21 # are no more hooks being executed on any of the nodes.
22 d.sentry.wait()
23except amulet.helpers.TimeoutError:
24 amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
25except:
26 # Something else has gone wrong, raise the error so we can see it and this
27 # will automatically "FAIL" the test.
28 raise
29
30# Shorten the names a little to make working with unit data easier
31wp_unit = d.sentry.unit['wordpress/0']
32mysql_unit = d.sentry.unit['mysql/0']
33
34# WordPress requires user input to "finish" a setup. This code is contained in
35# the helper.py file found in the lib directory. If it's not able to complete
36# the WordPress setup we need to quit the test, not as failed per se, but as a
37# SKIPed test since we can't accurately setup the environment
38try:
39 helper.finish_setup(wp_unit.info['public-address'], password='amulet-test')
40except:
41 amulet.raise_status(amulet.SKIP, msg="Unable to finish WordPress setup")
42
43home_page = requests.get('http://%s/' % wp_unit.info['public-address'], proxies=None)
44home_page.raise_for_status() # Make sure it's not 5XX error
45
46d.relate('wordpress:cache', 'memcached:cache')
47
48# Since we've changed the schema of our deployment, we need to run setup again
49
50try:
51 # Default timeout should be enough time to get memcached up and related
52 d.setup()
53 d.sentry.wait()
54except amulet.helpers.TimeoutError:
55 amulet.raise_status(amulet.SKIP, msg="Memcached wasn't stood up in time.")
56except:
57 # Incase deployer throws an error
58 raise
59
60# Verify WordPress still responds with a 200
61home_page = requests.get('http://%s/' % wp_unit.info['public-address'], proxies=None)
62home_page.raise_for_status()
63
64# Verify the WordPress plugin was installed correctly
65wp_unit.directory('/var/www/wp-content/plugins/wp-ffpc')
066
=== added file 'tests/__init__.py'
=== added file 'tests/helper.py'
--- tests/helper.py 1970-01-01 00:00:00 +0000
+++ tests/helper.py 2014-11-06 15:55:47 +0000
@@ -0,0 +1,17 @@
1import requests
2
3
4def finish_setup(unit, user='admin', password=None):
5 h = {'User-Agent': 'Mozilla/5.0 Gecko/20100101 Firefox/12.0',
6 'Content-Type': 'application/x-www-form-urlencoded',
7 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*',
8 'Accept-Encoding': 'gzip, deflate'}
9
10 r = requests.post('http://%s/wp-admin/install.php?step=2' % unit,
11 headers=h, data={'weblog_title': 'Amulet Test %s' % unit,
12 'user_name': user, 'admin_password': password,
13 'admin_email': 'test@example.tld',
14 'admin_password2': password,
15 'Submit': 'Install WordPress'}, proxies=None)
16
17 r.raise_for_status()
018
=== added file 'tests/tests.yaml'
--- tests/tests.yaml 1970-01-01 00:00:00 +0000
+++ tests/tests.yaml 2014-11-06 15:55:47 +0000
@@ -0,0 +1,1 @@
1tests: "0*"

Subscribers

People subscribed via source and target branches

to all changes: