11078.2.2
by Curtis Hovey
Refactored milestone cache tests. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
__metaclass__ = type |
|
5 |
||
11666.3.5
by Curtis Hovey
Import layers from canonical.testing.layers. |
6 |
from canonical.testing.layers import LaunchpadFunctionalLayer |
11078.2.2
by Curtis Hovey
Refactored milestone cache tests. |
7 |
from lp.testing import TestCaseWithFactory |
8 |
||
9 |
||
10 |
class MemcacheTestCase(TestCaseWithFactory): |
|
11 |
||
12 |
layer = LaunchpadFunctionalLayer |
|
13 |
||
14 |
def assertCacheMiss(self, fragment, content): |
|
11078.2.3
by Curtis Hovey
Fixed grammar. |
15 |
# Verify that fragment is not cached in the content.
|
11078.2.2
by Curtis Hovey
Refactored milestone cache tests. |
16 |
self.assertTrue(fragment in content) |
17 |
before, after = content.split(fragment, 1) |
|
18 |
cache_start = '<!-- Cache hit: memcache expression' |
|
19 |
if cache_start in before: |
|
11078.2.3
by Curtis Hovey
Fixed grammar. |
20 |
# Verify that the preceding cache is not for this fragment
|
11078.2.2
by Curtis Hovey
Refactored milestone cache tests. |
21 |
cache_end = '<!-- End cache hit' |
22 |
self.assertTrue(cache_end in before) |
|
11078.2.3
by Curtis Hovey
Fixed grammar. |
23 |
ignore, start = before.rsplit(cache_end, 1) |
11078.2.2
by Curtis Hovey
Refactored milestone cache tests. |
24 |
self.assertTrue(cache_start not in start) |
25 |
||
26 |
def assertCacheHit(self, fragment, expression, content): |
|
11078.2.3
by Curtis Hovey
Fixed grammar. |
27 |
# Verify that fragment is cached by the specific expression in
|
11078.2.2
by Curtis Hovey
Refactored milestone cache tests. |
28 |
# the content.
|
29 |
self.assertTrue(fragment in content) |
|
30 |
before, after = content.split(fragment, 1) |
|
31 |
cache_start = ( |
|
32 |
'<!-- Cache hit: memcache expression (%s) ' % expression) |
|
33 |
self.assertTrue(cache_start in before) |
|
11078.2.3
by Curtis Hovey
Fixed grammar. |
34 |
ignore, start = before.rsplit(cache_start, 1) |
11078.2.2
by Curtis Hovey
Refactored milestone cache tests. |
35 |
self.assertTrue('<!-- End cache hit' not in start) |