~pwlars/uci-engine/kill-the-waaaabbit

« back to all changes in this revision

Viewing changes to charms/precise/wsgi-app/unit_tests/test_hooks.py

Consolidates all uci-e juju services and relations into single files. [r=PS Jenkins bot, Parameswaran Sivatharman, Paul Larson, Ursula Junque, Evan Dandrea]

Show diffs side-by-side

added added

removed removed

Lines of Context:
437
437
            f.write('rm $0   # just delete ourself')
438
438
            f.flush()
439
439
        self.config.return_value['db_migration_cmd'] = 'dash ./tmp.sh'
 
440
        self.config.return_value['wsgi_user'] = os.getlogin()
440
441
        hooks.hooks.execute([hook])
441
442
        if runs:
442
443
            self.assertFalse(os.path.exists(os.path.join(cdir, 'tmp.sh')))
466
467
    def test_pgsql_broken(self):
467
468
        hooks.hooks.execute(['hooks/pgsql-relation-broken'])
468
469
        self.assertEqual(1, self.wsgi_reload.call_count)
 
470
 
 
471
 
 
472
class TestOAuthHooks(RestishTestCase):
 
473
 
 
474
    def setUp(self):
 
475
        super(TestOAuthHooks, self).setUp()
 
476
        local_patches = (
 
477
            'hooks._service_dir',
 
478
            'hooks._wsgi_reload',
 
479
            'hooks.update_nrpe_config',
 
480
            'hooks.handle_code',
 
481
        )
 
482
 
 
483
        for spec in local_patches:
 
484
            attr_name = spec.split('.')[-1]
 
485
            _m = mock.patch(spec)
 
486
            setattr(self, attr_name, _m.start())
 
487
            self.addCleanup(_m.stop)
 
488
 
 
489
        self._service_dir.return_value = self.tmpdir
 
490
 
 
491
        self.relation_ids.side_effect = lambda rel: ['oauth:1']
 
492
        self.related_units.return_value = ['a_unit']
 
493
        self.relation_get.side_effect = lambda rid, unit: {'url': 'A_URL'}
 
494
 
 
495
    @mock.patch('subprocess.check_output')
 
496
    def test_oauth_client(self, c_output):
 
497
        c_output.return_value = 'A_KEY:A_SECRET'
 
498
        hooks.hooks.execute(['hooks/config_changed'])
 
499
        c_output.assert_called_once_with(
 
500
            ['sudo -u www-data ./run-python ticket_system/manage.py '
 
501
             'create_client A_URL'],
 
502
            shell=True,
 
503
            cwd='%s/code/current' % self.tmpdir
 
504
        )