~launchpad-pqm/launchpad/devel

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
QuestionWorkflowView: Handling of the subscribe_me option
=========================================================

This test makes sure that it is possible to subscribe to the question
whatever the action used.

    >>> from lp.answers.browser.question import QuestionWorkflowView
    >>> from lp.testing.deprecated import LaunchpadFormHarness
    >>> from lp.services.webapp.interfaces import ILaunchBag
    >>> from lp.registry.interfaces.product import IProductSet

    >>> firefox = getUtility(IProductSet).getByName('firefox')
    >>> login('test@canonical.com')
    >>> sample_person = getUtility(ILaunchBag).user
    >>> firefox_question = firefox.newQuestion(
    ...     sample_person, 'New question', 'A problem.')

Empty the subscribers list:

    >>> firefox_question.unsubscribe(sample_person, sample_person)
    >>> list(firefox_question.subscriptions)
    []

Create a view harness:

    >>> workflow_harness = LaunchpadFormHarness(
    ...     firefox_question, QuestionWorkflowView)
    >>> form_data = {'field.message': 'A message.',
    ...              'field.subscribe_me.used': 1,
    ...              'field.subscribe_me': 'on'}

Subscription is possible when requesting for more information:

    >>> login('foo.bar@canonical.com')
    >>> foo_bar = getUtility(ILaunchBag).user
    >>> workflow_harness.submit('requestinfo', form_data)
    >>> firefox_question.isSubscribed(foo_bar)
    True
    >>> firefox_question.unsubscribe(foo_bar, foo_bar)

Subscription is possible when providing more information:

    >>> login('test@canonical.com')
    >>> workflow_harness.submit('giveinfo', form_data)
    >>> firefox_question.isSubscribed(sample_person)
    True
    >>> firefox_question.unsubscribe(sample_person, sample_person)

Subscription is possible when providing an answer:

    >>> login('foo.bar@canonical.com')
    >>> workflow_harness.submit('answer', form_data)
    >>> firefox_question.isSubscribed(foo_bar)
    True
    >>> firefox_question.unsubscribe(foo_bar, foo_bar)

As when confirming an answer (altough this is probably not that common):

    >>> login('test@canonical.com')
    >>> workflow_harness.submit('confirm', dict(answer_id=-1, **form_data))
    >>> firefox_question.isSubscribed(sample_person)
    True
    >>> firefox_question.unsubscribe(sample_person, sample_person)

It is also possible when reopening the request.

    >>> workflow_harness.submit('reopen', form_data)
    >>> firefox_question.isSubscribed(sample_person)
    True
    >>> firefox_question.unsubscribe(sample_person, sample_person)

Self-Answering the request:

    >>> workflow_harness.submit('selfanswer', form_data)
    >>> firefox_question.isSubscribed(sample_person)
    True
    >>> firefox_question.unsubscribe(sample_person, sample_person)

As well as adding a comment:

    >>> workflow_harness.submit('comment', form_data)
    >>> firefox_question.isSubscribed(sample_person)
    True
    >>> firefox_question.unsubscribe(sample_person, sample_person)

Make sure that whenever the view actions is modified, this test
requires update:

    >>> print "\n".join(sorted(
    ...     action.__name__.split('.')[-1]
    ...     for action in workflow_harness.view.actions))
    answer
    comment
    confirm
    giveinfo
    reopen
    requestinfo
    selfanswer