~bcsaller/charms/trusty/cloudfoundry/progressbar

« back to all changes in this revision

Viewing changes to tests/test_contexts.py

  • Committer: Benjamin Saller
  • Date: 2014-11-07 21:10:56 UTC
  • mfrom: (145.1.13 trunk)
  • Revision ID: benjamin.saller@canonical.com-20141107211056-zu7scr425xyv042x
merge mega

Show diffs side-by-side

added added

removed removed

Lines of Context:
200
200
class TestCloudFoundryCredentials(unittest.TestCase):
201
201
    @mock.patch('charmhelpers.core.hookenv.charm_dir', lambda: 'charm_dir')
202
202
    @mock.patch('charmhelpers.core.services.RelationContext.get_data', mock.Mock())
203
 
    def test_provide_data(self):
204
 
        result = contexts.CloudFoundryCredentials().provide_data()
205
 
        self.assertEqual(result, {
206
 
                "admin-password": "admin",
207
 
                "admin-user": "admin"
 
203
    @mock.patch('charmhelpers.core.hookenv.config')
 
204
    def test_provide_data_config(self, config):
 
205
        config.return_value = {'admin_password': 'test'}
 
206
        result = contexts.CloudFoundryCredentials().provide_data()
 
207
        self.assertEqual(result, {
 
208
            "admin-password": "test",
 
209
            "admin-user": "admin"
 
210
        })
 
211
 
 
212
    @mock.patch('charmhelpers.core.hookenv.charm_dir', lambda: 'charm_dir')
 
213
    @mock.patch('charmhelpers.core.services.RelationContext.get_data', mock.Mock())
 
214
    @mock.patch('cloudfoundry.contexts.StoredContext')
 
215
    @mock.patch('charmhelpers.core.host.pwgen')
 
216
    @mock.patch('charmhelpers.core.hookenv.config')
 
217
    def test_provide_data_gen(self, config, pwgen, StoredContext):
 
218
        config.return_value = {'admin_password': ''}
 
219
        pwgen.return_value = 'pw1'
 
220
        StoredContext.return_value = {'admin_password': 'pw2'}
 
221
        result = contexts.CloudFoundryCredentials().provide_data()
 
222
        self.assertEqual(result, {
 
223
            "admin-password": "pw2",
 
224
            "admin-user": "admin"
 
225
        })
 
226
        StoredContext.assert_called_once_with('cf-secrets.yml', {
 
227
            'admin_password': 'pw1',
208
228
        })
209
229
 
210
230