Skip to content

Commit 1155fb3

Browse files
Accept 'None' when updating DocumentAuthor affiliation / country. Commit ready for merge.
- Legacy-Id: 19028
1 parent 43321f1 commit 1155fb3

File tree

5 files changed

+470
-9
lines changed

5 files changed

+470
-9
lines changed

ietf/doc/tests_utils.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Copyright The IETF Trust 2020, All Rights Reserved
22
import datetime
33

4+
from django.db import IntegrityError
5+
46
from ietf.group.factories import GroupFactory, RoleFactory
57
from ietf.name.models import DocTagName
68
from ietf.person.factories import PersonFactory
79
from ietf.utils.test_utils import TestCase
810
from ietf.person.models import Person
911
from ietf.doc.factories import DocumentFactory
10-
from ietf.doc.models import State, DocumentActionHolder
11-
from ietf.doc.utils import update_action_holders, add_state_change_event
12+
from ietf.doc.models import State, DocumentActionHolder, DocumentAuthor
13+
from ietf.doc.utils import update_action_holders, add_state_change_event, update_documentauthors
1214

1315

1416
class ActionHoldersTests(TestCase):
@@ -204,4 +206,36 @@ def test_doc_action_holders_enabled(self):
204206

205207
for state in State.objects.filter(type='draft-iesg').exclude(slug='idexists'):
206208
doc.set_state(state)
207-
self.assertTrue(doc.action_holders_enabled())
209+
self.assertTrue(doc.action_holders_enabled())
210+
211+
212+
class MiscTests(TestCase):
213+
def test_update_documentauthors_with_nulls(self):
214+
"""A 'None' value in the affiliation/country should be handled correctly"""
215+
author_person = PersonFactory()
216+
doc = DocumentFactory(authors=[author_person])
217+
doc.documentauthor_set.update(
218+
affiliation='Some Affiliation', country='USA'
219+
)
220+
try:
221+
events = update_documentauthors(
222+
doc,
223+
[
224+
DocumentAuthor(
225+
person=author_person,
226+
email=author_person.email(),
227+
affiliation=None,
228+
country=None,
229+
)
230+
],
231+
)
232+
except IntegrityError as err:
233+
self.fail('IntegrityError was raised: {}'.format(err))
234+
235+
self.assertEqual(len(events), 1)
236+
self.assertEqual(events[0].type, 'edited_authors')
237+
self.assertIn('cleared affiliation (was "Some Affiliation")', events[0].desc)
238+
self.assertIn('cleared country (was "USA")', events[0].desc)
239+
docauth = doc.documentauthor_set.first()
240+
self.assertEqual(docauth.affiliation, '')
241+
self.assertEqual(docauth.country, '')

ietf/doc/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def _change_field_and_describe(auth, field, newval):
535535
setattr(auth, field, newval)
536536

537537
was_empty = oldval is None or len(str(oldval)) == 0
538-
now_empty = newval is None or len(str(oldval)) == 0
538+
now_empty = newval is None or len(str(newval)) == 0
539539

540540
# describe the change
541541
if oldval == newval:
@@ -566,8 +566,8 @@ def _change_field_and_describe(auth, field, newval):
566566
author_changes = []
567567
# Now fill in other author details
568568
author_changes.append(_change_field_and_describe(auth, 'email', docauthor.email))
569-
author_changes.append(_change_field_and_describe(auth, 'affiliation', docauthor.affiliation))
570-
author_changes.append(_change_field_and_describe(auth, 'country', docauthor.country))
569+
author_changes.append(_change_field_and_describe(auth, 'affiliation', docauthor.affiliation or ''))
570+
author_changes.append(_change_field_and_describe(auth, 'country', docauthor.country or ''))
571571
author_changes.append(_change_field_and_describe(auth, 'order', order + 1))
572572
auth.save()
573573
log.assertion('auth.email_id != "none"')
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
2+
3+
4+
5+
Network Working Group %(initials)s %(surname)s
6+
Internet-Draft
7+
Intended status: Informational %(month)s %(year)s
8+
Expires: %(expiration)s
9+
10+
11+
%(title)s
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+
Name 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. Yang . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
65+
3. JSON example . . . . . . . . . . . . . . . . . . . . . . . . 2
66+
4. Security Considerations . . . . . . . . . . . . . . . . . . . 2
67+
5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 2
68+
6. References . . . . . . . . . . . . . . . . . . . . . . . . . 2
69+
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 2
70+
71+
1. Introduction
72+
73+
This document describes a protocol for testing tests.
74+
75+
2. Yang
76+
77+
<CODE BEGINS> file "ietf-yang-metadata@2016-08-05.yang"
78+
79+
module ietf-yang-metadata {
80+
81+
namespace "urn:ietf:params:xml:ns:yang:ietf-yang-metadata";
82+
83+
prefix "md";
84+
85+
organization
86+
"IETF NETMOD (NETCONF Data Modeling Language) Working Group";
87+
88+
contact
89+
"WG Web: <https://datatracker.ietf.org/wg/netmod/>
90+
91+
WG List: <mailto:netmod@ietf.org>
92+
93+
WG Chair: Lou Berger
94+
<mailto:lberger@labn.net>
95+
96+
WG Chair: Kent Watsen
97+
<mailto:kwatsen@juniper.net>
98+
99+
Editor: Ladislav Lhotka
100+
<mailto:lhotka@nic.cz>";
101+
102+
description
103+
"This YANG module defines an 'extension' statement that allows
104+
for defining metadata annotations.
105+
106+
Copyright (c) 2016 IETF Trust and the persons identified as
107+
authors of the code. All rights reserved.
108+
109+
Redistribution and use in source and binary forms, with or
110+
without modification, is permitted pursuant to, and subject to
111+
the license terms contained in, the Simplified BSD License set
112+
forth in Section 4.c of the IETF Trust's Legal Provisions
113+
Relating to IETF Documents
114+
(http://trustee.ietf.org/license-info).
115+
116+
This version of this YANG module is part of RFC 7952
117+
(http://www.rfc-editor.org/info/rfc7952); see the RFC itself
118+
for full legal notices.";
119+
120+
revision 2016-08-05 {
121+
description
122+
"Initial revision.";
123+
reference
124+
"RFC 7952: Defining and Using Metadata with YANG";
125+
}
126+
127+
extension annotation {
128+
argument name;
129+
description
130+
"This extension allows for defining metadata annotations in
131+
YANG modules. The 'md:annotation' statement can appear only
132+
at the top level of a YANG module or submodule, i.e., it
133+
becomes a new alternative in the ABNF production rule for
134+
'body-stmts' (Section 14 in RFC 7950).
135+
136+
The argument of the 'md:annotation' statement defines the name
137+
of the annotation. Syntactically, it is a YANG identifier as
138+
defined in Section 6.2 of RFC 7950.
139+
140+
An annotation defined with this 'extension' statement inherits
141+
the namespace and other context from the YANG module in which
142+
it is defined.
143+
144+
The data type of the annotation value is specified in the same
145+
way as for a leaf data node using the 'type' statement.
146+
147+
The semantics of the annotation and other documentation can be
148+
specified using the following standard YANG substatements (all
149+
are optional): 'description', 'if-feature', 'reference',
150+
'status', and 'units'.
151+
152+
A server announces support for a particular annotation by
153+
including the module in which the annotation is defined among
154+
the advertised YANG modules, e.g., in a NETCONF <hello>
155+
message or in the YANG library (RFC 7950). The annotation can
156+
then be attached to any instance of a data node defined in any
157+
YANG module that is advertised by the server.
158+
159+
XML encoding and JSON encoding of annotations are defined in
160+
RFC 7952.";
161+
}
162+
}
163+
164+
<CODE ENDS>
165+
166+
3. JSON example
167+
168+
The JSON object should look like this:
169+
170+
{
171+
"test": 1234
172+
}
173+
174+
4. Security Considerations
175+
176+
There are none.
177+
178+
5. IANA Considerations
179+
180+
No new registrations for IANA.
181+
182+
[RFC8175] is mentioned here in order to give the reference
183+
classification code a chance to mess up.
184+
185+
186+
6. References
187+
188+
6.1. Normative References
189+
190+
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
191+
Requirement Levels", BCP 14, RFC 2119,
192+
DOI 10.17487/RFC2119, March 1997,
193+
<https://www.rfc-editor.org/info/rfc2119>.
194+
195+
[RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC
196+
2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174,
197+
May 2017, <https://www.rfc-editor.org/info/rfc8174>.
198+
199+
6.2. Informative References
200+
201+
[RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for
202+
Writing an IANA Considerations Section in RFCs", BCP 26,
203+
RFC 8126, DOI 10.17487/RFC8126, June 2017,
204+
<https://www.rfc-editor.org/info/rfc8126>.
205+
206+
[RFC8175] Ratliff, S., Jury, S., Satterwhite, D., Taylor, R., and B.
207+
Berry, "Dynamic Link Exchange Protocol (DLEP)", RFC 8175,
208+
DOI 10.17487/RFC8175, June 2017,
209+
<https://www.rfc-editor.org/info/rfc8175>.
210+
211+
Author's Address
212+
213+
%(author)s
214+
215+
Email: %(email)s
216+
217+
218+
219+
Appendix A. Comments
220+
221+
[RFC8174] is mentioned here just to give the reference classification
222+
code a chance to mess up.
223+
224+
225+
226+
227+
228+
229+
230+
231+
232+
233+
234+
235+
236+
237+
238+
239+
240+
241+
242+
243+
Name Expires %(expiration)s [Page 2]

0 commit comments

Comments
 (0)