Пример #1
0
    def handle(self, **options):
        options = dict_from_values(options)
        paginator_kwargs = dict((key, options[key]) for key in
                filter(options.has_key, ('total_pages', 'start_page',
                    'interactive','silent_fail')))
        consumer_kwargs = dict((key, options[key]) for key in filter(options.has_key, ('mock_api', 'trust')))
        client_kwargs = dict((key, options[key]) for key in filter(options.has_key, ('make_dumps',)))

        # mux up settings with overrides
        query_kwargs = dict((key, options[key]) for key in filter(options.has_key, ('page_size',)))
        mux_query_kwargs = dict(conf.IMPORT_PARAMETERS, **query_kwargs)

        # do work
#        try:
        paginator = EventfulPaginator(client_kwargs=client_kwargs,
                query_kwargs=mux_query_kwargs, consumer_kwargs=consumer_kwargs, **paginator_kwargs)
        results = paginator.import_events()

        # FIXME should prolly happen automagically elsewhere
        for e in Event.objects.filter(id__in=[event_id for created, event_id in results]):
            e.save()

        #        except Exception, e:
        #            raise CommandError(e)
        #        else:
        created_events_count = reduce(lambda count, result: count + int(result[0]), results, 0)
        self.stdout.write('Successfully imported eventful API results: %i total | %i created.\n' % (
            len(results), created_events_count)
        )
Пример #2
0
    def handle(self, **options):
        options = dict_from_values(options)
        paginator_kwargs = dict(
            (key, options[key])
            for key in filter(options.has_key, ('total_pages', 'start_page',
                                                'interactive', 'silent_fail')))
        consumer_kwargs = dict(
            (key, options[key])
            for key in filter(options.has_key, ('mock_api', 'trust')))
        client_kwargs = dict(
            (key, options[key])
            for key in filter(options.has_key, ('make_dumps', )))

        # mux up settings with overrides
        query_kwargs = dict(
            (key, options[key])
            for key in filter(options.has_key, ('page_size', )))
        mux_query_kwargs = dict(conf.IMPORT_PARAMETERS, **query_kwargs)

        # do work
        #        try:
        paginator = EventfulPaginator(client_kwargs=client_kwargs,
                                      query_kwargs=mux_query_kwargs,
                                      consumer_kwargs=consumer_kwargs,
                                      **paginator_kwargs)
        results = paginator.import_events()

        # FIXME should prolly happen automagically elsewhere
        for e in Event.objects.filter(
                id__in=[event_id for created, event_id in results]):
            e.save()

        #        except Exception, e:
        #            raise CommandError(e)
        #        else:
        created_events_count = reduce(
            lambda count, result: count + int(result[0]), results, 0)
        self.stdout.write(
            'Successfully imported eventful API results: %i total | %i created.\n'
            % (len(results), created_events_count))
Пример #3
0
class EventfulPaginatorTest(ImporterTestCase):
    fixtures = ['categories', 'sources', 'external_categories', 'users']

    @classmethod
    def setUpClass(cls):
        super(EventfulPaginatorTest, cls).setUpClass()
        User.objects.create(username='******')
        cls.args = dict(interactive=False, total_pages=1, start_page=1,
            silent_fail=False, consumer_kwargs={'trust': False, 'mock_api': True},
            client_kwargs={'make_dumps': False},
            query_kwargs={'query': '', 'sort_order': 'popularity', 'location': 'NYC', 'page_size': 1}
        )

    def test_silent_fail_off(self):
        with self.assertRaises(ValueError):
            self.paginator = EventfulPaginator(**self.args)
            self.paginator._import_page_events([self.invalid_response],
                self.args['interactive'], self.args['silent_fail'])

    def test_silent_fail_on(self):
        self.args['silent_fail'] = True
        self.paginator = EventfulPaginator(**self.args)
        self.paginator._import_page_events([self.invalid_response],
            self.args['interactive'], self.args['silent_fail'])
Пример #4
0
 def test_silent_fail_on(self):
     self.args['silent_fail'] = True
     self.paginator = EventfulPaginator(**self.args)
     self.paginator._import_page_events([self.invalid_response],
         self.args['interactive'], self.args['silent_fail'])
Пример #5
0
 def test_silent_fail_off(self):
     with self.assertRaises(ValueError):
         self.paginator = EventfulPaginator(**self.args)
         self.paginator._import_page_events([self.invalid_response],
             self.args['interactive'], self.args['silent_fail'])