~launchpad-pqm/launchpad/devel

7845.3.4 by Edwin Grubbs
Fixed the display of the AnnouncementDateWidget.
1
= AnnouncementDateWidget =
2
3
This widget combines radio buttons and a DateTimeWidget. It allows you to
4
choose to publish an announcement immediately, at a predetermined date in the
5
future, or to manually publish it later.
6
11716.1.12 by Curtis Hovey
Sorted imports in doctests.
7
    >>> from zope.schema import Field
14578.4.1 by William Grant
Move the remains of canonical.launchpad.testing to lp.testing.
8
    >>> from lp.testing.pages import extract_text
7845.3.4 by Edwin Grubbs
Fixed the display of the AnnouncementDateWidget.
9
    >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
12293.1.1 by Curtis Hovey
Migrates some widgets.
10
    >>> from lp.app.widgets.announcementdate import AnnouncementDateWidget
7845.3.4 by Edwin Grubbs
Fixed the display of the AnnouncementDateWidget.
11
    >>> field = Field(__name__='foo', title=u'Foo')
12
    >>> widget = AnnouncementDateWidget(field, LaunchpadTestRequest())
13
    >>> print extract_text(widget())
14
    Publish this announcement:
15
    Immediately
16
    At some time in the future when I come back to authorize it
17
    At this specific date and time:
18
    in time zone: UTC
19
20
When you choose to publish at a specific date in the future, the widget will
21
return the date you specified.
22
23
    >>> action_widget = widget.action_widget
24
    >>> action_widget.request.form[action_widget.name] = 'specific'
25
    >>> date_widget = widget.announcement_date_widget
26
    >>> date_widget.request.form[date_widget.name] = '2005-07-23'
27
    >>> print widget.getInputValue()
28
    2005-07-23 00:00:00+00:00
29
30
When you choose to publish immediately, the widget will return the current
31
date and time.
32
7845.3.9 by Edwin Grubbs
Addressed reviewer comments and fixed lint errors.
33
    >>> from datetime import datetime, timedelta
7845.3.4 by Edwin Grubbs
Fixed the display of the AnnouncementDateWidget.
34
    >>> import pytz
35
    >>> action_widget.request.form[action_widget.name] = 'immediately'
36
    >>> date_widget.request.form[date_widget.name] = ''
7845.3.9 by Edwin Grubbs
Addressed reviewer comments and fixed lint errors.
37
    >>> now = datetime.now(pytz.utc)
38
    >>> before = now - timedelta(1) # 1 day
39
    >>> after = now + timedelta(1) # 1 day
7845.3.4 by Edwin Grubbs
Fixed the display of the AnnouncementDateWidget.
40
    >>> immediate_date = widget.getInputValue()
7845.3.9 by Edwin Grubbs
Addressed reviewer comments and fixed lint errors.
41
    >>> print repr(immediate_date)
42
    datetime.datetime(...)
7845.3.4 by Edwin Grubbs
Fixed the display of the AnnouncementDateWidget.
43
    >>> before < immediate_date < after
44
    True
45
46
When you choose to publish manually at some time in the future, the widget
47
won't return a date.
48
49
    >>> action_widget.request.form[action_widget.name] = 'sometime'
50
    >>> date_widget.request.form[date_widget.name] = '2005-07-23'
51
    >>> print widget.getInputValue()
52
    None
53
54
If you choose to publish immediately, the date field must be empty.
55
56
    >>> action_widget.request.form[action_widget.name] = 'immediately'
57
    >>> date_widget.request.form[date_widget.name] = '2005-07-23'
58
    >>> print widget.getInputValue()
59
    Traceback (most recent call last):
60
    ...
61
    WidgetInputError: ('field.foo', u'Foo',
8697.27.32 by Gary Poster
fix problems revealed in ec2test
62
                       LaunchpadValidationError(u'Please do not provide a date
63
                                                  if you want to publish
64
                                                  immediately.'))
7845.3.4 by Edwin Grubbs
Fixed the display of the AnnouncementDateWidget.
65
66
If you choose to publish at a specific date in the future, the date field
67
must be filled.
68
69
    >>> action_widget.request.form[action_widget.name] = 'specific'
70
    >>> date_widget.request.form[date_widget.name] = ''
71
    >>> print widget.getInputValue()
72
    Traceback (most recent call last):
73
    ...
74
    WidgetInputError: ('field.foo', u'Foo',
8697.27.32 by Gary Poster
fix problems revealed in ec2test
75
    LaunchpadValidationError(u'Please provide a publication date.'))