4
from textwrap import dedent
5
from unittest import TestCase
7
from jujupy import _temp_env
8
from utility import temp_dir
9
from write_industrial_test_metadata import (
16
class TestWriteIndustrialTestMetadata(TestCase):
18
def test_parse_args_insufficiennt_args(self):
19
with patch('sys.stderr'):
20
with self.assertRaises(SystemExit):
21
parse_args(['foo', 'bar'])
23
def test_parse_args(self):
24
args = parse_args(['foo', 'bar', 'baz'])
25
self.assertItemsEqual(['buildvars', 'env', 'output'],
26
[a for a in dir(args) if not a.startswith('_')])
27
self.assertEqual(args.buildvars, 'foo')
28
self.assertEqual(args.env, 'bar')
29
self.assertEqual(args.output, 'baz')
31
def test_make_metadata(self):
32
with temp_dir() as tempdir:
33
buildvars_path = os.path.join(tempdir, 'buildvars')
34
with open(buildvars_path, 'w') as buildvars_file:
35
json.dump({'foo': 'bar'}, buildvars_file)
36
with patch('subprocess.check_output', return_value='1.20'):
37
envs = {'environments': {'foobar': {'type': 'local'}}}
39
metadata = make_metadata(buildvars_path, 'foobar')
40
self.assertEqual(metadata, {
42
'buildvars': {'foo': 'bar'},
51
'substrate': 'LXC (local)',
56
with temp_dir() as tempdir:
57
buildvars_path = os.path.join(tempdir, 'buildvars')
58
with open(buildvars_path, 'w') as buildvars_file:
59
json.dump({'foo': 'bar'}, buildvars_file)
60
output_path = os.path.join(tempdir, 'output')
61
envs = {'environments': {'foo': {'type': 'ec2'}}}
63
with patch('subprocess.check_output', return_value='1.20'):
64
main([buildvars_path, 'foo', output_path])
65
with open(output_path) as output_file:
66
output = output_file.read()
67
expected = dedent("""\
80
"type": "release",\x20
85
self.assertEqual(output, expected)