def test_user_drink(): user = User("TEST", 2, time(8, 0, 0), time(18, 0, 0)) now = datetime.now() user.drink() assert user.last_drink < user.next_drink assert user.last_drink.date() == now.date() # date assert user.last_drink.strftime("%H") == now.strftime("%H") # hour assert user.last_drink.strftime("%M") == now.strftime("%M") # minute
def test_get_user_data_as_json(): user = User("TEST", 2, time(8, 0, 0), time(18, 0, 0)) expected_json = { "user_id": "TEST", "water": 2, "start": "08:00:00", "end": "18:00:00" } assert expected_json == user.getDataAsDict()
def test_set_next_drink_time_on_user_init(): user = User("TEST", 2, time(8, 0, 0), time(18, 0, 0)) first_drink = user.next_drink expect_date = datetime.now() + timedelta(minutes=int(600 / 8)) assert user.next_drink.date() == expect_date.date() # date assert user.next_drink.strftime("%H") == expect_date.strftime("%H") # hour assert user.next_drink.strftime("%M") == expect_date.strftime( "%M") # minute
def test_update_user_water(): liters = 4 user = User("TEST", liters, time(8, 0, 0), time(18, 0, 0)) actual_date = user.next_drink expect_date = datetime.now() + timedelta(minutes=int(600 / (liters * 4))) assert actual_date.date() == expect_date.date() # date assert actual_date.strftime("%H") == expect_date.strftime("%H") # hour assert actual_date.strftime("%M") == expect_date.strftime("%M") # minute
def test_user_delta_time(): user_id = "TEST" user = User(user_id, 8, time(8, 0, 0), time(18, 0, 0)) assert user.deltaTime() == 600 user = User(user_id, 8, time(8, 0, 0), time(8, 30, 0)) assert user.deltaTime() == 30
def test_refactoring_user_timeframe(): user = User("TEST", 2, time(8, 1, 0), time(18, 2, 0)) assert user.start == time(8, 1, 0) assert user.end == time(18, 2, 0)
def test_update_user_water_high_value(): liters = 20 user = User("TEST", liters, time(8, 0, 0), time(18, 0, 0)) assert user.water == liters assert user.glass == 20 * 4