wordpress-charmers team mailing list archive
-
wordpress-charmers team
-
Mailing list archive
-
Message #00436
[Merge] ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:wordpress_plugin_integration into charm-k8s-wordpress:master
Thomas Cuthbert has proposed merging ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:wordpress_plugin_integration into charm-k8s-wordpress:master.
Requested reviews:
Wordpress Charmers (wordpress-charmers)
For more details, see:
https://code.launchpad.net/~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress/+merge/386800
--
Your team Wordpress Charmers is requested to review the proposed merge of ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:wordpress_plugin_integration into charm-k8s-wordpress:master.
diff --git a/Makefile b/Makefile
index cf18918..a4853e1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,24 @@
-lint:
+format:
@echo "Normalising python layout with black."
@tox -e black
+
+lint:
@echo "Running flake8"
@tox -e lint
+integration:
+ @echo "Running integration"
+ @export WORKSPACE=${WORKSPACE}
+ @tox -e integration
+
unittest:
@tox -e unit
-test: lint unittest
+test: lint unittest clean
clean:
@echo "Cleaning files"
- @git clean -fXd
+ @git clean -fXd || true
+ @rm -r /tmp/.tox
-.PHONY: lint test unittest clean
+.PHONY: format lint test unittest integration clean
diff --git a/tests/integration/requirements.txt b/tests/integration/requirements.txt
new file mode 100644
index 0000000..4666f84
--- /dev/null
+++ b/tests/integration/requirements.txt
@@ -0,0 +1,5 @@
+requests
+selenium
+pytest
+pytest-cov
+python2-secrets
diff --git a/tests/integration/test_wordpress_plugins.py b/tests/integration/test_wordpress_plugins.py
new file mode 100755
index 0000000..0ec8d91
--- /dev/null
+++ b/tests/integration/test_wordpress_plugins.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+import os
+import requests
+import unittest
+from selenium import webdriver
+from selenium.webdriver.common.action_chains import ActionChains
+from selenium.webdriver.common.by import By
+from selenium.webdriver.common.keys import Keys
+from selenium.webdriver.firefox.options import Options
+from selenium.webdriver import FirefoxProfile
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.webdriver.support.ui import WebDriverWait
+
+
+def read_secret(filen, mode="r"):
+ with open(os.path.join(os.environ["WORKSPACE"], filen), mode) as f:
+ return f.read()
+
+
+AUTH_TOKEN = str(read_secret("auth_token.txt")).rstrip()
+MAXIMUM_PAGE_LOAD_TIME = 15
+SSO_PASSWORD = str(read_secret("sso_password.txt")).rstrip()
+TEST_IMAGE = read_secret("test.png", mode="rb")
+
+
+class WordpressIntegrationTest(unittest.TestCase):
+ def _wordpress_sso_login(self):
+ self.driver.get("https://ci-blog.admin.canonical.com/wp-admin")
+ self.assertIn("Log In", self.driver.title)
+ elem = self.driver.find_element_by_id("lplogin")
+ elem.send_keys(Keys.RETURN)
+ WebDriverWait(self.driver, MAXIMUM_PAGE_LOAD_TIME).until(EC.presence_of_element_located((By.ID, "id_email")))
+ elem = self.driver.find_element_by_id("id_email")
+ elem.send_keys("webops+wordpress-ci@xxxxxxxxxxxxx")
+ elem = self.driver.find_element_by_id("id_password")
+ elem.send_keys(SSO_PASSWORD)
+ elem = self.driver.find_element_by_name("continue")
+ elem.send_keys(Keys.RETURN)
+ WebDriverWait(self.driver, MAXIMUM_PAGE_LOAD_TIME).until(EC.presence_of_element_located((By.NAME, "yes")))
+ elem = self.driver.find_element_by_id("id_wordpress-k8s-ci")
+ if not elem.is_selected():
+ ActionChains(self.driver).move_to_element(elem).click().perform()
+ elem = self.driver.find_element_by_name("yes")
+ elem.send_keys(Keys.RETURN)
+ WebDriverWait(self.driver, MAXIMUM_PAGE_LOAD_TIME).until(EC.title_contains(("Dashboard")))
+
+ def setUp(self):
+ profile = FirefoxProfile()
+ profile.accept_untrusted_certs = True
+ options = Options()
+ options.headless = True
+ self.driver = webdriver.Firefox(service_log_path="/dev/null", options=options, firefox_profile=profile)
+
+ def test_wordpress_signin(self):
+ self._wordpress_sso_login()
+ self.assertIn("Dashboard", self.driver.title)
+
+ def test_wordpress_akismit(self):
+ self._wordpress_sso_login()
+ self.driver.get("https://ci-blog.admin.canonical.com/wp-admin/options-general.php?page=akismet-key-config")
+ elem = self.driver.find_element_by_id("delete-action")
+ self.assertEqual("Disconnect this account", elem.text)
+
+ def test_swift_integration_content_rendering(self):
+ data = TEST_IMAGE
+ headers = {
+ "Authorization": "Basic {}".format(AUTH_TOKEN),
+ "content-disposition": "attachment; filename=test.png",
+ "content-type": "image/png",
+ }
+ resp = requests.post(
+ url="https://ci-blog.admin.canonical.com/wp-json/wp/v2/media/", data=data, headers=headers, verify=False
+ )
+
+ headers = {
+ "Authorization": "Basic {}".format(AUTH_TOKEN),
+ }
+ resp = requests.post(
+ url="https://ci-blog.admin.canonical.com/wp-json/wp/v2/posts",
+ data={"title": "Test Post", "content": resp.json()["description"]["rendered"], "status": "publish"},
+ headers=headers,
+ verify=False,
+ )
+ self.driver.get(resp.json()["guid"]["raw"])
+ elem = self.driver.find_element_by_xpath('//p[@class="attachment"]/a/img')
+ self.assertIn("test.png", elem.get_attribute("src"))
+
+ def tearDown(self):
+ self.driver.close()
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt
index 2d27572..c2bd57a 100644
--- a/tests/unit/requirements.txt
+++ b/tests/unit/requirements.txt
@@ -5,3 +5,4 @@ freezegun
mock
pytest
pytest-cov
+python2-secrets
diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
index 614c718..c72e1d5 100644
--- a/tests/unit/test_charm.py
+++ b/tests/unit/test_charm.py
@@ -75,7 +75,7 @@ class TestWordpressK8sCharm(unittest.TestCase):
_leader_get_func.side_effect = leadership_data._leader_get
create_wordpress_secrets()
- self.assertEqual(list(leadership_data.data.keys()), WORDPRESS_SECRETS)
+ self.assertEqual(sorted(list(leadership_data.data.keys())), sorted(WORDPRESS_SECRETS))
@mock.patch("charm._leader_set")
@mock.patch("charm._leader_get")
diff --git a/tox.ini b/tox.ini
index dbbb20f..b6528b2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,16 +1,20 @@
[tox]
skipsdist=True
-envlist = unit, functional
+envlist = unit, integration
skip_missing_interpreters = True
+toxworkdir=/tmp/.tox
[testenv]
basepython = python3
setenv =
PYTHONPATH = .
+passenv =
+ WORKSPACE
+
[testenv:unit]
commands =
- pytest --ignore mod --ignore {toxinidir}/tests/functional \
+ pytest --ignore mod --ignore {toxinidir}/tests/integration \
{posargs:-v --cov=src --cov-report=term-missing --cov-branch}
deps = -r{toxinidir}/tests/unit/requirements.txt
-r{toxinidir}/requirements.txt
@@ -18,14 +22,17 @@ setenv =
PYTHONPATH={toxinidir}/lib
TZ=UTC
-[testenv:functional]
+[testenv:integration]
passenv =
HOME
JUJU_REPOSITORY
PATH
+ WORKSPACE
+
commands =
- pytest -v --ignore mod --ignore {toxinidir}/tests/unit {posargs}
-deps = -r{toxinidir}/tests/functional/requirements.txt
+ pytest --ignore mod --ignore {toxinidir}/tests/unit \
+ {posargs:-v --cov=src --cov-report=term-missing --cov-branch}
+deps = -r{toxinidir}/tests/integration/requirements.txt
-r{toxinidir}/requirements.txt
[testenv:black]
References