wordpress-charmers team mailing list archive
-
wordpress-charmers team
-
Mailing list archive
-
Message #00131
[Merge] ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:operator into charm-k8s-wordpress:master
Thomas Cuthbert has proposed merging ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:operator 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/381908
--
Your team Wordpress Charmers is requested to review the proposed merge of ~tcuthbert/charm-k8s-wordpress/+git/charm-k8s-wordpress:operator into charm-k8s-wordpress:master.
diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
new file mode 100644
index 0000000..db859b6
--- /dev/null
+++ b/tests/unit/test_charm.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+import copy
+import unittest
+import sys
+
+sys.path.append('lib') # noqa
+sys.path.append('src') # noqa
+
+from charm import WordpressK8sCharm
+from ops import testing
+from ops.model import BlockedStatus
+
+from test_wordpress import TEST_MODEL_CONFIG
+
+
+class TestWordpressK8sCharm(unittest.TestCase):
+
+ test_model_config = TEST_MODEL_CONFIG
+
+ def setUp(self):
+ self.harness = testing.Harness(
+ WordpressK8sCharm,
+ meta='''
+ name: wordpress
+ ''',
+ )
+
+ self.harness.begin()
+ self.harness.charm.model.config = copy.deepcopy(self.test_model_config)
+
+ def test_is_config_valid(self):
+ # Test a valid model config.
+ want_true = self.harness.charm.is_valid_config()
+ self.assertTrue(want_true)
+
+ # Test for invalid model config.
+ want_keys = ("image", "db_host", "db_name", "db_user", "db_password")
+ for wanted_key in want_keys:
+ self.harness.charm.model.config[wanted_key] = ""
+ want_false = self.harness.charm.is_valid_config()
+ self.assertFalse(want_false)
+ self.harness.charm.model.config = copy.deepcopy(self.test_model_config)
+
+ # Test for missing initial_settings in model config.
+ self.harness.charm.model.config["initial_settings"] = ""
+ want_false = self.harness.charm.is_valid_config()
+ self.assertFalse(want_false)
+ self.harness.charm.model.config = copy.deepcopy(self.test_model_config)
+
+ # Test unit status msg.
+ for wanted_key in want_keys:
+ self.harness.charm.model.config[wanted_key] = ""
+ expected_msg = "image db_host db_name db_user db_password config is required"
+ self.harness.charm.is_valid_config()
+ self.assertIsInstance(self.harness.charm.unit.status, BlockedStatus)
+ self.assertEqual(self.harness.charm.unit.status.message, expected_msg)
Follow ups