Skip to main content
added 319 characters in body
Source Link
l0b0
  • 468
  • 2
  • 9

You can pass the "now" time into the function which verifies the expiry (and obviously also the function which creates the credentials). The test function calls it with a hard-coded time, and the production function calls it with the actual current time. For example (untested):

def validate_expirycredentials_valid(credentials, now):
    return credentials.expiry > now

def test_should_return_false_for_expired_credentials(self):
    now = datetime(year=2000, month=1, date=1)
    future = now + timedelta(second=1)
    credentials = create_credentials(now)
    self.assertFalse(credentials_valid(credentials, now))

You can pass the "now" time into the function which verifies the expiry (and obviously also the function which creates the credentials). The test function calls it with a hard-coded time, and the production function calls it with the actual current time. For example:

def validate_expiry(credentials, now):
    return credentials.expiry > now

You can pass the "now" time into the function which verifies the expiry (and obviously also the function which creates the credentials). The test function calls it with a hard-coded time, and the production function calls it with the actual current time. For example (untested):

def credentials_valid(credentials, now):
    return credentials.expiry > now

def test_should_return_false_for_expired_credentials(self):
    now = datetime(year=2000, month=1, date=1)
    future = now + timedelta(second=1)
    credentials = create_credentials(now)
    self.assertFalse(credentials_valid(credentials, now))
Source Link
l0b0
  • 468
  • 2
  • 9

You can pass the "now" time into the function which verifies the expiry (and obviously also the function which creates the credentials). The test function calls it with a hard-coded time, and the production function calls it with the actual current time. For example:

def validate_expiry(credentials, now):
    return credentials.expiry > now