~marcoceppi/charm-tools/python-port

« back to all changes in this revision

Viewing changes to helpers/python/charmhelpers/tests/test_charmhelpers.py

  • Committer: Marco Ceppi
  • Author(s): mattyw
  • Date: 2013-08-21 04:04:38 UTC
  • Revision ID: marco@ceppi.net-20130821040438-l68hcgatpw88bvbl
get charm directory from env variable, if it isn't set raise an exception

Show diffs side-by-side

added added

removed removed

Lines of Context:
475
475
        # The Go version of juju install an agent.conf file in the directory
476
476
        # above the charm. If that file exists then we must be running against
477
477
        # the go version of juju
 
478
        os.environ['CHARM_DIR'] = os.getcwd()
 
479
 
 
480
        def cleanup():
 
481
            del os.environ["CHARM_DIR"]
 
482
        self.addCleanup(cleanup)
 
483
 
478
484
        agent_file_path = "%s/../agent.conf" % os.getcwd()
479
485
        with open(agent_file_path, 'w') as agent_file:
480
486
            agent_file.write("")
 
487
 
481
488
        self.assertEqual(False, charmhelpers.legacy_juju())
482
489
        os.remove(agent_file_path)
483
490
        self.assertEqual(False, os.path.exists(agent_file_path))
486
493
        # The Go version of juju install an agent.conf file in the directory
487
494
        # above the charm. If that file doesn't exist then we must be running
488
495
        # against the legacy version of juju
 
496
        os.environ['CHARM_DIR'] = os.getcwd()
 
497
 
 
498
        def cleanup():
 
499
            del os.environ["CHARM_DIR"]
 
500
        self.addCleanup(cleanup)
 
501
 
489
502
        agent_file_exists = os.path.exists("%s/../agent.conf" % os.getcwd())
490
503
        self.assertEqual(False, agent_file_exists)
491
504
        self.assertEqual(True, charmhelpers.legacy_juju())
492
505
 
 
506
    def test_legacy_raises_exception(self):
 
507
        # The Go version of juju install an agent.conf file in the directory
 
508
        # above the charm. If the env variable CHARM_DIR isn't set we can't
 
509
        # reasonably work out which version of juju we're running
 
510
        self.assertRaises(KeyError, lambda: os.environ["CHARM_DIR"])
 
511
        self.assertRaises(
 
512
            charmhelpers.CantDetermineJujuVersionException,
 
513
            charmhelpers.legacy_juju)
 
514
 
493
515
 
494
516
if __name__ == '__main__':
495
517
    unittest.main()