~hazmat/pyjuju/proposed-support

« back to all changes in this revision

Viewing changes to juju/agents/tests/common.py

  • Committer: kapil.thangavelu at canonical
  • Date: 2012-05-22 22:08:15 UTC
  • mfrom: (484.1.53 trunk)
  • Revision ID: kapil.thangavelu@canonical.com-20120522220815-acyt8m89i9ybe0w1
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
from txzookeeper.tests.utils import deleteTree
6
6
 
7
7
from juju.agents.base import TwistedOptionNamespace
8
 
from juju.environment.config import EnvironmentsConfig
9
8
from juju.state.tests.common import StateTestBase
10
9
from juju.tests.common import get_test_zookeeper_address
11
10
 
12
11
 
13
 
SAMPLE_ENV = """\
14
 
environments:
15
 
  myfirstenv:
16
 
    type: dummy
17
 
    foo: bar
18
 
    storage-directory: %s
19
 
"""
20
 
 
21
 
 
22
12
class AgentTestBase(StateTestBase):
23
13
 
24
14
    agent_class = None
25
15
    juju_directory = None
 
16
    setup_environment = True
26
17
 
27
18
    @inlineCallbacks
28
19
    def setUp(self):
29
20
        self.juju_directory = self.makeDir()
30
21
        yield super(AgentTestBase, self).setUp()
31
22
        assert self.agent_class, "Agent Class must be specified on test"
 
23
        if self.setup_environment:
 
24
            yield self.push_default_config()
32
25
        self.agent = self.agent_class()
33
26
        self.options = yield self.get_agent_config()
34
27
        self.agent.configure(self.options)
42
35
            deleteTree("/", self.client.handle)
43
36
            self.client.close()
44
37
 
45
 
    def get_test_environment_config(self):
46
 
        sample_config = SAMPLE_ENV % self.makeDir()
47
 
        config = EnvironmentsConfig()
48
 
        config.parse(sample_config)
49
 
        return config
50
 
 
51
 
    def get_test_environment(self):
52
 
        return self.get_test_environment_config().get_default()
53
 
 
54
38
    def get_agent_config(self):
55
39
        options = TwistedOptionNamespace()
56
40
        options["juju_directory"] = self.juju_directory