Merge "Fixup failing tests due to passing date threshold"

This commit is contained in:
Zuul 2020-09-10 17:12:23 +00:00 committed by Gerrit Code Review
commit 5473d56736
2 changed files with 15 additions and 2 deletions

View File

@ -14,6 +14,7 @@
# limitations under the License.
import argparse
from datetime import datetime
import mock
from blazarclient import exception
@ -21,11 +22,13 @@ from blazarclient import shell
from blazarclient import tests
from blazarclient.v1.shell_commands import leases
mock_time = mock.Mock(return_value=datetime(2020, 6, 8))
FIRST_LEASE = 'd1e43d6d-8f6f-4c2e-b0a9-2982b39dc698'
SECOND_LEASE = '424d21c3-45a2-448a-81ad-32eddc888375'
@mock.patch('blazarclient.v1.shell_commands.leases._utc_now', mock_time)
class CreateLeaseTestCase(tests.TestCase):
def setUp(self):

View File

@ -58,6 +58,16 @@ CREATE_RESERVATION_KEYS = {
}
def _utc_now():
"""Wrap datetime.datetime.utcnow so it can be mocked in unit tests.
This is required because some of the tests require understanding the
'current time'; simply mocking utcnow() is made very difficult by
the many different ways the datetime package is used in this module.
"""
return datetime.datetime.utcnow()
class ListLeases(command.ListCommand):
"""Print a list of leases."""
resource = 'lease'
@ -87,7 +97,7 @@ class CreateLease(command.CreateCommand):
json_indent = 4
log = logging.getLogger(__name__ + '.CreateLease')
default_start = 'now'
default_end = datetime.datetime.utcnow() + datetime.timedelta(days=1)
default_end = _utc_now() + datetime.timedelta(days=1)
def get_parser(self, prog_name):
parser = super(CreateLease, self).get_parser(prog_name)
@ -203,7 +213,7 @@ class CreateLease(command.CreateCommand):
raise exception.IncorrectLease
if parsed_args.start == 'now':
start = datetime.datetime.utcnow()
start = _utc_now()
else:
start = parsed_args.start