~launchpad-pqm/launchpad/devel

9116.1.1 by Curtis Hovey
Updated karma action +index (index is a form) to UI 3.0
1
KarmaAction views
2
=================
3
4
    >>> from lp.registry.interfaces.karma import IKarmaActionSet
5
6
    >>> karmaactionset = getUtility(IKarmaActionSet)
9116.1.10 by Curtis Hovey
Updated old test. Removed bad test.
7
8
9
Karma action set
10
----------------
11
12
The karma action set +index view lists all the karma actions.
13
14
    >>> from canonical.launchpad.webapp.interfaces import ILaunchBag
15
    >>> from canonical.launchpad.testing.pages import (
16
    ...     extract_text, find_tag_by_id)
17
18
    >>> user = getUtility(ILaunchBag).user
19
    >>> view = create_view(karmaactionset, '+index', principal=user,
10023.2.6 by Curtis Hovey
Updated tests to use the fixed create_view.
20
    ...     path_info='/karmaaction')
9116.1.10 by Curtis Hovey
Updated old test. Removed bad test.
21
    >>> print extract_text(find_tag_by_id(view(), 'karmas'))
22
    Category        Action          Points
23
    bugs            Bug Accepted    5
24
    ...
25
26
27
Karma action
28
------------
9116.1.1 by Curtis Hovey
Updated karma action +index (index is a form) to UI 3.0
29
30
The karma action +edit view allow an admin to edit a karma action. The
31
view provides a label, page_title and a cancel_url
32
9116.1.10 by Curtis Hovey
Updated old test. Removed bad test.
33
    >>> action = karmaactionset.getByName('branchcreated')
9116.1.1 by Curtis Hovey
Updated karma action +index (index is a form) to UI 3.0
34
    >>> view = create_initialized_view(action, '+index')
35
    >>> print view.label
36
    Edit New branch registered karma action
37
38
    >>> print view.page_title
39
    Edit New branch registered karma action
40
41
    >>> print view.cancel_url
42
    http://launchpad.dev/karmaaction
43
44
The admin can edit the karma action's fields.
45
46
    >>> view.field_names
47
    ['name', 'category', 'points', 'title', 'summary']
48
49
    >>> action.points
50
    1
51
52
    >>> login('admin@canonical.com')
53
    >>> form = {
54
    ...     'field.points': '2',
55
    ...     'field.actions.change': 'Change',
56
    ...     }
57
    >>> view = create_initialized_view(action, '+index', form=form)
58
    >>> view.errors
59
    []
60
61
    >>> print view.next_url
62
    http://launchpad.dev/karmaaction
63
64
    >>> action.points
65
    2
9116.1.10 by Curtis Hovey
Updated old test. Removed bad test.
66
67
Only admins can access the view.
68
69
    >>> from canonical.launchpad.webapp.authorization import check_permission
70
71
    >>> check_permission('launchpad.Admin', view)
72
    True
73
74
    >>> login('test@canonical.com')
75
    >>> check_permission('launchpad.Admin', view)
76
    False