~lifeless/python-oops-tools/bug-881400

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
= Daily summary generated from the OOPS database =

The analyse script accepts a parameter to generate OOPS summaries directly
from the database.

    >>> from oopstools.oops.helpers import generate_summary, load_database
    >>> prefixes = ["S", "X"]
    >>> from datetime import date
    >>> start_date = date(2007, 02, 22)
    >>> end_date = date(2010, 01, 8)

Before generating the summary, let's load the sample data into the database.

    >>> load_database(start_date, end_date)
    'Oopses loaded into the database.'

And add a bug to the oops database so we can test that a linked bug is
correctly displayed in the summary.

    >>> from oopstools.oops.models import Oops
    >>> oops = Oops.objects.get(oopsid__exact='OOPS-689S4')
    >>> oops.oopsinfestation.bug = 2112
    >>> oops.oopsinfestation.save()

Now let's generate the summary.

    >>> webapp_summary = generate_summary(
    ...     prefixes, from_date=start_date, to_date=end_date)

    >>> from oopstools.oops.helpers import get_section_contents
    >>> print get_section_contents("Statistics", webapp_summary)
     * Log starts: ...
     * Analyzed period: ...
     * Total OOPSes: 2
     * Average OOPSes per day: ...
    <BLANKLINE>
     * 0 Exceptions
     * 0 Time Outs
     * 2 Soft Time Outs
     * 0 Informational Only Errors
     * 0 User Generated Errors
     * 0 Unauthorized Errors
     * 0 Pages Not Found

    >>> print get_section_contents("Top 10 Durations", webapp_summary)
    26.46s  OOPS-689S4      FooBar:+questions
    20.67s  OOPS-689S6      FooBar:+bug-text
    0.28s  OOPS-1308X1      Unknown

    >>> print get_section_contents("Top 10 Statement Counts", webapp_summary)
    14  OOPS-1308X1     Unknown
    4 OOPS-689S6        FooBar:+bug-text
    3  OOPS-689S4       FooBar:+questions

     4203  OOPS-969XMLP1805  MailingListApplication:MailingListAPIView
      260  OOPS-894EB74    Archive:+index
      111  OOPS-1311EC295  Product:+code-index
      107  OOPS-689S6      FooBar:+bug-text
       72  OOPS-689S80     FooBarPackage:+translate
    ...

    >>> print get_section_contents("Time Out Counts by Page ID", webapp_summary)
    Hard / Soft  Page ID

    >>> print get_section_contents("All Exceptions", webapp_summary)

    >>> print get_section_contents("All Time Outs", webapp_summary)

    >>> print get_section_contents("All Soft Time Outs", webapp_summary)
       1 SELECT ...
        Other: 1  Robots: 1  Local: 1
           1 https://answers.../questions/+index (FooBar:+questions)
            OOPS-689S4

    >>> print get_section_contents(
    ...     "All Informational Only Errors", webapp_summary)

    >>> print get_section_contents("All User Generated Errors", webapp_summary)

    >>> print get_section_contents("All Unauthorized Errors", webapp_summary)
    <BLANKLINE>

    >>> print get_section_contents("All Pages Not Found", webapp_summary)
    <BLANKLINE>


Let's remove the bug from the database, so it won't change the behaviour of
other tests.

    >>> oops.oopsinfestation.delete()

And reset the database.

    >>> from oopstools.oops.helpers import reset_database
    >>> reset_database()
    'Oops, DBOopsRootDirectory and Infestation deleted.'