~hazmat/pyjuju/proposed-support

« back to all changes in this revision

Viewing changes to juju/state/tests/test_errors.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:
6
6
from juju.state.errors import (
7
7
    JujuError, StateError, StateChanged, CharmStateNotFound,
8
8
    ServiceStateNotFound, ServiceUnitStateNotFound,
9
 
    MachineStateNotFound,  MachineStateInUse, NoUnusedMachines,
 
9
    MachineStateNotFound, MachineStateInUse, NoUnusedMachines,
10
10
    ServiceUnitStateMachineAlreadyAssigned, ServiceStateNameInUse,
11
11
    BadServiceStateName, EnvironmentStateNotFound,
12
12
    RelationAlreadyExists, RelationStateNotFound, UnitRelationStateNotFound,
14
14
    BadDescriptor, DuplicateEndpoints, IncompatibleEndpoints,
15
15
    NoMatchingEndpoints, AmbiguousRelation,
16
16
    ServiceUnitStateMachineNotAssigned, ServiceUnitDebugAlreadyEnabled,
17
 
    ServiceUnitResolvedAlreadyEnabled,
 
17
    ServiceUnitResolvedAlreadyEnabled, ServiceUnitUpgradeAlreadyEnabled,
18
18
    ServiceUnitRelationResolvedAlreadyEnabled, PrincipalNotFound,
19
 
    RelationBrokenContextError)
 
19
    RelationBrokenContextError, PrincipalServiceUnitRequired,
 
20
    NotSubordinateCharm, UnitMissingContainer, SubordinateUsedAsContainer,
 
21
    InvalidRelationIdentity, UnsupportedSubordinateServiceRemoval,
 
22
    IllegalSubordinateMachineAssignment)
20
23
 
21
24
 
22
25
class StateErrorsTest(TestCase):
100
103
            str(error),
101
104
            "Service unit 'wordpress/0' is already in debug mode.")
102
105
 
 
106
    def test_unit_already_marked_for_upgrade(self):
 
107
        error = ServiceUnitUpgradeAlreadyEnabled("wordpress/0")
 
108
        self.assertIsStateError(error)
 
109
        self.assertEquals(error.unit_name, "wordpress/0")
 
110
        self.assertEquals(
 
111
            str(error),
 
112
            "Service unit 'wordpress/0' is already marked for upgrade.")
 
113
 
103
114
    def test_unit_already_in_resolved_mode(self):
104
115
        error = ServiceUnitResolvedAlreadyEnabled("wordpress/0")
105
116
        self.assertIsStateError(error)
220
231
        error = RelationBrokenContextError("+++ OUT OF CHEESE ERROR +++")
221
232
        self.assertIsStateError(error)
222
233
        self.assertEquals(str(error), "+++ OUT OF CHEESE ERROR +++")
 
234
 
 
235
    def test_unit_missing_container(self):
 
236
        error = UnitMissingContainer("blubber/0")
 
237
        self.assertIsStateError(error)
 
238
        self.assertEquals(str(error),
 
239
                          "The unit blubber/0 expected a principal "
 
240
                          "container but none was assigned.")
 
241
 
 
242
    def test_principal_service_unit_required(self):
 
243
        error = PrincipalServiceUnitRequired("lard", 1)
 
244
        self.assertIsStateError(error)
 
245
        self.assertEquals(str(error),
 
246
                          "Expected principal service unit as container for "
 
247
                          "lard instance, got 1")
 
248
 
 
249
    def test_subordinate_used_as_container(self):
 
250
        error = SubordinateUsedAsContainer("lard", "blubber/0")
 
251
        self.assertIsStateError(error)
 
252
        self.assertEquals(str(error),
 
253
                          "Attempted to assign unit of lard "
 
254
                          "to subordinate blubber/0")
 
255
 
 
256
    def test_not_subordinate_charm(self):
 
257
        error = NotSubordinateCharm("lard", "blubber/0")
 
258
        self.assertIsStateError(error)
 
259
        self.assertEquals(str(error),
 
260
                          "lard cannot be used as subordinate to blubber/0")
 
261
 
 
262
    def test_unsupported_subordinate_service_removal(self):
 
263
        error = UnsupportedSubordinateServiceRemoval("lard", "blubber")
 
264
        self.assertIsStateError(error)
 
265
        self.assertEquals(str(error),
 
266
                          "Unsupported attempt to destroy subordinate "
 
267
                          "service 'lard' while principal service "
 
268
                          "'blubber' is related.")
 
269
 
 
270
    def test_invalid_relation_ident(self):
 
271
        error = InvalidRelationIdentity("invalid-id$forty-two")
 
272
        self.assertTrue(isinstance(error, JujuError))
 
273
        self.assertTrue(isinstance(error, ValueError))
 
274
        self.assertEquals(
 
275
            str(error),
 
276
            "Not a valid relation id: 'invalid-id$forty-two'")
 
277
 
 
278
    def test_illegal_subordinate_machine_assignment(self):
 
279
        error = IllegalSubordinateMachineAssignment("blubber/1")
 
280
        self.assertTrue(isinstance(error, JujuError))
 
281
        self.assertEquals(
 
282
            str(error),
 
283
            "Unable to assign subordinate blubber/1 to machine.")