Skip to content

Commit

Permalink
Fixed tests for datetime fields
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibling committed Dec 31, 2023
1 parent 505c338 commit aa806fa
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import faker

from datetime import datetime

import src.sshkey_tools.cert as _CERT
import src.sshkey_tools.exceptions as _EX
import src.sshkey_tools.fields as _FIELD
Expand Down Expand Up @@ -46,7 +48,7 @@ def assertRandomResponse(self, field_class, values=None, random_function=None):
decode, bytestring = field_class.decode(bytestring)
decoded.append(decode)

self.assertEqual(decoded, values)
self.assertEqual(values, decoded)

def assertExpectedResponse(self, field_class, input, expected_output):
self.assertEqual(field_class.encode(input), expected_output)
Expand Down Expand Up @@ -143,7 +145,7 @@ def test_invalid_integer64_field(self):

def test_datetime_field(self):
self.assertRandomResponse(
_FIELD.DateTimeField, random_function=lambda: self.faker.date_time()
_FIELD.DateTimeField, random_function=lambda: datetime.fromtimestamp(int(self.faker.date_time().timestamp()))
)

def test_invalid_datetime_field(self):
Expand Down Expand Up @@ -402,7 +404,7 @@ def test_invalid_principals_field(self):

def test_validity_start_field(self):
self.assertRandomResponse(
_FIELD.ValidAfterField, random_function=lambda: self.faker.date_time()
_FIELD.ValidAfterField, random_function=lambda: datetime.fromtimestamp(int(self.faker.date_time().timestamp()))
)

def test_invalid_validity_start_field(self):
Expand All @@ -416,7 +418,7 @@ def test_invalid_validity_start_field(self):

def test_validity_end_field(self):
self.assertRandomResponse(
_FIELD.ValidBeforeField, random_function=lambda: self.faker.date_time()
_FIELD.ValidBeforeField, random_function=lambda: datetime.fromtimestamp(int(self.faker.date_time().timestamp()))
)

def test_invalid_validity_end_field(self):
Expand Down

0 comments on commit aa806fa

Please sign in to comment.