~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maastesting/tests/test_celery.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Test matchers."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
__metaclass__ = type
 
13
__all__ = []
 
14
 
 
15
import random
 
16
 
 
17
from celery import current_app
 
18
from celery.decorators import task
 
19
from celery.result import EagerResult
 
20
from maastesting.celery import CeleryFixture
 
21
from maastesting.testcase import TestCase
 
22
 
 
23
 
 
24
@task()
 
25
def task_add(x, y):
 
26
    return x + y
 
27
 
 
28
 
 
29
@task()
 
30
def task_exception(x, y):
 
31
    raise RuntimeError()
 
32
 
 
33
 
 
34
class TestCeleryFixture(TestCase):
 
35
    """Tests `CeleryFixture`."""
 
36
 
 
37
    def setUp(self):
 
38
        super(TestCeleryFixture, self).setUp()
 
39
        self.celery = self.useFixture(CeleryFixture())
 
40
 
 
41
    def test_celery_config(self):
 
42
        self.assertTrue(current_app.conf.CELERY_ALWAYS_EAGER)
 
43
        self.assertTrue(current_app.conf.CELERY_EAGER_PROPAGATES_EXCEPTIONS)
 
44
 
 
45
    def test_celery_eagerresult_contains_result(self):
 
46
        # The result is an instance of EagerResult and it contains the actual
 
47
        # result.
 
48
        x = random.randrange(100)
 
49
        y = random.randrange(100)
 
50
        result = task_add.delay(x, y)
 
51
        self.assertIsInstance(result, EagerResult)
 
52
        self.assertEqual(x + y, result.result)
 
53
 
 
54
    def test_celery_exception_raised(self):
 
55
        self.assertRaises(RuntimeError, task_exception.delay, 1, 2)
 
56
 
 
57
    def test_celery_records_tasks(self):
 
58
        x = random.randrange(100)
 
59
        y = random.randrange(100)
 
60
        task_add.delay(x=x, y=y)
 
61
        z = random.randrange(100)
 
62
        t = random.randrange(100)
 
63
        task_add.delay(x=z, y=t)
 
64
        tasks = self.celery.tasks
 
65
        self.assertEqual(2, len(tasks))
 
66
        self.assertEqual(
 
67
            ['maastesting.tests.test_celery.task_add'] * 2,
 
68
            [task['task'].name for task in tasks])
 
69
        self.assertEqual({'x': x, 'y': y}, tasks[0]['kwargs'])
 
70
        self.assertEqual({'x': z, 'y': t}, tasks[1]['kwargs'])