Skip to content

Commit 68655b5

Browse files
committed
Fixed 2 testing bugs. Added tests for handling of submitters without email and drafts with non-ascii names in the author section.
- Legacy-Id: 12064
1 parent da2c251 commit 68655b5

5 files changed

Lines changed: 266 additions & 8 deletions

File tree

ietf/idindex/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_fields(content):
101101
author = draft.documentauthor_set.order_by("order").get()
102102
self.assertEqual(t[14], u"%s <%s>" % (author.author.person.name, author.author.address))
103103
self.assertEqual(t[15], u"%s <%s>" % (draft.shepherd.person.name, draft.shepherd.address))
104-
self.assertEqual(t[16], u"%s <%s>" % (draft.ad, draft.ad.email_address()))
104+
self.assertEqual(t[16], u"%s <%s>" % (draft.ad.plain_ascii(), draft.ad.email_address()))
105105

106106

107107
# test RFC

ietf/submit/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __unicode__(self):
5454
return u"%s-%s" % (self.name, self.rev)
5555

5656
def authors_parsed(self):
57-
if not hasattr(self._meta, '_cached_authors_parsed'):
57+
if not hasattr(self, '_cached_authors_parsed'):
5858
from ietf.submit.utils import ensure_person_email_info_exists
5959
res = []
6060
for line in self.authors.replace("\r", "").split("\n"):
@@ -64,8 +64,8 @@ def authors_parsed(self):
6464
if not parsed["email"]:
6565
parsed["email"] = ensure_person_email_info_exists(**parsed).address
6666
res.append(parsed)
67-
self._meta._cached_authors_parsed = res
68-
return self._meta._cached_authors_parsed
67+
self._cached_authors_parsed = res
68+
return self._cached_authors_parsed
6969

7070
def submitter_parsed(self):
7171
return parse_email_line(self.submitter)
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
2+
3+
4+
5+
Network Working Group %(initials)s %(surname)s
6+
Internet-Draft Test Centre Inc.
7+
Intended status: Informational %(month)s %(year)s
8+
Expires: %(expiration)s
9+
10+
11+
Testing Tests
12+
%(name)s
13+
14+
Abstract
15+
16+
This document describes how to test tests.
17+
18+
Status of This Memo
19+
20+
This Internet-Draft is submitted in full conformance with the
21+
provisions of BCP 78 and BCP 79.
22+
23+
Internet-Drafts are working documents of the Internet Engineering
24+
Task Force (IETF). Note that other groups may also distribute
25+
working documents as Internet-Drafts. The list of current Internet-
26+
Drafts is at http://datatracker.ietf.org/drafts/current/.
27+
28+
Internet-Drafts are draft documents valid for a maximum of six months
29+
and may be updated, replaced, or obsoleted by other documents at any
30+
time. It is inappropriate to use Internet-Drafts as reference
31+
material or to cite them other than as "work in progress."
32+
33+
This Internet-Draft will expire on %(expiration)s.
34+
35+
Copyright Notice
36+
37+
Copyright (c) %(year)s IETF Trust and the persons identified as the
38+
document authors. All rights reserved.
39+
40+
This document is subject to BCP 78 and the IETF Trust's Legal
41+
Provisions Relating to IETF Documents
42+
(http://trustee.ietf.org/license-info) in effect on the date of
43+
publication of this document. Please review these documents
44+
carefully, as they describe your rights and restrictions with respect
45+
to this document. Code Components extracted from this document must
46+
include Simplified BSD License text as described in Section 4.e of
47+
the Trust Legal Provisions and are provided without warranty as
48+
described in the Simplified BSD License.
49+
50+
51+
52+
53+
54+
55+
56+
%(surname)s Expires %(expiration)s [Page 1]
57+
58+
Internet-Draft Testing Tests %(month)s %(year)s
59+
60+
61+
Table of Contents
62+
63+
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2
64+
2. Security Considerations . . . . . . . . . . . . . . . . . . . 2
65+
3. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 2
66+
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 2
67+
68+
1. Introduction
69+
70+
This document describes a protocol for testing tests.
71+
72+
2. Yang
73+
74+
<CODE BEGINS> file "ietf-mpls@2015-10-16.yang"
75+
76+
module ietf-mpls {
77+
78+
namespace "urn:ietf:params:xml:ns:yang:ietf-mpls";
79+
80+
prefix "mpls";
81+
82+
import ietf-routing {
83+
prefix "rt";
84+
}
85+
86+
import ietf-interfaces {
87+
prefix "if";
88+
}
89+
90+
organization "TBD";
91+
92+
contact "TBD";
93+
94+
description
95+
"This YANG module defines the essential components for the
96+
management of the MPLS subsystem.";
97+
98+
revision "2015-10-16" {
99+
description
100+
"Initial revision";
101+
reference "RFC 3031: A YANG Data Model for base MPLS";
102+
}
103+
104+
typedef mpls-label {
105+
type uint32 {
106+
range "0..1048575";
107+
}
108+
description
109+
"The MPLS label range";
110+
}
111+
112+
typedef percent {
113+
type uint16 {
114+
range "0 .. 100";
115+
}
116+
description "Percentage";
117+
}
118+
119+
grouping interface-mpls {
120+
description "MPLS interface properties grouping";
121+
leaf enabled {
122+
type boolean;
123+
description
124+
"'true' if mpls encapsulation is enabled on the
125+
interface. 'false' if mpls encapsulation is enabled
126+
on the interface.";
127+
}
128+
}
129+
130+
augment "/rt:routing/rt:routing-instance" {
131+
description "MPLS augmentation.";
132+
container mpls {
133+
description
134+
"MPLS container, to be used as an augmentation target node
135+
other MPLS sub-features config, e.g. MPLS static LSP, MPLS
136+
LDP LSPs, and Trafic Engineering MPLS LSP Tunnels, etc.";
137+
138+
list interface {
139+
key "name";
140+
description "List of MPLS interfaces";
141+
leaf name {
142+
type if:interface-ref;
143+
description
144+
"The name of a configured MPLS interface";
145+
}
146+
container config {
147+
description "Holds intended configuration";
148+
uses interface-mpls;
149+
}
150+
container state {
151+
config false;
152+
description "Holds inuse configuration";
153+
uses interface-mpls;
154+
}
155+
}
156+
}
157+
}
158+
159+
augment "/rt:routing-state/rt:routing-instance" {
160+
description "MPLS augmentation.";
161+
container mpls {
162+
config false;
163+
description
164+
"MPLS container, to be used as an augmentation target node
165+
other MPLS sub-features state";
166+
}
167+
}
168+
}
169+
170+
<CODE ENDS>
171+
172+
3. Security Considerations
173+
174+
There are none.
175+
176+
4. IANA Considerations
177+
178+
No new registrations for IANA.
179+
180+
Author's Address
181+
182+
%(author)s
183+
Test Centre Inc.
184+
42 Some Road
185+
Some Where 12345
186+
UK
187+
188+
Email: author@example.com
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
200+
201+
202+
203+
204+
205+
206+
207+
208+
209+
210+
211+
212+
%(surname)s Expires %(expiration)s [Page 2]

ietf/submit/tests.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
import datetime
23
import os
34
import shutil
@@ -18,29 +19,37 @@
1819
from ietf.meeting.models import Meeting
1920
from ietf.message.models import Message
2021
from ietf.person.models import Person, Email
22+
from ietf.person.factories import UserFactory, PersonFactory
2123
from ietf.submit.models import Submission, Preapproval
2224
from ietf.submit.mail import add_submission_email, process_response_email
2325
from ietf.utils.mail import outbox, empty_outbox
2426
from ietf.utils.test_data import make_test_data
2527
from ietf.utils.test_utils import login_testing_unauthorized, unicontent, TestCase
2628

2729

28-
def submission_file(name, rev, group, format, templatename):
30+
def submission_file(name, rev, group, format, templatename, author=None):
2931
# construct appropriate text draft
3032
f = open(os.path.join(settings.BASE_DIR, "submit", templatename))
3133
template = f.read()
3234
f.close()
3335

36+
if not author:
37+
author = PersonFactory()
38+
3439
submission_text = template % dict(
3540
date=datetime.date.today().strftime("%d %B %Y"),
3641
expiration=(datetime.date.today() + datetime.timedelta(days=100)).strftime("%d %B, %Y"),
3742
year=datetime.date.today().strftime("%Y"),
3843
month=datetime.date.today().strftime("%B"),
3944
name="%s-%s" % (name, rev),
4045
group=group or "",
46+
author=author.name,
47+
initials=author.initials(),
48+
surname=author.last_name(),
49+
email=author.email().address.lower(),
4150
)
4251

43-
file = StringIO(str(submission_text))
52+
file = StringIO(submission_text)
4453
file.name = "%s-%s.%s" % (name, rev, format)
4554
return file
4655

@@ -618,7 +627,10 @@ def test_edit_submission_and_force_post(self):
618627
"authors-0-email": "person1@example.com",
619628
"authors-1-name": "Person 2",
620629
"authors-1-email": "person2@example.com",
621-
"authors-prefix": ["authors-", "authors-0", "authors-1"],
630+
"authors-2-name": "Person 3",
631+
"authors-2-email": "",
632+
633+
"authors-prefix": ["authors-", "authors-0", "authors-1", "authors-2"],
622634
})
623635
self.assertEqual(r.status_code, 302)
624636

@@ -633,11 +645,13 @@ def test_edit_submission_and_force_post(self):
633645
self.assertEqual(submission.state_id, "manual")
634646

635647
authors = submission.authors_parsed()
636-
self.assertEqual(len(authors), 2)
648+
self.assertEqual(len(authors), 3)
637649
self.assertEqual(authors[0]["name"], "Person 1")
638650
self.assertEqual(authors[0]["email"], "person1@example.com")
639651
self.assertEqual(authors[1]["name"], "Person 2")
640652
self.assertEqual(authors[1]["email"], "person2@example.com")
653+
self.assertEqual(authors[2]["name"], "Person 3")
654+
self.assertEqual(authors[2]["email"], "unknown-email-Person-3")
641655

642656
self.assertEqual(len(outbox), mailbox_before + 1)
643657
self.assertTrue("Manual Post Requested" in outbox[-1]["Subject"])
@@ -873,6 +887,36 @@ def test_submit_bad_file_ps(self):
873887
self.assertIn('Expected the PS file to have extension ".ps"', m)
874888
self.assertIn('Expected an PS file of type "application/postscript"', m)
875889

890+
def test_submit_nonascii_name(self):
891+
make_test_data()
892+
893+
name = "draft-authorname-testing-nonascii"
894+
rev = "00"
895+
group = None
896+
897+
# get
898+
url = urlreverse('ietf.submit.views.upload_submission')
899+
r = self.client.get(url)
900+
self.assertEqual(r.status_code, 200)
901+
q = PyQuery(r.content)
902+
903+
# submit
904+
#author = PersonFactory(name=u"Jörgen Nilsson".encode('latin1'))
905+
user = UserFactory(first_name=u"Jörgen", last_name=u"Nilsson")
906+
author = PersonFactory(user=user)
907+
files = {"txt": submission_file(name, rev, group, "txt", "test_submission.nonascii", author=author) }
908+
909+
r = self.client.post(url, files)
910+
911+
self.assertEqual(r.status_code, 302)
912+
status_url = r["Location"]
913+
r = self.client.get(status_url)
914+
q = PyQuery(r.content)
915+
m = q('p.alert-warning').text()
916+
917+
self.assertIn('The idnits check returned 1 error', m)
918+
919+
876920
class ApprovalsTestCase(TestCase):
877921
def test_approvals(self):
878922
make_test_data()

ietf/submit/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ def edit_submission(request, submission_id, access_token=None):
464464
replaces = replaces_form.cleaned_data.get("replaces", [])
465465
submission.replaces = ",".join(o.name for o in replaces)
466466
submission.authors = "\n".join(f.cleaned_line() for f in author_forms)
467+
if hasattr(submission, '_cached_authors_parsed'):
468+
del submission._cached_authors_parsed
467469
edit_form.save(commit=False) # transfer changes
468470

469471
if submission.rev != prev_submission.rev:

0 commit comments

Comments
 (0)