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

« back to all changes in this revision

Viewing changes to src/oopstools/oops/test/db-summary-datetime.txt

  • Committer: Robert Collins
  • Date: 2011-10-13 20:18:51 UTC
  • Revision ID: robertc@robertcollins.net-20111013201851-ym8jmdhoeol3p83s
Export of cruft-deleted tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
= Using datetime to generate a partial OOPS summary =
 
2
 
 
3
OOPS summaries can be generated for a shorter period of time than a day.
 
4
 
 
5
    >>> from oopstools.oops.helpers import generate_summary, load_database
 
6
    >>> prefixes = ["S"]
 
7
    >>> from datetime import datetime
 
8
    >>> start_date = datetime(2007, 11, 20, 11, 55, 0)
 
9
    >>> end_date = datetime(2007, 11, 20, 12, 20, 0)
 
10
 
 
11
Before generating the summary, let's load the sample data into the database.
 
12
 
 
13
    >>> load_database(start_date.date(), end_date.date())
 
14
    'Oopses loaded into the database.'
 
15
 
 
16
Now let's generate it.
 
17
 
 
18
    >>> webapp_summary = generate_summary(
 
19
    ...     prefixes, from_date=start_date, to_date=end_date)
 
20
 
 
21
And check that we get only OOPSes that happen during the 35m period requested.
 
22
 
 
23
    >>> from oopstools.oops.helpers import get_section_contents
 
24
    >>> print get_section_contents("Statistics", webapp_summary)
 
25
     * Log starts: ...
 
26
     * Analyzed period: ...
 
27
     * Total OOPSes: 1
 
28
    <BLANKLINE>
 
29
     * 0 Exceptions
 
30
     * 0 Time Outs
 
31
     * 1 Soft Time Outs
 
32
     * 0 Informational Only Errors
 
33
     * 0 User Generated Errors
 
34
     * 0 Unauthorized Errors
 
35
     * 0 Pages Not Found
 
36
 
 
37
    >>> print get_section_contents("All Soft Time Outs", webapp_summary)
 
38
    1 SELECT product, ... question_count DESC LIMIT $INT:
 
39
    Other: 1 Robots: 1  Local: 1
 
40
    1 https://answers.staging.launchpad.net/questions/+index (FooBar:+questions)
 
41
    OOPS-689S4
 
42
 
 
43
Demonstrate that there are more OOPS reports for the day (one was reported, so
 
44
> 1 need to exist to show the report did limit what it showed).
 
45
 
 
46
    >>> from datetime import timedelta
 
47
    >>> from oopstools.oops.models import Oops
 
48
    >>> for oops in Oops.objects.filter(date__gte=start_date.date(),
 
49
    ...                                 date__lt=end_date.date() + timedelta(days=1),
 
50
    ...                                 prefix__value__in=prefixes).order_by('date'):
 
51
    ...     print oops, oops.date
 
52
    OOPS-689S4 2007-11-20 12:00:31
 
53
    OOPS-689S6 2007-11-20 12:31:24
 
54
 
 
55
And reset the database.
 
56
 
 
57
    >>> from oopstools.oops.helpers import reset_database
 
58
    >>> reset_database()
 
59
    'Oops, DBOopsRootDirectory and Infestation deleted.'
 
60