Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(51)

Delta Between Two Patch Sets: juju/state/tests/test_hook.py

Issue 5845061: juju/control should be aware of subordinates
Left Patch Set: Created 13 years ago
Right Patch Set: juju/control should be aware of subordinates Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « juju/state/tests/test_firewall.py ('k') | juju/state/tests/test_initialize.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import yaml 1 import yaml
2 2
3 from twisted.internet.defer import inlineCallbacks, returnValue 3 from twisted.internet.defer import inlineCallbacks, returnValue
4 from juju.lib.pick import pick_attr 4 from juju.lib.pick import pick_attr
5 from juju.lib.testing import TestCase 5 from juju.lib.testing import TestCase
6 6
7 from juju.state.endpoint import RelationEndpoint 7 from juju.state.endpoint import RelationEndpoint
8 from juju.state.hook import ( 8 from juju.state.hook import (
9 DepartedRelationHookContext, HookContext, RelationChange, 9 DepartedRelationHookContext, HookContext, RelationChange,
10 RelationHookContext) 10 RelationHookContext)
11 from juju.state.errors import ( 11 from juju.state.errors import (
12 UnitRelationStateNotFound, RelationBrokenContextError) 12 UnitRelationStateNotFound, RelationBrokenContextError)
13 from juju.state.tests.test_relation import RelationTestBase 13 from juju.state.tests.test_relation import RelationTestBase
14 from juju.state.utils import AddedItem, DeletedItem, ModifiedItem 14 from juju.state.utils import AddedItem, DeletedItem, ModifiedItem
15 15
16 16
17 class RelationChangeTest(TestCase): 17 class RelationChangeTest(TestCase):
18 18
19 def test_change_properties(self): 19 def test_change_properties(self):
20 20
21 change = RelationChange("db", "membership", "mysql/0") 21 change = RelationChange("db:42", "membership", "mysql/0")
22 self.assertEqual(change.relation_name, "db") 22 self.assertEqual(change.relation_name, "db")
23 self.assertEqual(change.relation_ident, "db:42")
23 self.assertEqual(change.change_type, "membership") 24 self.assertEqual(change.change_type, "membership")
24 self.assertEqual(change.unit_name, "mysql/0") 25 self.assertEqual(change.unit_name, "mysql/0")
25 26
26 27
27 class CommonHookContextTestsMixin(object): 28 class CommonHookContextTestsMixin(object):
28 29
29 @inlineCallbacks 30 @inlineCallbacks
30 def test_config_get(self): 31 def test_config_get(self):
31 """Verify we can get config settings. 32 """Verify we can get config settings.
32 33
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 102
102 @inlineCallbacks 103 @inlineCallbacks
103 def setUp(self): 104 def setUp(self):
104 yield super(HookContextTest, self).setUp() 105 yield super(HookContextTest, self).setUp()
105 self.service = self.wordpress_states["service"] 106 self.service = self.wordpress_states["service"]
106 self.unit = self.wordpress_states["unit"] 107 self.unit = self.wordpress_states["unit"]
107 self.context = HookContext( 108 self.context = HookContext(
108 self.client, unit_name=self.unit.unit_name) 109 self.client, unit_name=self.unit.unit_name)
109 110
110 111
111 class RelationHookContextTest(HookContextTestBase, CommonHookContextTestsMixin): 112 class RelationHookContextTest(HookContextTestBase,
113 CommonHookContextTestsMixin):
112 114
113 @inlineCallbacks 115 @inlineCallbacks
114 def setUp(self): 116 def setUp(self):
115 yield super(RelationHookContextTest, self).setUp() 117 yield super(RelationHookContextTest, self).setUp()
116 self.service = self.wordpress_states["service"] 118 self.service = self.wordpress_states["service"]
117 self.unit = self.wordpress_states["unit"] 119 self.unit = self.wordpress_states["unit"]
118 self.reset_context() 120 self.reset_context()
119 121
120 def reset_context(self): 122 def reset_context(self):
121 self.context = self.get_context( 123 self.context = self.get_context(
122 self.wordpress_states, "modified", "mysql/0") 124 self.wordpress_states, "modified", "mysql/0")
123 125
124 def get_context(self, states, change_type, unit_name): 126 def get_context(self, states, change_type, unit_name):
125 change = RelationChange( 127 change = RelationChange(
126 states["service_relation"].relation_name, 128 states["service_relation"].relation_ident,
127 change_type, 129 change_type,
128 unit_name) 130 unit_name)
129 return RelationHookContext( 131 return RelationHookContext(
130 self.client, states["unit_relation"], change, 132 self.client, states["unit_relation"], change,
131 unit_name=self.unit.unit_name) 133 unit_name=self.unit.unit_name)
132 134
133 @inlineCallbacks 135 @inlineCallbacks
134 def test_get(self): 136 def test_get(self):
135 """Settings from a related unit can be retrieved as a blob.""" 137 """Settings from a related unit can be retrieved as a blob."""
136 yield self.mysql_states["unit_relation"].set_data({"hello": "world"}) 138 yield self.mysql_states["unit_relation"].set_data({"hello": "world"})
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 def test_get_self(self): 613 def test_get_self(self):
612 """Own settings can be retrieved.""" 614 """Own settings can be retrieved."""
613 settings_path = self.get_unit_settings_path( 615 settings_path = self.get_unit_settings_path(
614 self.relation_state, 616 self.relation_state,
615 self.unit, 617 self.unit,
616 self.container_unit) 618 self.container_unit)
617 self.client.set(settings_path, 619 self.client.set(settings_path,
618 yaml.dump({"hello": "world"})) 620 yaml.dump({"hello": "world"}))
619 data = yield self.context.get(None) 621 data = yield self.context.get(None)
620 self.assertEquals(data, {"hello": "world"}) 622 self.assertEquals(data, {"hello": "world"})
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b