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