14277.1.3
by Robert Collins
Core model given test coverage, leaner execution and date ranges. |
1 |
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
|
8687.15.18
by Karl Fogel
Add the copyright header block to files under lib/canonical/. |
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
3691.173.2
by Stuart Bishop
Add tests for oops pruner |
3 |
|
14277.1.3
by Robert Collins
Core model given test coverage, leaner execution and date ranges. |
4 |
"""Tests of the oopsreferences core."""
|
3691.173.2
by Stuart Bishop
Add tests for oops pruner |
5 |
|
6 |
__metaclass__ = type |
|
7 |
||
14277.1.3
by Robert Collins
Core model given test coverage, leaner execution and date ranges. |
8 |
from datetime import ( |
9 |
datetime, |
|
10 |
timedelta, |
|
11 |
)
|
|
12 |
||
13 |
from pytz import utc |
|
14 |
||
14612.2.1
by William Grant
format-imports on lib/. So many imports. |
15 |
from lp.registry.model.oopsreferences import referenced_oops |
14560.2.29
by Curtis Hovey
Restored lpstorm module name because it lp engineers know that name. |
16 |
from lp.services.database.lpstorm import IStore |
14277.1.3
by Robert Collins
Core model given test coverage, leaner execution and date ranges. |
17 |
from lp.services.messages.model.message import ( |
18 |
Message, |
|
19 |
MessageSet, |
|
20 |
)
|
|
14550.1.1
by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad |
21 |
from lp.testing import ( |
22 |
person_logged_in, |
|
23 |
TestCaseWithFactory, |
|
24 |
)
|
|
14612.2.1
by William Grant
format-imports on lib/. So many imports. |
25 |
from lp.testing.layers import DatabaseFunctionalLayer |
14277.1.3
by Robert Collins
Core model given test coverage, leaner execution and date ranges. |
26 |
|
27 |
||
28 |
class TestOopsReferences(TestCaseWithFactory): |
|
29 |
||
30 |
layer = DatabaseFunctionalLayer |
|
3691.173.2
by Stuart Bishop
Add tests for oops pruner |
31 |
|
32 |
def setUp(self): |
|
14277.1.3
by Robert Collins
Core model given test coverage, leaner execution and date ranges. |
33 |
super(TestOopsReferences, self).setUp() |
34 |
self.store = IStore(Message) |
|
35 |
||
36 |
def test_oops_in_messagechunk(self): |
|
37 |
oopsid = "OOPS-abcdef1234" |
|
38 |
MessageSet().fromText('foo', "foo %s bar" % oopsid) |
|
39 |
self.store.flush() |
|
40 |
now = datetime.now(tz=utc) |
|
41 |
day = timedelta(days=1) |
|
42 |
self.failUnlessEqual( |
|
43 |
set([oopsid.upper()]), |
|
44 |
referenced_oops(now - day, now, "product=1", {})) |
|
45 |
self.failUnlessEqual( |
|
46 |
set(), |
|
47 |
referenced_oops(now + day, now + day, "product=1", {})) |
|
48 |
||
49 |
def test_oops_in_messagesubject(self): |
|
50 |
oopsid = "OOPS-abcdef1234" |
|
51 |
self.factory.makeEmailMessage() |
|
52 |
MessageSet().fromText("Crash with %s" % oopsid, "body") |
|
53 |
self.store.flush() |
|
54 |
now = datetime.now(tz=utc) |
|
55 |
day = timedelta(days=1) |
|
56 |
self.failUnlessEqual( |
|
57 |
set([oopsid.upper()]), |
|
58 |
referenced_oops(now - day, now, "product=1", {})) |
|
59 |
self.failUnlessEqual( |
|
60 |
set(), |
|
61 |
referenced_oops(now + day, now + day, "product=1", {})) |
|
62 |
||
63 |
def test_oops_in_bug_title(self): |
|
64 |
oopsid = "OOPS-abcdef1234" |
|
65 |
bug = self.factory.makeBug() |
|
66 |
with person_logged_in(bug.owner): |
|
67 |
bug.title = "Crash with %s" % oopsid |
|
68 |
self.store.flush() |
|
69 |
now = datetime.now(tz=utc) |
|
70 |
day = timedelta(days=1) |
|
71 |
self.failUnlessEqual( |
|
72 |
set([oopsid.upper()]), |
|
73 |
referenced_oops(now - day, now, "product=1", {})) |
|
74 |
self.failUnlessEqual( |
|
75 |
set(), |
|
76 |
referenced_oops(now + day, now + day, "product=1", {})) |
|
77 |
||
78 |
def test_oops_in_bug_description(self): |
|
79 |
oopsid = "OOPS-abcdef1234" |
|
80 |
bug = self.factory.makeBug() |
|
81 |
with person_logged_in(bug.owner): |
|
82 |
bug.description = "Crash with %s" % oopsid |
|
83 |
self.store.flush() |
|
84 |
now = datetime.now(tz=utc) |
|
85 |
day = timedelta(days=1) |
|
86 |
self.failUnlessEqual( |
|
87 |
set([oopsid.upper()]), |
|
88 |
referenced_oops(now - day, now, "product=1", {})) |
|
89 |
self.failUnlessEqual( |
|
90 |
set(), |
|
91 |
referenced_oops(now + day, now + day, "product=1", {})) |
|
92 |
||
93 |
def test_oops_in_question_title(self): |
|
94 |
oopsid = "OOPS-abcdef1234" |
|
95 |
question = self.factory.makeQuestion(title="Crash with %s" % oopsid) |
|
96 |
self.store.flush() |
|
97 |
now = datetime.now(tz=utc) |
|
98 |
day = timedelta(days=1) |
|
99 |
self.failUnlessEqual( |
|
100 |
set([oopsid.upper()]), |
|
101 |
referenced_oops(now - day, now, "product=%(product)s", |
|
102 |
{'product': question.product.id})) |
|
103 |
self.failUnlessEqual( |
|
104 |
set([]), |
|
105 |
referenced_oops(now + day, now + day, "product=%(product)s", |
|
106 |
{'product': question.product.id})) |
|
107 |
||
108 |
def test_oops_in_question_wrong_context(self): |
|
109 |
oopsid = "OOPS-abcdef1234" |
|
110 |
question = self.factory.makeQuestion(title="Crash with %s" % oopsid) |
|
111 |
self.store.flush() |
|
112 |
now = datetime.now(tz=utc) |
|
113 |
day = timedelta(days=1) |
|
114 |
self.store.flush() |
|
115 |
self.failUnlessEqual( |
|
116 |
set(), |
|
117 |
referenced_oops(now - day, now, "product=%(product)s", |
|
118 |
{'product': question.product.id + 1})) |
|
119 |
||
120 |
def test_oops_in_question_description(self): |
|
121 |
oopsid = "OOPS-abcdef1234" |
|
122 |
question = self.factory.makeQuestion( |
|
123 |
description="Crash with %s" % oopsid) |
|
124 |
self.store.flush() |
|
125 |
now = datetime.now(tz=utc) |
|
126 |
day = timedelta(days=1) |
|
127 |
self.failUnlessEqual( |
|
128 |
set([oopsid.upper()]), |
|
129 |
referenced_oops(now - day, now, "product=%(product)s", |
|
130 |
{'product': question.product.id})) |
|
131 |
self.failUnlessEqual( |
|
132 |
set([]), |
|
133 |
referenced_oops(now + day, now + day, "product=%(product)s", |
|
134 |
{'product': question.product.id})) |
|
135 |
||
136 |
def test_oops_in_question_whiteboard(self): |
|
137 |
oopsid = "OOPS-abcdef1234" |
|
138 |
question = self.factory.makeQuestion() |
|
139 |
with person_logged_in(question.owner): |
|
140 |
question.whiteboard = "Crash with %s" % oopsid |
|
141 |
self.store.flush() |
|
142 |
now = datetime.now(tz=utc) |
|
143 |
day = timedelta(days=1) |
|
144 |
self.failUnlessEqual( |
|
145 |
set([oopsid.upper()]), |
|
146 |
referenced_oops(now - day, now, "product=%(product)s", |
|
147 |
{'product': question.product.id})) |
|
148 |
self.failUnlessEqual( |
|
149 |
set([]), |
|
150 |
referenced_oops(now + day, now + day, "product=%(product)s", |
|
151 |
{'product': question.product.id})) |
|
152 |
||
153 |
def test_oops_in_question_distribution(self): |
|
154 |
oopsid = "OOPS-abcdef1234" |
|
155 |
distro = self.factory.makeDistribution() |
|
156 |
question = self.factory.makeQuestion(target=distro) |
|
157 |
with person_logged_in(question.owner): |
|
158 |
question.whiteboard = "Crash with %s" % oopsid |
|
159 |
self.store.flush() |
|
160 |
now = datetime.now(tz=utc) |
|
161 |
day = timedelta(days=1) |
|
162 |
self.failUnlessEqual( |
|
163 |
set([oopsid.upper()]), |
|
164 |
referenced_oops(now - day, now, "distribution=%(distribution)s", |
|
165 |
{'distribution': distro.id})) |
|
166 |
self.failUnlessEqual( |
|
167 |
set([]), |
|
168 |
referenced_oops(now + day, now + day, |
|
169 |
"distribution=%(distribution)s", {'distribution': distro.id})) |
|
170 |
||
171 |
def test_referenced_oops_in_urls_bug_663249(self): |
|
172 |
# Sometimes OOPS ids appears as part of an URL. These should could as
|
|
173 |
# a reference even though they are not formatted specially - this
|
|
174 |
# requires somewhat special handling in the reference calculation
|
|
175 |
# function.
|
|
176 |
oopsid = "OOPS-abcdef1234" |
|
177 |
bug = self.factory.makeBug() |
|
178 |
with person_logged_in(bug.owner): |
|
179 |
bug.description = ( |
|
180 |
"foo https://lp-oops.canonical.com/oops.py?oopsid=%s bar" |
|
181 |
% oopsid) |
|
182 |
self.store.flush() |
|
183 |
now = datetime.now(tz=utc) |
|
184 |
day = timedelta(days=1) |
|
185 |
self.failUnlessEqual( |
|
186 |
set([oopsid.upper()]), |
|
187 |
referenced_oops(now - day, now, "product=1", {})) |
|
188 |
self.failUnlessEqual( |
|
189 |
set([]), |
|
190 |
referenced_oops(now + day, now + day, "product=1", {})) |