Merge ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:integration into charm-k8s-wordpress:master

Proposed by Thomas Cuthbert
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:integration
Merge into: charm-k8s-wordpress:master
Diff against target: 117 lines (+100/-0)
2 files modified
tests/integration/test_wordpress_plugins.py (+88/-0)
tox.ini (+12/-0)
Reviewer Review Type Date Requested Status
Wordpress Charmers Pending
Review via email: mp+386476@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tom Haddon (mthaddon) wrote :

Looks good, one small typo inline (akismit vs. akismet). I think we'll just need to document how you run these tests (against an already deployed environment and with some files in a folder that's exported as WORKSPACE env dir?).

Unmerged commits

146e992... by Thomas Cuthbert

Initial integration tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/integration/test_wordpress_plugins.py b/tests/integration/test_wordpress_plugins.py
2new file mode 100755
3index 0000000..0fd88d0
4--- /dev/null
5+++ b/tests/integration/test_wordpress_plugins.py
6@@ -0,0 +1,88 @@
7+#!/usr/bin/env python3
8+import os
9+import requests
10+import sys
11+import unittest
12+from selenium import webdriver
13+from selenium.webdriver.common.action_chains import ActionChains
14+from selenium.webdriver.common.by import By
15+from selenium.webdriver.common.keys import Keys
16+from selenium.webdriver.firefox.options import Options
17+from selenium.webdriver.support import expected_conditions as EC
18+from selenium.webdriver.support.ui import WebDriverWait
19+
20+
21+def read_secret(filen, mode="r"):
22+ with open(os.path.join(os.environ["WORKSPACE"], filen), mode) as f:
23+ return f.read()
24+
25+
26+AUTH_TOKEN = str(read_secret("auth_token.txt")).rstrip()
27+MAXIMUM_PAGE_LOAD_TIME = 15
28+SSO_PASSWORD = str(read_secret("sso_password.txt")).rstrip()
29+TEST_IMAGE = read_secret("test.png", mode="rb")
30+
31+
32+class WordpressIntegrationTest(unittest.TestCase):
33+ def _wordpress_sso_login(self):
34+ self.driver.get("https://test-blog.launchpad.net/wp-admin")
35+ self.assertIn("Log In", self.driver.title)
36+ elem = self.driver.find_element_by_id("lplogin")
37+ elem.send_keys(Keys.RETURN)
38+ WebDriverWait(self.driver, MAXIMUM_PAGE_LOAD_TIME).until(EC.presence_of_element_located((By.ID, "id_email")))
39+ elem = self.driver.find_element_by_id("id_email")
40+ elem.send_keys("webops+wordpress-ci@canonical.com")
41+ elem = self.driver.find_element_by_id("id_password")
42+ elem.send_keys(SSO_PASSWORD)
43+ elem = self.driver.find_element_by_name("continue")
44+ elem.send_keys(Keys.RETURN)
45+ WebDriverWait(self.driver, MAXIMUM_PAGE_LOAD_TIME).until(EC.presence_of_element_located((By.NAME, "yes")))
46+ elem = self.driver.find_element_by_id("id_wordpress-k8s-ci")
47+ if not elem.is_selected():
48+ ActionChains(self.driver).move_to_element(elem).click().perform()
49+ elem = self.driver.find_element_by_name("yes")
50+ elem.send_keys(Keys.RETURN)
51+ WebDriverWait(self.driver, MAXIMUM_PAGE_LOAD_TIME).until(EC.title_contains(("Dashboard")))
52+
53+ def setUp(self):
54+ options = Options()
55+ options.headless = True
56+ self.driver = webdriver.Firefox(service_log_path="/dev/null", options=options)
57+
58+ def test_wordpress_signin(self):
59+ self._wordpress_sso_login()
60+ self.assertIn("Dashboard", self.driver.title)
61+
62+ def test_wordpress_akismit(self):
63+ self._wordpress_sso_login()
64+ self.driver.get("https://test-blog.launchpad.net/wp-admin/options-general.php?page=akismet-key-config")
65+ elem = self.driver.find_element_by_id("delete-action")
66+ self.assertEqual("Disconnect this account", elem.text)
67+
68+ def test_swift_integration_content_rendering(self):
69+ data = TEST_IMAGE
70+ headers = {
71+ "Authorization": "Basic {}".format(AUTH_TOKEN),
72+ "content-disposition": "attachment; filename=test.png",
73+ "content-type": "image/png",
74+ }
75+ resp = requests.post(url="https://test-blog.launchpad.net/wp-json/wp/v2/media/", data=data, headers=headers)
76+
77+ headers = {
78+ "Authorization": "Basic {}".format(AUTH_TOKEN),
79+ }
80+ resp = requests.post(
81+ url="https://test-blog.launchpad.net/wp-json/wp/v2/posts",
82+ data={"title": "Test Post", "content": resp.json()["description"]["rendered"], "status": "publish"},
83+ headers=headers,
84+ )
85+ self.driver.get(resp.json()["guid"]["raw"])
86+ elem = self.driver.find_element_by_xpath('//p[@class="attachment"]/a/img')
87+ self.assertIn("test.png", elem.get_attribute("src"))
88+
89+ def tearDown(self):
90+ self.driver.close()
91+
92+
93+if __name__ == "__main__":
94+ unittest.main()
95diff --git a/tox.ini b/tox.ini
96index dbbb20f..6d9ed81 100644
97--- a/tox.ini
98+++ b/tox.ini
99@@ -28,6 +28,18 @@ commands =
100 deps = -r{toxinidir}/tests/functional/requirements.txt
101 -r{toxinidir}/requirements.txt
102
103+[testenv:integration]
104+passenv =
105+ WORKSPACE
106+
107+commands =
108+ pytest --ignore mod {toxinidir}/tests/integration
109+
110+deps =
111+ pytest
112+ selenium
113+ requests
114+
115 [testenv:black]
116 commands = black --skip-string-normalization --line-length=120 src/ tests/
117 deps = black

Subscribers

People subscribed via source and target branches