Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass last_login_at to user crud UI from backend API correctly (#133)
* Pass last_login_at to user crud from backend API correctly, so it displays in UI. * Make naturalized_datetime_str more robust for non-naive dt input. Co-authored-by: F.N. Claessen <felix@seita.nl>
- Loading branch information
Showing
9 changed files
with
110 additions
and
33 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
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,43 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import pytz | ||
import pytest | ||
|
||
from flexmeasures.utils.time_utils import ( | ||
server_now, | ||
naturalized_datetime_str, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dt_tz,now,server_tz,delta_in_h,exp_result", | ||
[ | ||
(None, datetime.utcnow(), "UTC", 3, "3 hours ago"), | ||
(None, datetime(2021, 5, 17, 3), "Europe/Amsterdam", 48, "May 15"), | ||
("Asia/Seoul", "server_now", "Europe/Amsterdam", 1, "an hour ago"), | ||
("UTC", datetime(2021, 5, 17, 3), "Asia/Seoul", 24 * 7, "May 10"), | ||
("UTC", datetime(2021, 5, 17, 3), "Asia/Seoul", None, "never"), | ||
], | ||
) | ||
def test_naturalized_datetime_str( | ||
app, | ||
monkeypatch, | ||
dt_tz, | ||
now, | ||
server_tz, | ||
delta_in_h, | ||
exp_result, | ||
): | ||
monkeypatch.setitem(app.config, "FLEXMEASURES_TIMEZONE", server_tz) | ||
if now == "server_now": | ||
now = server_now() # done this way as it needs app context | ||
if now.tzinfo is None: | ||
now.replace(tzinfo=pytz.utc) # assuming UTC | ||
if delta_in_h is not None: | ||
h_ago = now - timedelta(hours=delta_in_h) | ||
if dt_tz is not None: | ||
h_ago = h_ago.astimezone(pytz.timezone(dt_tz)) | ||
else: | ||
h_ago = None | ||
print(h_ago) | ||
assert naturalized_datetime_str(h_ago, now=now) == exp_result |
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