~launchpad-pqm/python-oops-tools/trunk

« back to all changes in this revision

Viewing changes to src/oopstools/oops/test/test_report.py

  • Committer: Tarmac
  • Author(s): James Westby
  • Date: 2012-12-05 05:01:01 UTC
  • mfrom: (48.1.4 recent-oopses)
  • Revision ID: launchpad@pqm.canonical.com-20121205050101-0xdbbnecsgyrlsne
Show the (paginated) oopses for each report.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2005-2012 Canonical Ltd.  All rights reserved.
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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/>.
 
15
 
 
16
from datetime import datetime
 
17
from operator import attrgetter
 
18
 
 
19
from oopstools.oops.models import (
 
20
    AppInstance,
 
21
    Classification,
 
22
    Infestation,
 
23
    Oops,
 
24
    Prefix,
 
25
    Report,
 
26
)
 
27
from oopstools.oops.test.testcase import TestCase
 
28
 
 
29
 
 
30
class ReportTests(TestCase):
 
31
 
 
32
    def test_no_report(self):
 
33
        resp = self.client.get('/reports/some-report/')
 
34
        self.assertEqual(404, resp.status_code)
 
35
 
 
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)
 
41
 
 
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, [])
 
48
 
 
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,
 
59
                date=datetime.now())
 
60
 
 
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)
 
67
 
 
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'))