~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
= Using datetime to generate a partial OOPS summary =

OOPS summaries can be generated for a shorter period of time than a day.

    >>> from oopstools.oops.helpers import generate_summary, load_database
    >>> prefixes = ["S"]
    >>> from datetime import datetime
    >>> start_date = datetime(2007, 11, 20, 11, 55, 0)
    >>> end_date = datetime(2007, 11, 20, 12, 20, 0)

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

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

Now let's generate it.

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

And check that we get only OOPSes that happen during the 35m period requested.

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

    >>> print get_section_contents("All Soft Time Outs", webapp_summary)
    1 SELECT product, ... question_count DESC LIMIT $INT:
    Other: 1 Robots: 1  Local: 1
    1 https://answers.staging.launchpad.net/questions/+index (FooBar:+questions)
    OOPS-689S4

Demonstrate that there are more OOPS reports for the day (one was reported, so
> 1 need to exist to show the report did limit what it showed).

    >>> from datetime import timedelta
    >>> from oopstools.oops.models import Oops
    >>> for oops in Oops.objects.filter(date__gte=start_date.date(),
    ...                                 date__lt=end_date.date() + timedelta(days=1),
    ...                                 prefix__value__in=prefixes).order_by('date'):
    ...     print oops, oops.date
    OOPS-689S4 2007-11-20 12:00:31
    OOPS-689S6 2007-11-20 12:31:24

And reset the database.

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