~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/longpoll/tests/test_interfaces.py

  • Committer: Jelmer Vernooij
  • Date: 2011-09-21 14:28:02 UTC
  • mfrom: (14006 devel)
  • mto: This revision was merged to the branch mainline in revision 14010.
  • Revision ID: jelmer@canonical.com-20110921142802-7ggkc204igsy532w
MergeĀ lp:launchpad

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Long-poll interface tests."""
 
5
 
 
6
__metaclass__ = type
 
7
 
 
8
from zope.component import adaptedBy
 
9
from zope.interface import Interface
 
10
 
 
11
from lp.services.longpoll.interfaces import (
 
12
    ILongPollEvent,
 
13
    long_poll_event,
 
14
    )
 
15
from lp.testing import TestCase
 
16
 
 
17
 
 
18
class IEventSourceInterface(Interface):
 
19
    """Test interface for an event source."""
 
20
 
 
21
 
 
22
class IEventSpecifierInterface(Interface):
 
23
    """Test interface for an event specifier."""
 
24
 
 
25
 
 
26
class TestLongPollInterfaces(TestCase):
 
27
 
 
28
    def test_long_poll_event(self):
 
29
        # long_poll_event is a class decorator that declares a class as an
 
30
        # ILongPollEvent.
 
31
        @long_poll_event(IEventSourceInterface, IEventSpecifierInterface)
 
32
        class Something:
 
33
            """An example event source."""
 
34
        self.assertTrue(ILongPollEvent.implementedBy(Something))
 
35
        self.assertEqual(
 
36
            (IEventSourceInterface, IEventSpecifierInterface),
 
37
            adaptedBy(Something))
 
38
 
 
39
    def test_long_poll_event_default(self):
 
40
        # By default, long_poll_event assumes that the event spec is
 
41
        # basestring.
 
42
        @long_poll_event(IEventSourceInterface)
 
43
        class Something:
 
44
            """An example event source."""
 
45
        self.assertTrue(ILongPollEvent.implementedBy(Something))
 
46
        self.assertEqual(
 
47
            (IEventSourceInterface, basestring),
 
48
            adaptedBy(Something))