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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#!/usr/bin/python
"""
Benchmark the daily calendar view with some long lasting recurrent events.
"""
from datetime import datetime, timedelta
from benchmark import *
import transaction
from schooltool.app.cal import CalendarEvent
from schooltool.person.person import Person
from schooltool.group.group import Group
from schooltool.calendar.recurrent import DailyRecurrenceRule
from schooltool.calendar.recurrent import WeeklyRecurrenceRule
from schooltool.calendar.recurrent import MonthlyRecurrenceRule
from schooltool.calendar.recurrent import YearlyRecurrenceRule
from schooltool.app.interfaces import ISchoolToolCalendar
def setup_benchmark():
setup = load_ftesting_zcml()
r = http("""POST /@@contents.html HTTP/1.1
Authorization: Basic mgr:mgrpw
Content-Length: 81
Content-Type: application/x-www-form-urlencoded
type_name=BrowserAdd__schooltool.app.app.SchoolToolApplication&new_value=frogpond""")
assert r.getStatus() == 303
app = setup.getRootFolder()['frogpond']
create_user_and_recurrent_events(app)
transaction.commit()
r = http(r"""GET /frogpond/persons HTTP/1.1
Authorization: Basic mgr:mgrpw
""")
assert r.getStatus() == 200
def create_user_and_recurrent_events(app):
"""Create a user with some recurrent events in his calendar.
The user's username will be 'manager', and his calendar will have
exactly four events, recurring daily, weekly, monthly, and yearly
respectively. All these events start on the same day.
"""
person = Person('manager', 'Manager')
app['persons']['manager'] = person
calendar = ISchoolToolCalendar(person)
recurrence = DailyRecurrenceRule()
daily_event = CalendarEvent(datetime(2005, 1, 1, 10, 0),
timedelta(60),
'Daily Event',
recurrence=recurrence)
calendar.addEvent(daily_event)
recurrence = WeeklyRecurrenceRule(weekdays=(0, 1, 2, 3, 4, 5, 6))
weekly_event = CalendarEvent(datetime(2005, 1, 1, 11, 0),
timedelta(60),
'Weekly event',
recurrence=recurrence)
calendar.addEvent(weekly_event)
recurrence = MonthlyRecurrenceRule()
monthly_event = CalendarEvent(datetime(2005, 1, 1, 12, 0),
timedelta(60),
'Monthly event',
recurrence=recurrence)
calendar.addEvent(monthly_event)
recurrence = YearlyRecurrenceRule()
yearly_event = CalendarEvent(datetime(2005, 1, 1, 13, 0),
timedelta(60),
'Yearly event',
recurrence=recurrence)
calendar.addEvent(yearly_event)
def daily_view_start_date():
"""Render the DailyCalendarView on the starting date."""
r = http(r"""GET /frogpond/persons/manager/calendar/2005-01-01 HTTP/1.1
Authorization: Basic mgr:mgrpw
""")
assert r.getStatus() == 200
def daily_view_in_a_year():
"""Render the DailyCalendarView a year after the starting date."""
r = http(r"""GET /frogpond/persons/manager/calendar/2006-01-01 HTTP/1.1
Authorization: Basic mgr:mgrpw
""")
assert r.getStatus() == 200
def daily_view_in_ten_years():
"""Render the DailyCalendarView ten years after the starting date."""
r = http(r"""GET /frogpond/persons/manager/calendar/2015-01-01 HTTP/1.1
Authorization: Basic mgr:mgrpw
""")
assert r.getStatus() == 200
def main():
print "ZCML took %.3f seconds." % measure(load_ftesting_zcml)
print "Setup took %.3f seconds." % measure(setup_benchmark)
benchmark("Daily calendar view on the start date.",
daily_view_start_date)
benchmark("Daily calendar view a year after the start date.",
daily_view_in_a_year)
benchmark("Daily calendar view ten years after the start date.",
daily_view_in_ten_years)
if __name__ == '__main__':
main()
|