class ConsumerContentInstallScheduleStrategyTests(rpm_support_base.PulpClientTests):

    def setUp(self):
        super(ConsumerContentInstallScheduleStrategyTests, self).setUp()
        self.strategy = YumConsumerContentScheduleStrategy(self.context, 'install', TYPE_ID_RPM)

    @mock.patch('pulp.bindings.consumer.ConsumerContentSchedulesAPI.add_schedule')
    def test_create_schedule(self, mock_add):
        # Setup
        schedule = '2012-09-18'
        failure_threshold = 3
        enabled = True
        kwargs = {OPTION_CONSUMER_ID.keyword : 'test-consumer',
                  'name': ['pkg1','pkg2']}

        # Test
        self.strategy.create_schedule(schedule, failure_threshold, enabled, kwargs)

        # Verify
        self.assertEqual(1, mock_add.call_count)
        call_args = mock_add.call_args[0]
        self.assertEqual('install', call_args[0])
        self.assertEqual('test-consumer', call_args[1])
        self.assertEqual(schedule, call_args[2])
        self.assertEqual(failure_threshold, call_args[4])
        self.assertEqual(enabled, call_args[5])
        self.assertEqual({}, call_args[6])

    @mock.patch('pulp.bindings.consumer.ConsumerContentSchedulesAPI.delete_schedule')
    def test_delete_schedule(self, mock_delete):
        # Setup
        schedule_id = 'fake-schedule'
        kwargs = {OPTION_CONSUMER_ID.keyword : 'fake-consumer'}

        # Test
        self.strategy.delete_schedule(schedule_id, kwargs)

        # Verify
        self.assertEqual(1, mock_delete.call_count)
        call_args = mock_delete.call_args[0]
        self.assertEqual('install', call_args[0])
        self.assertEqual('fake-consumer', call_args[1])
        self.assertEqual(schedule_id, call_args[2])

    @mock.patch('pulp.bindings.consumer.ConsumerContentSchedulesAPI.list_schedules')
    def test_retrieve_schedules(self, mock_retrieve):
        # Setup
        kwargs = {OPTION_CONSUMER_ID.keyword : 'retrieve-consumer'}

        # Test
        self.strategy.retrieve_schedules(kwargs)

        # Verify
        self.assertEqual(1, mock_retrieve.call_count)
        call_args = mock_retrieve.call_args[0]
        self.assertEqual('install', call_args[0])
        self.assertEqual('retrieve-consumer', call_args[1])

    @mock.patch('pulp.bindings.consumer.ConsumerContentSchedulesAPI.update_schedule')
    def test_update_schedule(self, mock_update):
        # Setup
        kwargs = {OPTION_CONSUMER_ID.keyword : 'fake-consumer', 'a' : 'a'}
        schedule_id = 'schedule-id'

        # Test
        self.strategy.update_schedule(schedule_id, **kwargs)

        # Verify
        self.assertEqual(1, mock_update.call_count)
        call_args = mock_update.call_args[0]
        self.assertEqual('install', call_args[0])
        self.assertEqual('fake-consumer', call_args[1])
        self.assertEqual(schedule_id, call_args[2])
        call_kwargs = mock_update.call_args[1]
        self.assertEqual({'a' : 'a'}, call_kwargs)
 def setUp(self):
     super(ConsumerContentInstallScheduleStrategyTests, self).setUp()
     self.strategy = YumConsumerContentScheduleStrategy(self.context, 'install', TYPE_ID_RPM)
 def setUp(self):
     super(ConsumerContentUpdateScheduleStrategyTests, self).setUp()
     self.strategy = YumConsumerContentScheduleStrategy(self.context, 'update', TYPE_ID_RPM)