Factor out generic call to main
This commit is contained in:
@@ -31,6 +31,14 @@ class TestCollect(testtools.TestCase):
|
|||||||
super(TestCollect, self).tearDown()
|
super(TestCollect, self).tearDown()
|
||||||
cfg.CONF.reset()
|
cfg.CONF.reset()
|
||||||
|
|
||||||
|
def _call_main(self, fake_args):
|
||||||
|
self.useFixture(
|
||||||
|
fixtures.MonkeyPatch('sys.argv', fake_args))
|
||||||
|
|
||||||
|
requests_impl_map = {'ec2': test_ec2.FakeRequests,
|
||||||
|
'cfn': test_cfn.FakeRequests(self)}
|
||||||
|
collect.__main__(requests_impl_map=requests_impl_map)
|
||||||
|
|
||||||
def test_main(self):
|
def test_main(self):
|
||||||
expected_cmd = self.getUniqueString()
|
expected_cmd = self.getUniqueString()
|
||||||
cache_dir = self.useFixture(fixtures.TempDir())
|
cache_dir = self.useFixture(fixtures.TempDir())
|
||||||
@@ -49,8 +57,6 @@ class TestCollect(testtools.TestCase):
|
|||||||
'--cfn-path',
|
'--cfn-path',
|
||||||
'foo.Metadata'
|
'foo.Metadata'
|
||||||
]
|
]
|
||||||
self.useFixture(
|
|
||||||
fixtures.MonkeyPatch('sys.argv', fake_args))
|
|
||||||
self.called_fake_call = False
|
self.called_fake_call = False
|
||||||
|
|
||||||
def fake_call(args, env, shell):
|
def fake_call(args, env, shell):
|
||||||
@@ -73,9 +79,7 @@ class TestCollect(testtools.TestCase):
|
|||||||
|
|
||||||
self.useFixture(fixtures.MonkeyPatch('subprocess.call', fake_call))
|
self.useFixture(fixtures.MonkeyPatch('subprocess.call', fake_call))
|
||||||
|
|
||||||
requests_impl_map = {'ec2': test_ec2.FakeRequests,
|
self._call_main(fake_args)
|
||||||
'cfn': test_cfn.FakeRequests(self)}
|
|
||||||
collect.__main__(requests_impl_map=requests_impl_map)
|
|
||||||
|
|
||||||
self.assertTrue(self.called_fake_call)
|
self.assertTrue(self.called_fake_call)
|
||||||
|
|
||||||
@@ -91,14 +95,10 @@ class TestCollect(testtools.TestCase):
|
|||||||
'--cfn-path',
|
'--cfn-path',
|
||||||
'foo.Metadata'
|
'foo.Metadata'
|
||||||
]
|
]
|
||||||
self.useFixture(
|
|
||||||
fixtures.MonkeyPatch('sys.argv', fake_args))
|
|
||||||
output = self.useFixture(fixtures.ByteStream('stdout'))
|
output = self.useFixture(fixtures.ByteStream('stdout'))
|
||||||
self.useFixture(
|
self.useFixture(
|
||||||
fixtures.MonkeyPatch('sys.stdout', output.stream))
|
fixtures.MonkeyPatch('sys.stdout', output.stream))
|
||||||
requests_impl_map = {'ec2': test_ec2.FakeRequests,
|
self._call_main(fake_args)
|
||||||
'cfn': test_cfn.FakeRequests(self)}
|
|
||||||
collect.__main__(requests_impl_map=requests_impl_map)
|
|
||||||
out_struct = json.loads(output.stream.getvalue())
|
out_struct = json.loads(output.stream.getvalue())
|
||||||
self.assertThat(out_struct, matchers.IsInstance(dict))
|
self.assertThat(out_struct, matchers.IsInstance(dict))
|
||||||
self.assertIn('ec2', out_struct)
|
self.assertIn('ec2', out_struct)
|
||||||
|
|||||||
Reference in New Issue
Block a user