~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/tests/test_personsubscriptioninfo.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-22 21:02:33 UTC
  • mfrom: (14006.2.5 trivial)
  • Revision ID: launchpad@pqm.canonical.com-20110922210233-j0gidd1az9bh992o
[r=allenap,
        rvb][bug=856048][no-qa] Merge SQLLogger and StormStatementRecorder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from testtools.matchers import LessThan
9
9
from zope.security.proxy import removeSecurityProxy
10
10
 
11
 
from canonical.launchpad.webapp.adapter import SQLLogger
12
11
from canonical.testing import DatabaseFunctionalLayer
13
12
from lp.bugs.interfaces.personsubscriptioninfo import (
14
13
    IRealSubscriptionInfo,
20
19
from lp.registry.interfaces.teammembership import TeamMembershipStatus
21
20
from lp.testing import (
22
21
    person_logged_in,
 
22
    StormStatementRecorder,
23
23
    TestCaseWithFactory,
24
24
    )
25
 
from lp.testing.matchers import Provides
 
25
from lp.testing.matchers import (
 
26
    HasQueryCount,
 
27
    Provides,
 
28
    )
26
29
 
27
30
 
28
31
class TestPersonSubscriptionInfo(TestCaseWithFactory):
509
512
            team.addMember(self.subscriber, team.teamowner,
510
513
                           status=TeamMembershipStatus.ADMIN)
511
514
        self.makeDuplicates(count=1, subscriber=team)
512
 
        logger = SQLLogger()
513
 
        with logger:
 
515
        with StormStatementRecorder() as recorder:
514
516
            self.subscriptions.reload()
515
517
        # This should produce a very small number of queries.
516
 
        count_with_one_subscribed_duplicate = len(logger.queries)
517
 
        self.assertThat(count_with_one_subscribed_duplicate, LessThan(5))
 
518
        self.assertThat(recorder, HasQueryCount(LessThan(5)))
 
519
        count_with_one_subscribed_duplicate = recorder.count
518
520
        # It should have the correct result.
519
521
        self.assertCollectionsAreEmpty(except_='from_duplicate')
520
522
        self.assertCollectionContents(
522
524
        # If we increase the number of duplicates subscribed via the team that
523
525
        # the user administers...
524
526
        self.makeDuplicates(count=4, subscriber=team)
525
 
        with logger:
 
527
        with StormStatementRecorder() as recorder:
526
528
            self.subscriptions.reload()
527
529
        # ...then the query count should remain the same.
528
 
        count_with_five_subscribed_duplicates = len(logger.queries)
 
530
        count_with_five_subscribed_duplicates = recorder.count
529
531
        self.assertEqual(
530
532
            count_with_one_subscribed_duplicate,
531
533
            count_with_five_subscribed_duplicates)