Beispiel #1
0
    def test_producer_should_load_all_tasks(self):
        responses.add(responses.GET,
                'https://api.github.com',
                body='something',
                status=200)
        responses.add(responses.GET,
                'https://api.github.com/repos/bigodines/api-health/',
                body='mocked',
                status=200)

        t1 = Task(url="https://api.github.com")
        t2 = Task(url="https://api.github.com/repos/bigodines/api-health/")
        session.add(t1)
        session.add(t2)
        session.commit()

        yield cron.producer()
        self.assertEquals(cron.queue.qsize(), 2)
Beispiel #2
0
    def add_task(self, args):
        """
        Stores a new Task() and returns a TaskForm() to be rendered
        or Raise and exception with the invalid/missing fields
        """
        task = Task()
        # TODO: write a helper in the base class to mimic form.populate_obj()
        # or better yet: make form.populate_obj() work with dicts.
        if 'expected_fields' in args:
            if isinstance(args['expected_fields'], list):
                task.expected_fields = ','.join(str(args['expected_fields']))
            else:
                task.expected_fields = args['expected_fields']
        if 'url' in args:
            task.url = args["url"]
        session.add(task)
        session.commit()

        raise gen.Return(task)