~adam-collard/charms/trusty/swift-proxy/add-missing-symlinks

« back to all changes in this revision

Viewing changes to unit_tests/test_swift_context.py

  • Committer: Christopher Glass
  • Date: 2015-09-07 14:18:22 UTC
  • mfrom: (106.1.5 lib-in-python-package)
  • Revision ID: christopher.glass@canonical.com-20150907141822-69auo1g57dnkc4je
Merge lp:~adam-collard/charms/trusty/swift-proxy/lib-in-python-package [a=adam.collard] [r=tribaal]

Refactor hooks/lib into a lib/ folder to prepare for actions implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
 
8
8
with mock.patch('charmhelpers.core.hookenv.config'):
9
 
    import swift_context
 
9
    import lib.swift_context as swift_context
10
10
 
11
11
 
12
12
class SwiftContextTestCase(unittest.TestCase):
13
13
 
14
 
    @mock.patch('swift_context.config')
 
14
    @mock.patch('lib.swift_context.config')
15
15
    def test_get_swift_hash_file(self, mock_config):
16
16
        expected = '##FILEHASH##'
17
17
        with tempfile.NamedTemporaryFile() as tmpfile:
24
24
        self.assertFalse(mock_config.called)
25
25
        self.assertEqual(expected, hash)
26
26
 
27
 
    @mock.patch('swift_context.config')
 
27
    @mock.patch('lib.swift_context.config')
28
28
    def test_get_swift_hash_config(self, mock_config):
29
29
        expected = '##CFGHASH##'
30
30
        mock_config.return_value = expected
38
38
        self.assertTrue(mock_config.called)
39
39
        self.assertEqual(expected, hash)
40
40
 
41
 
    @mock.patch('swift_context.service_name')
42
 
    @mock.patch('swift_context.config')
 
41
    @mock.patch('lib.swift_context.service_name')
 
42
    @mock.patch('lib.swift_context.config')
43
43
    def test_get_swift_hash_env(self, mock_config, mock_service_name):
44
44
        mock_config.return_value = None
45
45
        mock_service_name.return_value = "testsvc"
47
47
        swift_context.SWIFT_HASH_FILE = tmpfile
48
48
        with mock.patch('swift_context.os.environ.get') as mock_env_get:
49
49
            mock_env_get.return_value = str(uuid.uuid4())
50
 
            hash = swift_context.get_swift_hash()
 
50
            hash_ = swift_context.get_swift_hash()
51
51
            mock_env_get.assert_called_with('JUJU_ENV_UUID')
52
52
 
53
53
        with open(tmpfile, 'r') as fd:
54
 
            self.assertEqual(hash, fd.read())
 
54
            self.assertEqual(hash_, fd.read())
55
55
 
56
56
        self.assertTrue(mock_config.called)