8000 Handle null dates returned from the API. · Stackdriver/twilio-python@38a6b6e · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.

Commit 38a6b6e

Browse files
author
Kevin Burke
committed
Handle null dates returned from the API.
1 parent 000cb31 commit 38a6b6e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

tests/test_base_resource.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest2 as unittest
88

99
from mock import Mock
10-
from nose.tools import assert_equal, assert_true
10+
from nose.tools import assert_equal, assert_true, assert_is_none
1111
from twilio.rest.resources import Resource
1212
from twilio.rest.resources import ListResource
1313
from twilio.rest.resources import InstanceResource
@@ -115,6 +115,10 @@ def testLoadDateCreated(self):
115115
except AttributeError:
116116
pass
117117

118+
def testLoadNullDate(self):
119+
self.r.load({"date_created": None, "uri": "foobar"})
120+
assert_is_none(self.r.date_created)
121+
118122
def testLoadWithFrom(self):
119123
self.r.load({"from": "foo"})
120124
self.assertEquals(self.r.from_, "foo")

twilio/rest/resources/util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ def parse_date(d):
4646
def parse_rfc2822_date(s):
4747
"""
4848
Parses an RFC 2822 date string and returns a time zone naive datetime
49-
object. It is assumed that all dates returned from Twilio are UTC.
49+
object. All dates returned from Twilio are UTC.
5050
"""
51-
return datetime.datetime(*parsedate(s)[:6])
51+
date_tuple = parsedate(s)
52+
if date_tuple is None:
53+
return None
54+
return datetime.datetime(date_tuple[:6])
5255

5356

5457
def convert_boolean(boolean):

0 commit comments

Comments
 (0)
0