mirror of
https://github.com/certbot/certbot.git
synced 2026-07-31 18:25:24 +02:00
RegistrationResource: return any phone/email from phones/emails or None.
This commit is contained in:
+18
-6
@@ -182,15 +182,27 @@ class Registration(ResourceBody):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def phone(self):
|
def phone(self):
|
||||||
"""Phone."""
|
"""Phone.
|
||||||
assert len(self.phones) == 1
|
|
||||||
return self.phones[0]
|
Picks any phone from `phones` or ``None`` if not available.
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return self.phones[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def email(self):
|
def email(self):
|
||||||
"""Email."""
|
"""Email.
|
||||||
assert len(self.emails) == 1
|
|
||||||
return self.emails[0]
|
Picks any email from `emails` or ``None`` if not available.
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return self.emails[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class RegistrationResource(ResourceWithURI):
|
class RegistrationResource(ResourceWithURI):
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ class RegistrationTest(unittest.TestCase):
|
|||||||
self.reg = Registration(
|
self.reg = Registration(
|
||||||
key=key, contact=contact, recovery_token=recovery_token,
|
key=key, contact=contact, recovery_token=recovery_token,
|
||||||
agreement=agreement)
|
agreement=agreement)
|
||||||
|
self.reg_none = Registration()
|
||||||
|
|
||||||
self.jobj_to = {
|
self.jobj_to = {
|
||||||
'contact': contact,
|
'contact': contact,
|
||||||
@@ -149,9 +150,15 @@ class RegistrationTest(unittest.TestCase):
|
|||||||
def test_phone(self):
|
def test_phone(self):
|
||||||
self.assertEqual('1234', self.reg.phone)
|
self.assertEqual('1234', self.reg.phone)
|
||||||
|
|
||||||
|
def test_phone_none(self):
|
||||||
|
self.assertTrue(self.reg_none.phone is None)
|
||||||
|
|
||||||
def test_email(self):
|
def test_email(self):
|
||||||
self.assertEqual('admin@foo.com', self.reg.email)
|
self.assertEqual('admin@foo.com', self.reg.email)
|
||||||
|
|
||||||
|
def test_email_none(self):
|
||||||
|
self.assertTrue(self.reg_none.email is None)
|
||||||
|
|
||||||
def test_to_partial_json(self):
|
def test_to_partial_json(self):
|
||||||
self.assertEqual(self.jobj_to, self.reg.to_partial_json())
|
self.assertEqual(self.jobj_to, self.reg.to_partial_json())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user