Replace parse_strtime with datetime.strptime

This change switches the use of parse_strtime to datetime.strptime since
oslo.utils parse_strtime simply calls strptime from the datetime library[0],
which keystone already uses.

[0] https://github.com/openstack/oslo.utils/blob/master/oslo_utils/timeutils.py#L97

Change-Id: I9d428d16bfe5ed83a9ff441725c293576a11e09d
This commit is contained in:
Gage Hugo 2017-12-21 12:11:35 -06:00
parent 6d5fe4828f
commit 7e102514c7
2 changed files with 5 additions and 7 deletions

View File

@ -12,8 +12,6 @@
import datetime
from oslo_utils import timeutils
import keystone.tests.unit as tests
@ -21,13 +19,13 @@ class TestTimeUtils(tests.BaseTestCase):
def test_parsing_date_strings_returns_a_datetime(self):
example_date_str = '2015-09-23T04:45:37.196621Z'
dt = timeutils.parse_strtime(example_date_str, fmt=tests.TIME_FORMAT)
dt = datetime.datetime.strptime(example_date_str, tests.TIME_FORMAT)
self.assertIsInstance(dt, datetime.datetime)
def test_parsing_invalid_date_strings_raises_a_ValueError(self):
example_date_str = ''
simple_format = '%Y'
self.assertRaises(ValueError,
timeutils.parse_strtime,
datetime.datetime.strptime,
example_date_str,
fmt=simple_format)
simple_format)

View File

@ -12,11 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import uuid
import oslo_context.context
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from six.moves import http_client
from testtools import matchers
import webtest
@ -549,7 +549,7 @@ class RestfulTestCase(unit.SQLDriverOverrides, rest.RestfulTestCase,
def assertValidISO8601ExtendedFormatDatetime(self, dt):
try:
return timeutils.parse_strtime(dt, fmt=TIME_FORMAT)
return datetime.datetime.strptime(dt, TIME_FORMAT)
except Exception:
msg = '%s is not a valid ISO 8601 extended format date time.' % dt
raise AssertionError(msg)