|
13 | 13 | import datetime |
14 | 14 |
|
15 | 15 | import pretend |
| 16 | +import pytest |
16 | 17 |
|
17 | 18 | from warehouse.rss import views as rss |
18 | 19 |
|
@@ -102,36 +103,39 @@ def test_rss_project_releases(db_request): |
102 | 103 | assert db_request.response.content_type == "text/xml" |
103 | 104 |
|
104 | 105 |
|
105 | | -def test_format_author(db_request): |
| 106 | +@pytest.mark.parametrize( |
| 107 | + ("author_email", "expected"), |
| 108 | + [ |
| 109 | + (None, None), |
| 110 | + ("", None), |
| 111 | + ("UNKNOWN", None), |
| 112 | + ("noreply@pypi.org, UNKNOWN", None), |
| 113 | + ("noreply@pypi.org", "noreply@pypi.org"), |
| 114 | + ("No Reply <noreply@pypi.org>", "noreply@pypi.org"), |
| 115 | + ( |
| 116 | + ( |
| 117 | + # simple, no spaces |
| 118 | + "noreply@pypi.org," |
| 119 | + # space after |
| 120 | + "noreply@pypi.org ," |
| 121 | + # space before, incl realname |
| 122 | + " No Reply <noreply@pypi.org>," |
| 123 | + # two spaces before, angle brackets |
| 124 | + " <noreply@pypi.org>" |
| 125 | + ), |
| 126 | + ", ".join(["noreply@pypi.org"] * 4), |
| 127 | + ), |
| 128 | + ], |
| 129 | +) |
| 130 | +def test_format_author(db_request, author_email, expected): |
106 | 131 | db_request.find_service = pretend.call_recorder( |
107 | 132 | lambda *args, **kwargs: pretend.stub( |
108 | 133 | enabled=False, csp_policy=pretend.stub(), merge=lambda _: None |
109 | 134 | ) |
110 | 135 | ) |
111 | | - |
112 | 136 | db_request.session = pretend.stub() |
113 | 137 |
|
114 | | - project = ProjectFactory.create() |
115 | | - release = ReleaseFactory.create(project=project) |
116 | | - |
117 | | - release.author_email = "noreply@pypi.org" |
118 | | - assert rss._format_author(release) == release.author_email |
119 | | - |
120 | | - release.author_email = "No Reply <noreply@pypi.org>" |
121 | | - assert rss._format_author(release) == "noreply@pypi.org" |
122 | | - |
123 | | - for invalid in (None, "", "UNKNOWN", "noreply@pypi.org, UNKNOWN"): |
124 | | - release.author_email = invalid |
125 | | - assert rss._format_author(release) is None |
126 | | - |
127 | | - release.author_email = ( |
128 | | - # simple, no spaces |
129 | | - "noreply@pypi.org," |
130 | | - # space after |
131 | | - "noreply@pypi.org ," |
132 | | - # space before, incl realname |
133 | | - " No Reply <noreply@pypi.org>," |
134 | | - # two spaces before, angle brackets |
135 | | - " <noreply@pypi.org>" |
136 | | - ) |
137 | | - assert rss._format_author(release) == ", ".join(["noreply@pypi.org"] * 4) |
| 138 | + release = ReleaseFactory.create() |
| 139 | + |
| 140 | + release.author_email = author_email |
| 141 | + assert rss._format_author(release) == expected |
0 commit comments