def test_list(self):
        # Setup
        strategy = mock.Mock()
        strategy.retrieve_schedules.return_value = Response(
            200, copy.deepcopy(EXAMPLE_SCHEDULE_LIST))

        list_command = commands.ListScheduleCommand(self.context, strategy,
                                                    'list', 'list')
        list_command.create_option('--extra', 'extra')
        self.cli.add_command(list_command)

        # Test
        self.cli.run('list --extra foo'.split())

        # Verify
        self.assertEqual(strategy.retrieve_schedules.call_count, 1)
        self.assertEqual(strategy.retrieve_schedules.call_args[0][0]['extra'],
                         'foo')

        # Spot check the ID lines in the displayed list
        id_lines = [l for l in self.recorder.lines if l.startswith('Id')]
        self.assertEqual(3, len(id_lines))

        ids = [l.split()[1] for l in id_lines]
        self.assertTrue(EXAMPLE_SCHEDULE_LIST[0]['_id'] in ids)
        self.assertTrue(EXAMPLE_SCHEDULE_LIST[1]['_id'] in ids)
        self.assertTrue(EXAMPLE_SCHEDULE_LIST[2]['_id'] in ids)
    def test_list_details(self):
        # Setup
        strategy = mock.Mock()
        strategy.retrieve_schedules.return_value = Response(
            200, copy.deepcopy(EXAMPLE_SCHEDULE_LIST))

        list_command = commands.ListScheduleCommand(self.context, strategy,
                                                    'list', 'list')
        self.cli.add_command(list_command)

        # Test
        self.cli.run('list --details'.split())

        # Verify
        self.assertEqual(strategy.retrieve_schedules.call_count, 1)

        # Spot check the ID lines in the displayed list
        fr_lines = [
            l for l in self.recorder.lines if l.startswith('First Run')
        ]
        self.assertEqual(3, len(fr_lines))

        first_runs = [l.split()[2] for l in fr_lines]
        self.assertTrue(EXAMPLE_SCHEDULE_LIST[0]['first_run'] in first_runs)
        self.assertTrue(EXAMPLE_SCHEDULE_LIST[1]['first_run'] in first_runs)
        self.assertTrue(EXAMPLE_SCHEDULE_LIST[2]['first_run'] in first_runs)