Skip to content

Commit

Permalink
Merge pull request #13 from ueckoken/timedelta
Browse files Browse the repository at this point in the history
use timedelta instead of primitive int
  • Loading branch information
otariidae authored Aug 21, 2023
2 parents f7732a8 + aeded58 commit cf7f152
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions KM4K.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
import time
from datetime import timedelta

import nfc
import redis
Expand All @@ -17,7 +18,7 @@


# 有効期間1週間
CACHE_EXPIRES_SECONDS = 60 * 60 * 24 * 7
CACHE_EXPIRES_DELTA = timedelta(weeks=1)


def read_nfc():
Expand All @@ -44,7 +45,7 @@ def start_system(isopen, okled_pin, ngled_pin, cache: redis.Redis, card: CardSDK
if is_registered_sso:
# 有効期限付きでRedisに保存
# 値は今のところ使わないので適当に1にしておいた
cache.set(idm.decode(), 1, ex=CACHE_EXPIRES_SECONDS)
cache.set(idm.decode(), 1, ex=CACHE_EXPIRES_DELTA)
verified = True
if verified:
print("Registered (idm:" + idm.decode() + ")")
Expand Down
3 changes: 2 additions & 1 deletion test_KM4K.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import contextlib
import os
import time
from datetime import timedelta
from unittest import TestCase
from unittest.mock import Mock, create_autospec, patch

Expand Down Expand Up @@ -180,7 +181,7 @@ def test_start_system_unregistered_card_with_redis_cache(
mocked_servo.lock.assert_called_once()
card.verify.assert_called_once()

@patch("KM4K.CACHE_EXPIRES_SECONDS", 5)
@patch("KM4K.CACHE_EXPIRES_DELTA", timedelta(seconds=5))
@patch("KM4K.servo", autospec=True)
@patch("KM4K.read_nfc", side_effect=[b"456789", b"456789", InterruptedError])
def test_start_system_with_redis_cache_expires(
Expand Down

0 comments on commit cf7f152

Please sign in to comment.