~billy-olsen/charm-helpers/better-address-endpoint-overrides

« back to all changes in this revision

Viewing changes to tests/core/test_hookenv.py

  • Committer: james.page at ubuntu
  • Date: 2015-05-20 22:56:01 UTC
  • mfrom: (369.2.2 charm-helpers-hookenv)
  • Revision ID: james.page@ubuntu.com-20150520225601-43t384k7r4lx8mh4
Add basic hookenv support for leadership-election

Show diffs side-by-side

added added

removed removed

Lines of Context:
668
668
            },
669
669
        })
670
670
 
 
671
    @patch('charmhelpers.core.hookenv.relation_set')
 
672
    @patch('charmhelpers.core.hookenv.relation_get')
 
673
    @patch('charmhelpers.core.hookenv.local_unit')
 
674
    def test_relation_clear(self, local_unit,
 
675
                            relation_get,
 
676
                            relation_set):
 
677
        local_unit.return_value = 'local-unit'
 
678
        relation_get.return_value = {
 
679
            'private-address': '10.5.0.1',
 
680
            'foo': 'bar',
 
681
            'public-address': '146.192.45.6'
 
682
        }
 
683
        hookenv.relation_clear('relation:1')
 
684
        relation_get.assert_called_with(rid='relation:1',
 
685
                                        unit='local-unit')
 
686
        relation_set.assert_called_with(
 
687
            relation_id='relation:1',
 
688
            **{'private-address': '10.5.0.1',
 
689
               'foo': None,
 
690
               'public-address': '146.192.45.6'})
 
691
 
671
692
    @patch('charmhelpers.core.hookenv.relation_ids')
672
693
    @patch('charmhelpers.core.hookenv.related_units')
673
694
    @patch('charmhelpers.core.hookenv.relation_get')
1050
1071
        with patch.dict('os.environ', {'CHARM_DIR': '/var/empty'}):
1051
1072
            self.assertEqual(hookenv.charm_dir(), '/var/empty')
1052
1073
 
 
1074
    @patch('subprocess.check_output')
 
1075
    def test_is_leader_unsupported(self, check_output_):
 
1076
        check_output_.side_effect = OSError(2, 'is-leader')
 
1077
        self.assertRaises(NotImplementedError, hookenv.is_leader)
 
1078
 
 
1079
    @patch('subprocess.check_output')
 
1080
    def test_is_leader(self, check_output_):
 
1081
        check_output_.return_value = b'false'
 
1082
        self.assertFalse(hookenv.is_leader())
 
1083
        check_output_.return_value = b'true'
 
1084
        self.assertTrue(hookenv.is_leader())
 
1085
 
1053
1086
 
1054
1087
class HooksTest(TestCase):
1055
1088
    def setUp(self):