コード例 #1
0
    def test_set_charm_instance(self):

        # a fake charm instance to play with
        class FakeCharm(object):
            name = 'fake-charm'

        shared_db = FakeDatabaseRelation()
        charm = FakeCharm()
        a = adapters.OpenStackRelationAdapters([shared_db],
                                               charm_instance=charm)
        self.assertEqual(a.charm_instance, charm)
コード例 #2
0
 def test_class(self):
     test_config = {'one': 1, 'two': 2, 'three': 3, 'that-one': 4}
     with mock.patch.object(adapters, 'PeerHARelationAdapter',
                            new=FakePeerHARelationAdapter), \
             mock.patch.object(adapters.hookenv, 'config',
                               new=lambda: test_config):
         amqp = FakeRabbitMQRelation()
         shared_db = FakeDatabaseRelation()
         mine = MyRelation()
         a = adapters.OpenStackRelationAdapters([amqp, shared_db, mine])
         self.assertEqual(a.amqp.private_address, 'private-address')
         self.assertEqual(a.my_name.this, 'this')
         items = list(a)
         self.assertEqual(items[0][0], 'options')
         #            self.assertEqual(items[1][0], 'cluster')
         self.assertEqual(items[1][0], 'amqp')
         self.assertEqual(items[2][0], 'shared_db')
         self.assertEqual(items[3][0], 'my_name')
コード例 #3
0
 def test_class(self):
     test_config = {'one': 1, 'two': 2, 'three': 3, 'that-one': 4}
     with mock.patch.object(adapters, 'PeerHARelationAdapter',
                            new=FakePeerHARelationAdapter), \
             mock.patch.object(adapters.hookenv, 'config',
                               new=lambda: test_config):
         amqp = FakeRabbitMQRelation()
         shared_db = FakeDatabaseRelation()
         mine = MyRelation()
         a = adapters.OpenStackRelationAdapters([amqp, shared_db, mine])
         self.assertEqual(a.amqp.private_address, 'private-address')
         self.assertEqual(a.my_name.this, 'this')
         # pick the keys off the __iter__() for the adapters instance
         items = [x[0] for x in list(a)]
         self.assertTrue('options' in items)
         # self.assertTrue('cluster' in items)
         self.assertTrue('amqp' in items)
         self.assertTrue('shared_db' in items)
         self.assertTrue('my_name' in items)
コード例 #4
0
    def test_custom_configurations_creation(self):
        # Test we can bring in a custom configurations

        class FakeConfigurationAdapter(adapters.ConfigurationAdapter):
            def __init__(self, charm_instance):
                self.test = 'hello'

        class FakeCharm(object):
            name = 'fake-charm'
            configuration_class = FakeConfigurationAdapter

        with mock.patch.object(adapters, '_custom_config_properties', new={}):

            @adapters.config_property
            def custom_prop(config):
                return config.test

            a = adapters.OpenStackRelationAdapters([],
                                                   charm_instance=FakeCharm())

            self.assertEqual(a.options.custom_prop, 'hello')
            self.assertIsInstance(a.options, FakeConfigurationAdapter)