コード例 #1
0
    def test_raises_error_from_inner_object_as_dict(self):
        foo = {
            'bar': 'baz',
        }
        wrapped = hookenv.Serializable(foo)

        self.assertRaises(AttributeError, getattr, wrapped, 'baz')
コード例 #2
0
    def test_gets_inner_object(self):
        foo = {
            'bar': 'baz',
        }
        wrapped = hookenv.Serializable(foo)

        self.assertIs(wrapped.data, foo)
コード例 #3
0
    def test_gets_attribute_from_inner_object_as_dict(self):
        foo = {
            'bar': 'baz',
        }
        wrapped = hookenv.Serializable(foo)

        self.assertEqual(wrapped.bar, 'baz')
コード例 #4
0
    def test_equality(self):
        foo = {'bar': 'baz'}
        bar = {'baz': 'bar'}
        wrapped_foo = hookenv.Serializable(foo)

        self.assertEqual(wrapped_foo, foo)
        self.assertEqual(wrapped_foo, wrapped_foo)
        self.assertNotEqual(wrapped_foo, bar)
コード例 #5
0
    def test_pickle(self):
        foo = {'bar': 'baz'}
        wrapped = hookenv.Serializable(foo)
        pickled = pickle.dumps(wrapped)
        unpickled = pickle.loads(pickled)

        self.assert_(isinstance(unpickled, hookenv.Serializable))
        self.assertEqual(unpickled, foo)
コード例 #6
0
    def test_get_gets_from_inner_object(self):
        foo = {
            'bar': 'baz',
        }
        wrapped = hookenv.Serializable(foo)

        self.assertEqual(wrapped.get('foo'), None)
        self.assertEqual(wrapped.get('bar'), 'baz')
        self.assertEqual(wrapped.get('zoo', 'bla'), 'bla')
コード例 #7
0
    def test_dict_methods_from_inner_object(self):
        foo = {
            'bar': 'baz',
        }
        wrapped = hookenv.Serializable(foo)
        for meth in ('keys', 'values', 'items'):
            self.assertEqual(sorted(list(getattr(wrapped, meth)())),
                             sorted(list(getattr(foo, meth)())))

        self.assertEqual(wrapped.get('bar'), foo.get('bar'))
        self.assertEqual(wrapped.get('baz', 42), foo.get('baz', 42))
        self.assertIn('bar', wrapped)
コード例 #8
0
    def test_writes_vars_file(self):
        ansible, hookenv = self.makeone()
        self.assertFalse(os.path.exists(self.vars_path))
        self.mock_config.return_value = hookenv.Serializable({
            'group_code_owner':
            'webops_deploy',
            'user_code_runner':
            'ubunet',
            'private-address':
            '10.10.10.10',
        })
        self.mock_relation_type.return_value = 'wsgi-file'
        self.mock_relation_get.return_value = {
            'relation_key1': 'relation_value1',
            'relation-key2': 'relation_value2',
        }

        ansible.apply_playbook('playbooks/dependencies.yaml')

        self.assertTrue(os.path.exists(self.vars_path))
        with open(self.vars_path, 'r') as vars_file:
            result = yaml.load(vars_file.read())
            control = {
                "group_code_owner": "webops_deploy",
                "user_code_runner": "ubunet",
                "private_address": "10.10.10.10",
                "charm_dir": "",
                "service_name": "svc",
                "local_unit": "svc/1",
                'current_relation': {
                    'relation_key1': 'relation_value1',
                    'relation-key2': 'relation_value2',
                },
                'relations_full': {
                    'nrpe-external-master': {},
                    'website': {},
                    'wsgi-file': {},
                },
                'relations': {
                    'nrpe-external-master': [],
                    'website': [],
                    'wsgi-file': [],
                },
                "wsgi_file__relation_key1": "relation_value1",
                "wsgi_file__relation_key2": "relation_value2",
                "unit_private_address": "10.0.3.2",
                "unit_public_address": "123.123.123.123",
            }
            assert control == result, tuple(dd.diff(control, result))
コード例 #9
0
    def test_boolean(self):
        true_dict = {'foo': 'bar'}
        false_dict = {}

        self.assertIs(bool(hookenv.Serializable(true_dict)), True)
        self.assertIs(bool(hookenv.Serializable(false_dict)), False)
コード例 #10
0
 def test_serializes_object_to_yaml(self):
     foo = {
         'bar': 'baz',
     }
     wrapped = hookenv.Serializable(foo)
     self.assertEqual(wrapped.yaml(), yaml.dump(foo))
コード例 #11
0
 def test_serializes_object_to_json(self):
     foo = {
         'bar': 'baz',
     }
     wrapped = hookenv.Serializable(foo)
     self.assertEqual(wrapped.json(), json.dumps(foo))