~bcsaller/charms/precise/juju-gui/apache-fallback

« back to all changes in this revision

Viewing changes to tests/test_backends.py

  • Committer: Benjamin Saller
  • Author(s): Benjamin Saller
  • Date: 2013-04-17 20:51:54 UTC
  • mfrom: (41.1.17 sandbox-charm)
  • Revision ID: bcsaller@gmail.com-20130417205154-uyl9rhuh95ix8dy8
Refactor Charm for Sandbox support

This adds a composition system for creating backend object.
Backend implement start(), stop() and install() methods. A backend
is composed of many mixins and each mixin will implement any/of
of those methods and all will be called. Backends additionally 
provide for collecting property values from each mixin into a single 
final property on the backend. There is also a feature for determining 
if configuration values have changed between old and new configurations
so we can selectively take action.

Using these features we add support for Sandbox'd deployments, 
limiting support for adding apt repositories and the ability 
to fetch a juju-gui release from a URL specified in a configuration 
property.

R=gary.poster, matthew.scott
CC=
https://codereview.appspot.com/8727047

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
 
 
3
from backend import Backend
 
4
 
 
5
class TestBackends(unittest.TestCase):
 
6
    """
 
7
    As the number of configurations this charm supports increases it becomes
 
8
    desirable to move to Strategy pattern objects to implement features
 
9
    per backend. These tests insure the basic factory code works.
 
10
    """
 
11
    def backendNames(self, backend):
 
12
        return [b.__class__.__name__ for b in backend.backends]
 
13
 
 
14
    def test_get_python(self):
 
15
        config = {
 
16
            "sandbox": False,
 
17
            "staging": True,
 
18
        }
 
19
        backend = Backend(config)
 
20
        self.assertIn("nginx", backend.debs)
 
21
        self.assertIn("haproxy", backend.debs)
 
22
        self.assertIn("curl", backend.debs)
 
23
        self.assertIn("openssl", backend.debs)
 
24
        self.assertIn('zookeeper', backend.debs)
 
25
        self.assertIn('ppa:juju-gui/ppa', backend.repositories)
 
26
        self.assertIn('ImprovBackend', self.backendNames(backend))
 
27
        self.assertNotIn('PythonBackend', self.backendNames(backend))
 
28
 
 
29
 
 
30
    def test_get_python_sandbox(self):
 
31
        config = {
 
32
            "sandbox": True,
 
33
            "staging": True,
 
34
        }
 
35
        backend = Backend(config)
 
36
        self.assertIn("nginx", backend.debs)
 
37
        self.assertNotIn('zookeeper', backend.debs)
 
38
        self.assertNotIn('ImprovBackend', self.backendNames(backend))
 
39