1
= Loading OOPS across day boundaries =
3
This test makes sure the fix for bug
4
https://bugs.edge.launchpad.net/oops-tools/+bug/576801 works.
6
Create two new oops directories to be used in this test.
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))
20
Create a fake oops report in the first directory.
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()
30
Load the oops from the first directory.
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
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))]
43
Create another fake oops report in the second directory.
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()
52
Load the second oops report.
54
>>> helpers._today = end_date
55
>>> found_oopses = loader.find_oopses(start_date=start_date)
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))]
61
Remove the fake OOPSes and directories.
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)
68
And reset the database.
70
>>> from oopstools.oops.helpers import reset_database
72
'Oops, DBOopsRootDirectory and Infestation deleted.'