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

« back to all changes in this revision

Viewing changes to src/oopstools/oops/test/bug-576801.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
= Loading OOPS across day boundaries =
 
2
 
 
3
This test makes sure the fix for bug
 
4
https://bugs.edge.launchpad.net/oops-tools/+bug/576801 works.
 
5
 
 
6
Create two new oops directories to be used in this test.
 
7
 
 
8
    >>> import os
 
9
    >>> from datetime import date, timedelta
 
10
    >>> from django.conf import settings
 
11
    >>> start_date = date(2010, 5, 10)
 
12
    >>> end_date = start_date + timedelta(days=1)
 
13
    >>> oops_dir_one_str = start_date.strftime("%Y-%m-%d")
 
14
    >>> oops_dir_two_str = end_date.strftime("%Y-%m-%d")
 
15
    >>> os.mkdir(os.path.join(
 
16
    ...     settings.OOPSDIR[0], 'dir1', oops_dir_one_str))
 
17
    >>> os.mkdir(os.path.join(
 
18
    ...     settings.OOPSDIR[0], 'dir1', oops_dir_two_str))
 
19
 
 
20
Create a fake oops report in the first directory.
 
21
 
 
22
    >>> from oopstools.oops.helpers import create_fake_oops
 
23
    >>> oops_dir_one = os.path.join(
 
24
    ...     settings.OOPSDIR[0], 'dir1', oops_dir_one_str)
 
25
    >>> fake_oops_one = open(oops_dir_one + "/" + "68350.X1", "w")
 
26
    >>> contents = create_fake_oops(start_date)
 
27
    >>> fake_oops_one.write(contents)
 
28
    >>> fake_oops_one.close()
 
29
 
 
30
Load the oops from the first directory.
 
31
 
 
32
    >>> from oopstools.oops.dboopsloader import OopsLoader
 
33
    >>> from oopstools.oops import helpers
 
34
    >>> loader = OopsLoader()
 
35
    >>> helpers._today = start_date
 
36
    >>> found_oopses = loader.find_oopses(start_date=start_date)
 
37
    >>> from pprint import pprint
 
38
    >>> pprint(
 
39
    ...     [(oops, oops.date) for oops in
 
40
    ...      sorted(found_oopses, key=lambda oops: oops.date)])
 
41
    [(<Oops: OOPS-1591X1>, datetime.datetime(2010, 5, 10, 18, 59, 10))]
 
42
 
 
43
Create another fake oops report in the second directory.
 
44
 
 
45
    >>> oops_dir_two = os.path.join(
 
46
    ...     settings.OOPSDIR[0], 'dir1', oops_dir_two_str)
 
47
    >>> fake_oops_two = open(oops_dir_two + "/" + "68350.X1", "w")
 
48
    >>> contents = create_fake_oops(end_date)
 
49
    >>> fake_oops_two.write(contents)
 
50
    >>> fake_oops_two.close()
 
51
 
 
52
Load the second oops report.
 
53
 
 
54
    >>> helpers._today = end_date
 
55
    >>> found_oopses = loader.find_oopses(start_date=start_date)
 
56
    >>> pprint(
 
57
    ...     [(oops, oops.date) for oops in
 
58
    ...      sorted(found_oopses, key=lambda oops: oops.date)])
 
59
    [(<Oops: OOPS-1592X1>, datetime.datetime(2010, 5, 11, 18, 59, 10))]
 
60
 
 
61
Remove the fake OOPSes and directories.
 
62
 
 
63
    >>> os.remove(fake_oops_one.name)
 
64
    >>> os.remove(fake_oops_two.name)
 
65
    >>> os.rmdir(oops_dir_one)
 
66
    >>> os.rmdir(oops_dir_two)
 
67
 
 
68
And reset the database.
 
69
 
 
70
    >>> from oopstools.oops.helpers import reset_database
 
71
    >>> reset_database()
 
72
    'Oops, DBOopsRootDirectory and Infestation deleted.'