~james-w/python-oops-tools/prod-deploy

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Martin Packman
  • Date: 2011-12-15 12:50:52 UTC
  • mfrom: (27.2.6 python-oops-tools)
  • Revision ID: launchpad@pqm.canonical.com-20111215125052-3uso1kf6dfjimbsq
Encode output of analyse_error_reports as UTF-8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2005-2011 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
 
 
17
from datetime import (
 
18
    datetime,
 
19
    )
 
20
from cStringIO import StringIO
 
21
 
 
22
from pytz import utc
 
23
from testtools import TestCase
 
24
from testtools.matchers import Contains
 
25
 
 
26
from oopstools.oops.dbsummaries import WebAppErrorSummary
 
27
from oopstools.oops.models import parsed_oops_to_model_oops
 
28
 
 
29
 
 
30
class TestWebAppErrorSummary(TestCase):
 
31
 
 
32
    def _createOops(self):
 
33
        python_oops = {
 
34
            'id': 'OOPS-1234S101',
 
35
            'reporter': 'edge',
 
36
            'type': 'Exception',
 
37
            'value': u'a unicode char (\xa7)',
 
38
            'time': datetime(2008, 1, 13, 23, 14, 23, 00, utc),
 
39
            }
 
40
        ignored = parsed_oops_to_model_oops(
 
41
            python_oops, 'test_unicode_handling')
 
42
 
 
43
    def setUp(self):
 
44
        super(TestWebAppErrorSummary, self).setUp()
 
45
        self._createOops()
 
46
        start = end = datetime(2008, 1, 13)
 
47
        prefixes = ['EDGE']
 
48
        self.summary = WebAppErrorSummary(start, end, prefixes)
 
49
 
 
50
    def test_renderHTML_with_unicode_data(self):
 
51
        # Summarising an oops with a unicode exception value should output
 
52
        # a UTF-8 encoded html representation.
 
53
        fp = StringIO()
 
54
        self.summary.renderHTML(fp)
 
55
        self.assertThat(fp.getvalue(), Contains('a unicode char (\xc2\xa7)'))