Merge lp:~abentley/juju-core/cleanups into lp:~juju-qa/juju-core/cd-release-juju

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 285
Proposed branch: lp:~abentley/juju-core/cleanups
Merge into: lp:~juju-qa/juju-core/cd-release-juju
Diff against target: 134 lines (+48/-13)
3 files modified
tests/test_update_streams.py (+19/-12)
tests/test_utility.py (+28/-1)
update_config.py (+1/-0)
To merge this branch: bzr merge lp:~abentley/juju-core/cleanups
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+287652@code.launchpad.net

Commit message

Add tests, fix lint.

Description of the change

This branch cleans the hasty fixes needed to use signed streams.

It adds tests for require_branch, updates the get_path_hashes tests, and fixes some lint.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test_update_streams.py'
2--- tests/test_update_streams.py 2016-02-23 17:53:55 +0000
3+++ tests/test_update_streams.py 2016-03-01 15:34:50 +0000
4@@ -22,22 +22,22 @@
5 class TestParseArgs(TestCase):
6
7 def test_default(self):
8- parsed = parse_args(['foo', 'bar', 'baz'])
9+ parsed = parse_args(['foo', 'bar', 'baz', 'qux'])
10 expected = Namespace(
11- config_file='foo', s3_root='bar', dest='baz', version=None,
12- poke='0', timestamp=None)
13+ config_file='foo', s3_root='bar', dest='baz',
14+ simplestreams_dir='qux', version=None, poke='0', timestamp=None)
15 self.assertEqual(expected, parsed)
16
17 def test_version(self):
18- parsed = parse_args(['foo', 'bar', 'baz', 'qux'])
19- self.assertEqual('qux', parsed.version)
20+ parsed = parse_args(['foo', 'bar', 'baz', 'qux', 'quxx'])
21+ self.assertEqual('quxx', parsed.version)
22
23 def test_poke(self):
24- parsed = parse_args(['foo', 'bar', 'baz', '--poke', '123'])
25+ parsed = parse_args(['foo', 'bar', 'baz', 'qux', '--poke', '123'])
26 self.assertEqual('123', parsed.poke)
27
28 def test_timestamp(self):
29- parsed = parse_args(['foo', 'bar', 'baz', '--timestamp',
30+ parsed = parse_args(['foo', 'bar', 'baz', 'qux', '--timestamp',
31 'Wed, 17 Feb 2016 20:44:59 +0000'])
32 self.assertEqual('Wed, 17 Feb 2016 20:44:59 +0000', parsed.timestamp)
33
34@@ -59,16 +59,17 @@
35 def test_from_args(self):
36 updater = Updater.from_args(Namespace(
37 config_file='foo', s3_root='bar', dest='baz', version='qux',
38- poke='123'), 'temp_dir1')
39+ poke='123', simplestreams_dir='quxx'), 'temp_dir1')
40 self.assertEqual(updater.config_file, 'foo')
41 self.assertEqual(updater.s3_root, 'bar')
42 self.assertEqual(updater.dest, 'baz')
43 self.assertEqual(updater.version, 'qux')
44 self.assertEqual(updater.temp_dir, 'temp_dir1')
45+ self.assertEqual(updater.simplestreams_dir, 'quxx')
46
47 def make_updater(self, download_dir='temp_dir1', dest_dir='dest1'):
48 return Updater('config1', 's3_root1', download_dir, dest_dir,
49- 'version1')
50+ 'sstream_dir', 'version1')
51
52 def test_s3cmd(self):
53 updater = self.make_updater()
54@@ -80,10 +81,16 @@
55 def test_get_path_hashes(self):
56 updater = self.make_updater()
57 with patch('subprocess.check_output', autospec=True) as cc_mock:
58- result = updater.get_path_hashes()
59+ with patch('update_streams.require_branch',
60+ autospec=True) as rb_mock:
61+ result = updater.get_path_hashes()
62+ env = dict(os.environ)
63+ env['PYTHONPATH'] = 'sstream_dir'
64+ rb_mock.assert_called_once_with('lp:simplestreams', 'sstream_dir')
65 cc_mock.assert_called_once_with([
66- 'sstream-query', 'temp_dir1/streams/v1/index2.json',
67- 'version=version1', '--output-format=%(path)s %(sha256)s'])
68+ 'sstream_dir/bin/sstream-query',
69+ 'temp_dir1/streams/v1/index2.json', 'version=version1',
70+ '--output-format=%(path)s %(sha256)s'], env=env)
71 self.assertIs(cc_mock.return_value, result)
72
73 def test_get_path_hashes_none_version(self):
74
75=== modified file 'tests/test_utility.py'
76--- tests/test_utility.py 2016-02-19 21:43:30 +0000
77+++ tests/test_utility.py 2016-03-01 15:34:50 +0000
78@@ -1,12 +1,16 @@
79 import os
80 from unittest import TestCase
81
82-from mock import patch
83+from mock import (
84+ call,
85+ patch,
86+ )
87
88 from utility import (
89 acquire_log_dir,
90 check_log,
91 get_log_subdir,
92+ require_branch,
93 temp_dir,
94 )
95
96@@ -79,3 +83,26 @@
97 with open(dest_filename) as dest_file:
98 dest_content = dest_file.read()
99 self.assertEqual(tools_content, dest_content)
100+
101+
102+class TestRequireBranch(TestCase):
103+
104+ def test_default(self):
105+ with temp_dir() as destination:
106+ with patch('subprocess.check_call') as cc_mock:
107+ require_branch('lp:source', destination)
108+ cc_mock.assert_called_once_with(
109+ ['bzr', '--no-aliases', 'pull', '--overwrite', '-d', destination,
110+ 'lp:source'])
111+
112+ def test_subdir(self):
113+ with temp_dir() as parent:
114+ grandchild = os.path.join(parent, 'child', 'grandchild')
115+ with patch('subprocess.check_call') as cc_mock:
116+ require_branch('lp:source', grandchild)
117+ self.assertTrue(os.path.isdir(grandchild))
118+ self.assertEqual([
119+ call(['bzr', '--no-aliases', 'init', grandchild]),
120+ call(['bzr', '--no-aliases', 'pull', '--overwrite', '-d',
121+ grandchild, 'lp:source']),
122+ ], cc_mock.mock_calls)
123
124=== modified file 'update_config.py'
125--- update_config.py 2016-02-24 22:11:03 +0000
126+++ update_config.py 2016-03-01 15:34:50 +0000
127@@ -2,6 +2,7 @@
128 from argparse import ArgumentParser
129 from textwrap import dedent
130
131+
132 def update_streams(args):
133 return {
134 'operation': 'update-streams',

Subscribers

People subscribed via source and target branches