~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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
= Atom Feeds For Revisions =

Atom feeds produce XML not HTML.  Therefore we must parse the output as XML
using BeautifulStoneSoup instead of BeautifulSoup or the helper functions.

    >>> from BeautifulSoup import BeautifulStoneSoup as BSS
    >>> from canonical.launchpad.ftests.feeds_helper import (
    ...     parse_ids, parse_links, validate_feed)

== Create some specific branches to use for this test ==

    >>> login(ANONYMOUS)
    >>> from lp.testing import time_counter
    >>> from datetime import datetime, timedelta
    >>> import pytz
    >>> # Since the feed only shows revisions from the last 30 days, we
    >>> # need recent revisions.
    >>> initial_revision_date = datetime.now(pytz.UTC) - timedelta(days=10)
    >>> date_generator = time_counter(
    ...     initial_revision_date, timedelta(days=1))
    >>> mike = factory.makePerson(
    ...    name='mike', displayname='Mike Murphy', email='mike@example.com')
    >>> mary = factory.makePerson(
    ...    name='mary', displayname='Mary Murphy', email='mary@example.com')
    >>> fubar = factory.makeProject(name='fubar', displayname="Fubar")
    >>> fooix = factory.makeProduct(
    ...     name='fooix', displayname="Fooix", project=fubar)
    >>> fooey = factory.makeProduct(
    ...     name='fooey', displayname="Fooey", project=fubar)
    >>> fooix_branch = factory.makeProductBranch(
    ...     name='feature-x', product=fooix, owner=mike)
    >>> fooey_branch = factory.makeProductBranch(
    ...     name='feature-x', product=fooey, owner=mike)

    >>> from zope.security.proxy import removeSecurityProxy
    >>> def makeRevision(author, rev_id, log_body):
    ...     global factory, date_generator
    ...     return factory.makeRevision(
    ...         author=removeSecurityProxy(author).preferredemail.email,
    ...         revision_date=date_generator.next(),
    ...         rev_id=rev_id, log_body=log_body)
    >>> ignored = fooey_branch.createBranchRevision(
    ...     1, makeRevision(
    ...         mike, 'rev1', 'This is a short log message'))
    >>> ignored = fooix_branch.createBranchRevision(
    ...     2, makeRevision(
    ...         mike, 'rev2', 'This is a much longer log message that will'
    ...         ' be truncated due to length of a single line.'))
    >>> ignored = fooix_branch.createBranchRevision(
    ...     None, makeRevision(
    ...         mike, 'rev2.1', 'This is a two\nline log message.'))
    >>> ignored = fooey_branch.createBranchRevision(
    ...     3, makeRevision(
    ...         mary, 'rev3', "Mary's revision"))

    >>> login_person(mike)
    >>> team = factory.makeTeam(mike, 'The M Team', name='m-team')
    >>> ignored = team.addMember(mary, mike)
    >>> from zope.component import getUtility
    >>> from lp.code.interfaces.revision import IRevisionSet
    >>> revision_set = getUtility(IRevisionSet)
    >>> revision_set.updateRevisionCacheForBranch(fooey_branch)
    >>> revision_set.updateRevisionCacheForBranch(fooix_branch)
    >>> logout()


== Feed for a person's revisions ==

The feed for a person's revisions will show the most recent 25 revisions
that have been committed by that person (or attributed to that person).

    >>> anon_browser.open('http://feeds.launchpad.dev/~mike/revisions.atom')
    >>> def validate_browser_feed(browser):
    ...     validate_feed(
    ...         browser.contents, browser.headers['content-type'], browser.url)
    >>> validate_browser_feed(anon_browser)
    No Errors
    >>> BSS(anon_browser.contents).title.contents
    [u'Latest Revisions by Mike Murphy']
    >>> def print_parse_ids(browser):
    ...     for id in parse_ids(browser.contents):
    ...         print id

Ignore the date associated with the id of 'mike' as this is the date created
of the person, which will be different each time the test is run.

    >>> print_parse_ids(anon_browser)
    <id>tag:launchpad.net,...:/code/~mike</id>
    <id>tag:launchpad.net,...:/revision/rev2.1</id>
    <id>tag:launchpad.net,...:/revision/rev2</id>
    <id>tag:launchpad.net,...:/revision/rev1</id>

Ensure the self link is correct and there is only one.

    >>> def print_parse_links(browser):
    ...     for link in parse_links(browser.contents, rel="self"):
    ...         print link
    >>> print_parse_links(anon_browser)
    <link rel="self" href="http://feeds.launchpad.dev/~mike/revisions.atom" />

If we look at the feed for a team, we get revisions created by any member
of that team.

    >>> browser.open('http://feeds.launchpad.dev/~m-team/revisions.atom')
    >>> validate_browser_feed(browser)
    No Errors
    >>> BSS(browser.contents).title.contents
    [u'Latest Revisions by members of The M Team']
    >>> print_parse_ids(browser)
    <id>tag:launchpad.net,...:/code/~m-team</id>
    <id>tag:launchpad.net,...:/revision/rev3</id>
    <id>tag:launchpad.net,...:/revision/rev2.1</id>
    <id>tag:launchpad.net,...:/revision/rev2</id>
    <id>tag:launchpad.net,...:/revision/rev1</id>


== Feed for a product's revisions ==

The feed for a product's revisions will show the most recent 25 revisions
that have been committed on branches for the product.

    >>> anon_browser.open('http://feeds.launchpad.dev/fooix/revisions.atom')
    >>> validate_browser_feed(anon_browser)
    No Errors
    >>> BSS(anon_browser.contents).title.contents
    [u'Latest Revisions for Fooix']

Ignore the date associated with the id of 'fooix' as this is the date created
for the product, which will be different each time the test is run.

    >>> print_parse_ids(anon_browser)
    <id>tag:launchpad.net,...:/code/fooix</id>
    <id>tag:launchpad.net,...:/revision/rev2.1</id>
    <id>tag:launchpad.net,...:/revision/rev2</id>

Ensure the self link points to the feed location and there is only one.

    >>> print_parse_links(anon_browser)
    <link rel="self" href="http://feeds.launchpad.dev/fooix/revisions.atom" />


== Feed for a project's revisions ==

A feed for a project will show the most recent 25 revisions across any
branch for any product that is associated with the project.

    >>> anon_browser.open('http://feeds.launchpad.dev/fubar/revisions.atom')
    >>> validate_browser_feed(anon_browser)
    No Errors
    >>> BSS(anon_browser.contents).title.contents
    [u'Latest Revisions for Fubar']

Ignore the date associated with the id of 'fubar' as this is the date created
of the project, which will be different each time the test is run.

    >>> print_parse_ids(anon_browser)
    <id>tag:launchpad.net,...:/code/fubar</id>
    <id>tag:launchpad.net,...:/revision/rev3</id>
    <id>tag:launchpad.net,...:/revision/rev2.1</id>
    <id>tag:launchpad.net,...:/revision/rev2</id>
    <id>tag:launchpad.net,...:/revision/rev1</id>

Ensure the self link points to the feed location and there is only one.

    >>> print_parse_links(anon_browser)
    <link rel="self" href="http://feeds.launchpad.dev/fubar/revisions.atom" />