collective / collective.taskqueue

Asyncore-based asynchronous task queue for Plone
https://pypi.org/project/collective.taskqueue
8 stars 7 forks source link

How to integrate c.taskqueue on your own tests? #16

Closed gforcada closed 8 years ago

gforcada commented 8 years ago

I'm having a hard time trying to make some tests to check that my code queues tasks with collective.taskqueue.

Looking at test_acceptance.py I thought that something like this would be enough:

from collective.taskqueue.testing import TASK_QUEUE_ZSERVER_FIXTURE
from collective.taskqueue.testing import ZSERVER_FIXTURE

...

MY_ASYNC_TESTING = z2.FunctionalTesting(
    bases=(
        TASK_QUEUE_ZSERVER_FIXTURE,
        MY_SPECIFIC_PLONE_FIXTURE,
        ZSERVER_FIXTURE,
    ),
    name='DerFreitagAsyncLayer:Functional'
)

But then something like this already fails with a KeyError: 'portal':

class TestAsyncView(unittest.TestCase):
    layer = MY_ASYNC_TESTING

    def setUp(self):
        self.portal = self.layer['portal']

I'm missing something obvious?

datakurre commented 8 years ago

I'm not sure. Do you still have the issue? I'm not yet managed to see that myself with similar config.

self.layer['portal'] should be se by Plone sandbox layer. Does running the test still trigger setups from your test fixture?

Quoting Gil Forcada Codinachs (2016-01-14 13:27:14)

I'm having a hard time trying to make some tests to check that my code queues tasks with collective.taskqueue.

Looking at test_acceptance.py I thought that something like this would be enough:

from collective.taskqueue.testing import TASK_QUEUE_ZSERVER_FIXTURE from collective.taskqueue.testing import ZSERVER_FIXTURE

...

MY_ASYNC_TESTING = z2.FunctionalTesting( bases=( TASK_QUEUE_ZSERVER_FIXTURE, MY_SPECIFIC_PLONE_FIXTURE, ZSERVER_FIXTURE, ), name='DerFreitagAsyncLayer:Functional' )

But then something like this already fails with a KeyError: 'portal':

class TestAsyncView(unittest.TestCase): layer = MY_ASYNC_TESTING

def setUp(self):
    self.portal = self.layer['portal']

I'm missing something obvious?

— Reply to this email directly or view it on GitHub.*

gforcada commented 8 years ago

@datakurre I will give it a try right now. Thanks!

gforcada commented 8 years ago

@datakurre they are called but the same happens, no portal on the layer.

I tried using collective.taskqueue.tests.test_acceptance.TASK_QUEUE_ROBOT_TESTING as the layer but the same still happens as well :-/

datakurre commented 8 years ago

Strange. I'm currently working with similar layers (Plone 4.3.x):

... = IntegrationTesting( bases=( TASK_QUEUE_FIXTURE, MY_PLONE_FIXTURE ), name='...:IntegrationTesting' )

... = FunctionalTesting( bases=( TASK_QUEUE_FIXTURE, MY_PLONE_FIXTURE ), name='...:FunctionalTesting' )

... = FunctionalTesting( bases=( TASK_QUEUE_ZSERVER_FIXTURE, MY_PLONE_FIXTURE REMOTE_LIBRARY_BUNDLE_FIXTURE, z2.ZSERVER_FIXTURE ), name='...:AcceptanceTesting' )

With all them, I do have self.layer['portal'] as expected.

Quoting Gil Forcada Codinachs (2016-01-14 15:15:00)

@datakurre they are called but the same happens, no portal on the layer.

I tried using collective.taskqueue.tests.test_acceptance.TASK_QUEUE_ROBOT_TESTING as the layer but the same still happens as well :-/

— Reply to this email directly or view it on GitHub.*

gforcada commented 8 years ago

Ok, I'm also using 4.3.x... then it has to be something on my layers... I will dig a bit more.

gforcada commented 8 years ago

Solved!

The demon is always on the details: I was using

MY_ASYNC_TESTING = z2.FunctionalTesting(
    bases=(
        TASK_QUEUE_ZSERVER_FIXTURE,
        MY_SPECIFIC_PLONE_FIXTURE,
        ZSERVER_FIXTURE,
    ),
    name='...:Functional'
)

And now I'm using:

MY_ASYNC_TESTING = FunctionalTesting(
    bases=(
        TASK_QUEUE_FIXTURE,
        MY_SPECIFIC_PLONE_FIXTURE,
    ),
    name='...:Functional'
)

So z2.FunctionalTesting to FunctionalTesting, TASK_QUEUE_ZSERVER_FIXTURE to TASK_QUEUE_FIXTURE and remove the ZSERVER_FIXTURE.

Thanks for all the help!

datakurre commented 8 years ago

Great that it works. Altough, I still don't understand the issue. Fixtures without ZSERVER do not really handle tasks, but only log them and designed for integration tests. The ZSERVER -combo should be the correct one for true functional tests and robot tests :/

Quoting Gil Forcada Codinachs (2016-01-15 11:54:33)

Solved!

The demon is always on the details: I was using

MY_ASYNC_TESTING = z2.FunctionalTesting( bases=( TASK_QUEUE_ZSERVER_FIXTURE, MY_SPECIFIC_PLONE_FIXTURE, ZSERVER_FIXTURE, ), name='...:Functional' )

And now I'm using:

MY_ASYNC_TESTING = FunctionalTesting( bases=( TASK_QUEUE_FIXTURE, MY_SPECIFIC_PLONE_FIXTURE, ), name='...:Functional' )

So z2.FunctionalTesting to FunctionalTesting, TASK_QUEUE_ZSERVER_FIXTURE to TASK_QUEUE_FIXTURE and remove the ZSERVER_FIXTURE.

Thanks for all the help!

— Reply to this email directly or view it on GitHub.*