示例#1
0
    def test_charm_instance(self):
        with mock.patch.object(adapters.hookenv, 'config', new=lambda: {}):
            c = adapters.ConfigurationAdapter()
            self.assertEqual(c.charm_instance, None)

            class MockCharm(object):
                pass

            instance = MockCharm()
            c = adapters.ConfigurationAdapter(charm_instance=instance)
            self.assertEqual(c.charm_instance, instance)
            self.assertTrue(c._charm_instance_weakref is not None)
 def test_application_name(self):
     with mock.patch.object(adapters.hookenv, 'config', new=lambda: {}):
         with mock.patch.object(adapters.hookenv,
                                'service_name',
                                return_value='myapp'):
             c = adapters.ConfigurationAdapter()
             self.assertEqual(c.application_name, 'myapp')
示例#3
0
 def test_class(self):
     test_config = {'one': 1, 'two': 2, 'three': 3, 'that-one': 4}
     with mock.patch.object(adapters.hookenv,
                            'config',
                            new=lambda: test_config):
         c = adapters.ConfigurationAdapter()
         self.assertEqual(c.one, 1)
         self.assertEqual(c.three, 3)
         self.assertEqual(c.that_one, 4)