From b425379360438f6fea50d1e69c121ea65827800e Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Mon, 4 Jul 2016 08:53:27 +0800 Subject: [PATCH] Refactoring: remove the duplicate method The method `assertTimestampEqual` which compare two ISO 8601 format time can be used across the testcases, so move the method to core.py and remove the duplicate method. Change-Id: I7bd34380f87da0ee8a52af228f1cf966d90b33c8 Related-Bug: #1598040 --- keystone/tests/unit/core.py | 11 +++++++++++ keystone/tests/unit/test_v3_auth.py | 11 ----------- keystone/tests/unit/test_v3_os_revoke.py | 14 -------------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/keystone/tests/unit/core.py b/keystone/tests/unit/core.py index 74b0e2e384..0eda78dce8 100644 --- a/keystone/tests/unit/core.py +++ b/keystone/tests/unit/core.py @@ -810,6 +810,17 @@ class TestCase(BaseTestCase): self.assertTrue(abs(a - b).seconds <= delta, msg) + def assertTimestampEqual(self, expected, value): + # Compare two timestamps but ignore the microseconds part + # of the expected timestamp. Keystone does not track microseconds and + # is working to eliminate microseconds from it's datetimes used. + expected = timeutils.parse_isotime(expected).replace(microsecond=0) + value = timeutils.parse_isotime(value).replace(microsecond=0) + self.assertEqual( + expected, + value, + "%s != %s" % (expected, value)) + def assertNotEmpty(self, l): self.assertTrue(len(l)) diff --git a/keystone/tests/unit/test_v3_auth.py b/keystone/tests/unit/test_v3_auth.py index a0c251ad7d..88af10d3ea 100644 --- a/keystone/tests/unit/test_v3_auth.py +++ b/keystone/tests/unit/test_v3_auth.py @@ -245,17 +245,6 @@ class TokenAPITests(object): return project - def assertTimestampEqual(self, expected, value): - # Compare two timestamps but ignore the microseconds part - # of the expected timestamp. Keystone does not track microseconds and - # is working to eliminate microseconds from it's datetimes used. - expected = timeutils.parse_isotime(expected).replace(microsecond=0) - value = timeutils.parse_isotime(value).replace(microsecond=0) - self.assertEqual( - expected, - value, - "%s != %s" % (expected, value)) - def test_auth_with_token_as_different_user_fails(self): # get the token for a user. This is self.user which is different from # self.default_domain_user. diff --git a/keystone/tests/unit/test_v3_os_revoke.py b/keystone/tests/unit/test_v3_os_revoke.py index 4a74026d52..502fe1c9e1 100644 --- a/keystone/tests/unit/test_v3_os_revoke.py +++ b/keystone/tests/unit/test_v3_os_revoke.py @@ -38,20 +38,6 @@ class OSRevokeTests(test_v3.RestfulTestCase, test_v3.JsonHomeTestMixin): }, } - # TODO(davechen): This method is copied from `keystone.tests.unit. - # test_v3_auth.TokenAPITests`, move this method into utils.py to avoid - # the duplication? - def assertTimestampEqual(self, expected, value): - # Compare two timestamps but ignore the microseconds part - # of the expected timestamp. Keystone does not track microseconds and - # is working to eliminate microseconds from it's datetimes used. - expected = timeutils.parse_isotime(expected).replace(microsecond=0) - value = timeutils.parse_isotime(value).replace(microsecond=0) - self.assertEqual( - expected, - value, - "%s != %s" % (expected, value)) - def test_get_empty_list(self): resp = self.get('/OS-REVOKE/events') self.assertEqual([], resp.json_body['events'])