def setUp(self): self.access_key_id = 'xxxxxxxx' self.secret_access_key = 'xxxx' self.instance_ids = ['i-1111', 'i-2222'] self.out = StringIO() self.patcher = patch('ec2alternate.instances.' \ 'InstanceManager._get_instances') self.mock_method = self.patcher.start() self.mock_method.return_value = get_instances_mock(self.instance_ids)
def test_cmd_now(self): self.out = StringIO() argv = self._get_argv('now') main(argv=argv, out=self.out) output_lines = self.out.getvalue().splitlines() self.assertTrue(output_lines[0].startswith( 'Instance:i-1111 (name-i-1111) running')) self.assertTrue(output_lines[1].startswith( 'Instance:i-2222 (name-i-2222) running')) instance_ids = self.mock_method.call_args[0][0] self.mock_method.return_value = get_instances_mock(instance_ids) self.out = StringIO() argv = self._get_argv('now') main(argv=argv, out=self.out) output_lines = self.out.getvalue().splitlines() self.assertTrue(output_lines[0].startswith( 'Instance:i-2222 (name-i-2222) running')) self.assertTrue(output_lines[1].startswith( 'Instance:i-1111 (name-i-1111) running'))