~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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
= Launchpad field validators =

    >>> from zope.security.proxy import removeSecurityProxy
    >>> from zope.component import getUtility
    >>> from canonical.launchpad.webapp.interfaces import IOpenLaunchBag
    >>> from lp.bugs.interfaces.bug import CreateBugParams
    >>> from lp.registry.interfaces.person import IPersonSet
    >>> from lp.registry.interfaces.product import IProductSet
    >>> no_priv = getUtility(IPersonSet).getByEmail(
    ...     'no-priv@canonical.com')
    >>> firefox = getUtility(IProductSet).getByName("firefox")
    >>> firefox = removeSecurityProxy(firefox)
    >>> firefox.bug_supervisor = no_priv

== can_be_nominated_for_series ==

This validator is used to check if the bug in the launchbag can be
nominated for the given series.

    >>> from lp.app.validators.validation import (
    ...     can_be_nominated_for_series)

If we create a new bug, all the target's series can be nominated.

    >>> login('no-priv@canonical.com')
    >>> firefox = getUtility(IProductSet).getByName('firefox')
    >>> bug = firefox.createBug(
    ...     CreateBugParams(no_priv, "New Bug", comment="New Bug."))
    >>> getUtility(IOpenLaunchBag).add(bug)

    >>> can_be_nominated_for_series(firefox.series)
    True

If we nominate the bug for one of the series, the validation will
fail for that specific series.

    >>> nomination = bug.addNomination(no_priv, firefox.series[0])
    >>> can_be_nominated_for_series(firefox.series)
    Traceback (most recent call last):
    ...
    LaunchpadValidationError...

    >>> can_be_nominated_for_series([firefox.series[0]])
    Traceback (most recent call last):
    ...
    LaunchpadValidationError...

It will pass for the rest of the series, though.

    >>> can_be_nominated_for_series(firefox.series[1:])
    True

Of course, if we accept the nomination, the validation will still
fail:

    >>> login('foo.bar@canonical.com')
    >>> foo_bar =  getUtility(IPersonSet).getByEmail(
    ...     'foo.bar@canonical.com')
    >>> nomination.approve(foo_bar)
    >>> can_be_nominated_for_series([firefox.series[0]])
    Traceback (most recent call last):
    ...
    LaunchpadValidationError...

The validation message will contain all the series that can't be
nominated.

    >>> trunk_nomination = bug.addNomination(
    ...     no_priv, firefox.series[1])
    >>> can_be_nominated_for_series(firefox.series)
    Traceback (most recent call last):
    ...
    LaunchpadValidationError:
    This bug has already been nominated for these series: 1.0, Trunk

Declined nominations can be re-nominated.

    >>> trunk_nomination.decline(foo_bar)
    >>> can_be_nominated_for_series([firefox.series[1]])
    True

== PersonNameField ==

The PersonNameField class, which is only used for extra validation on a
person's/team's name.

All persons have a unique name in launchpad, so to allow them to change
their names, we must make sure that name is not already in use by someone
else.

    >>> login('no-priv@canonical.com')
    >>> lifeless = getUtility(IPersonSet).getByName('lifeless')
    >>> from lp.registry.interfaces.person import PersonNameField
    >>> field = PersonNameField(
    ...     __name__='name', title=u'Unique name', description=u'',
    ...     readonly=False, required=True)
    >>> field = field.bind(lifeless)
    >>> field.context == lifeless
    True

You can always use your own name.

    >>> field.validate(lifeless.name)

Or a name that is not already in use.

    >>> field.validate(u'namenotinuse')

But you can't use Mark's name, of course. ;)

    >>> field.validate(u'mark')
    Traceback (most recent call last):
      ...
    LaunchpadValidationError: ...mark is already in use by another
    person or team...