1
# Copyright 2005-2012 Canonical Ltd. All rights reserved.
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
from datetime import datetime
17
from operator import attrgetter
19
from oopstools.oops.models import (
27
from oopstools.oops.test.testcase import TestCase
30
class ReportTests(TestCase):
32
def test_no_report(self):
33
resp = self.client.get('/reports/some-report/')
34
self.assertEqual(404, resp.status_code)
36
def test_inactive_report(self):
37
report_name = 'areport'
38
Report.objects.create(name=report_name, active=False)
39
resp = self.client.get('/reports/%s/' % (report_name,))
40
self.assertEqual(404, resp.status_code)
42
def test_no_recent_oopses(self):
43
report_name = 'areport'
44
Report.objects.create(name=report_name, active=True)
45
resp = self.client.get('/reports/%s/' % (report_name,))
46
self.assertEqual(200, resp.status_code)
47
self.assertQuerysetEqual(resp.context['recent'].object_list, [])
49
def make_oops(self, prefix):
50
classification = Classification.objects.create(
51
title=self.getUniqueString(prefix="classification"))
52
infestation = Infestation.objects.create(
53
exception_type=self.getUniqueString(prefix="exc_type"),
54
exception_value=self.getUniqueString(prefix="exc_value"))
55
return Oops.objects.create(
56
prefix=prefix, classification=classification,
57
oopsinfestation=infestation, statements_count=100,
58
appinstance=prefix.appinstance, total_time=3,
61
def make_prefix(self):
62
appinstance = AppInstance.objects.create(
63
title=self.getUniqueString(prefix="appinstance"))
64
return Prefix.objects.create(
65
value=self.getUniqueString(prefix="prefix"),
66
appinstance=appinstance)
68
def test_recent_oopses(self):
69
report_name = 'areport'
70
report = Report.objects.create(name=report_name, active=True)
71
prefix = self.make_prefix()
72
report.prefixes.add(prefix)
73
oops = self.make_oops(prefix)
74
resp = self.client.get('/reports/%s/' % (report_name,))
75
self.assertEqual(200, resp.status_code)
76
self.assertQuerysetEqual(
77
resp.context['recent'].object_list, [oops.pk], transform=attrgetter('pk'))