-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #814: add timestamps to newsletters and waitlists in contact resp…
…onses (#816) * Fix #814: add timestamps to newsletters and waitlists in contact responses * Rewrite datetime comparisons in tests * Add docstring to test helper * Rename Whatever to FuzzyAssert
- Loading branch information
Showing
8 changed files
with
154 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Common test configuration both unit and integration tests. | ||
""" | ||
|
||
from datetime import datetime | ||
|
||
|
||
class FuzzyAssert: | ||
""" | ||
This class is a testing helper that provides flexible equality | ||
of values. | ||
.. code-block:: | ||
>>> FuzzyAssert(lambda x: x.startswith("a")) == "abc" | ||
True | ||
>>> FuzzyAssert(lambda x: x % 2 == 0) == 11 | ||
False | ||
It is mainly used to make sure fields contain valid dates | ||
without having to hardcode values: | ||
.. code-block:: | ||
>>> FuzzyAssert.iso8601() == "2020-01-01" | ||
True | ||
>>> FuzzyAssert.iso8601() == None | ||
False | ||
""" | ||
|
||
def __init__(self, test=lambda x: True, name="unnamed"): | ||
self.test = test | ||
self.name = name | ||
|
||
def __eq__(self, other): | ||
return self.test(other) | ||
|
||
def __repr__(self): | ||
return f"<{self.__class__.__name__}.{self.name}>" | ||
|
||
@classmethod | ||
def iso8601(cls): | ||
def is_iso8601_date(sdate): | ||
if not isinstance(sdate, str): | ||
return False | ||
try: | ||
datetime.fromisoformat(sdate) | ||
return True | ||
except ValueError: | ||
return False | ||
|
||
return cls(is_iso8601_date, name="datetime") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.