def test_next_run_no_schedules(self):
        # Setup
        strategy = mock.Mock()
        strategy.retrieve_schedules.return_value = Response(200, {})

        next_command = commands.NextRunCommand(self.context, strategy, 'next',
                                               'next')
        self.cli.add_command(next_command)

        # Test
        self.cli.run('next'.split())

        # Verify
        self.assertTrue('no schedules' in self.recorder.lines[0])
    def test_next_run_quiet(self):
        # Setup
        strategy = mock.Mock()
        strategy.retrieve_schedules.return_value = Response(
            200, copy.copy(EXAMPLE_SCHEDULE_LIST))

        next_command = commands.NextRunCommand(self.context, strategy, 'next',
                                               'next')
        self.cli.add_command(next_command)

        # Test
        self.cli.run('next --quiet'.split())

        # Verify
        self.assertEqual(1, len(self.prompt.get_write_tags()))
        self.assertEqual(TAG_PARAGRAPH, self.prompt.get_write_tags()[0])
        self.assertEqual('2012-05-22T00:00:00Z\n', self.recorder.lines[0])
    def test_next_run(self):
        # Setup
        strategy = mock.Mock()
        strategy.retrieve_schedules.return_value = Response(
            200, copy.copy(EXAMPLE_SCHEDULE_LIST))

        next_command = commands.NextRunCommand(self.context, strategy, 'next',
                                               'next')
        next_command.create_option('--extra', 'extra')
        self.cli.add_command(next_command)

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

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

        self.assertEqual(1, len(self.prompt.get_write_tags()))
        self.assertEqual(TAG_PARAGRAPH, self.prompt.get_write_tags()[0])
        self.assertTrue('2012-05-22T00:00:00Z' in self.recorder.lines[0])
        self.assertTrue('2012-05-15T00:00:00Z/P1W' in self.recorder.lines[0])