def test_get_user_from_token(session): user = User() user.get_token() session.add(user) session.commit() assert get_user_from_token(session, user.token) == user
def test_get_user_from_wrong_token(session): user = User() user.get_token() session.add(user) session.commit() assert get_user_from_token(session, "foo") is None
def test_get_expired_token(): now = datetime.datetime.utcnow() user = User() t1 = user.get_token() user.token_expires = now - datetime.timedelta(seconds=1) t2 = user.get_token() assert t1 != t2 assert t2 == user.token
def test_get_user_from_expired_token(session): now = datetime.datetime.utcnow() user = User() user.get_token() user.token_expires = now - datetime.timedelta(seconds=1) session.add(user) session.commit() assert get_user_from_token(session, user.token) is None
def test_get_items_for_user(session): u1 = User(id=1) u2 = User(id=2) session.add_all( [ u1, u2, Item(id=1, user=u1), Item(id=2, user=u2), ] ) items = get_items_for_user(session, u1).all() assert len(items) == 1 and items[0].id == 1
def test_get_authenticated_user_long_password(session, password_hash): user = User(username="******", password_hash=password_hash) session.add(user) session.commit() authenticated_user = get_authenticated_user(session, username="******", password="******" * 65) assert authenticated_user is None
def test_get_authenticated_user(session, password_hash): user = User(username="******", password_hash=password_hash) session.add(user) session.commit() authenticated_user = get_authenticated_user(session, username="******", password="******") assert authenticated_user == user
def test_login_with_long_password(flask_anonymous_client, session, password_hash): user = User(username="******", password_hash=password_hash) session.add(user) session.commit() response = flask_anonymous_client.post(url_for("login"), data={ "username": "******", "password": "******" * 65 }) assert response.status_code == 200
def test_register_existing_username(flask_anonymous_client, session): session.add(User(username="******")) session.commit() response = flask_anonymous_client.post( url_for("register"), data={ "username": "******", "password": "******", "repeat_password": "******", }, ) assert response.status_code == 200 assert b"Dieser Name existiert bereits." in response.data
def test_include_inactive_items(session): user = User(id=1) session.add_all( [ user, Item(id=1, user=user), Item(id=2, user=user, next_iteration=datetime.datetime.utcnow()), Item( id=3, user=user, next_iteration=datetime.datetime.utcnow(), is_active=False, ), ] ) items = get_items_for_user(session, user, include_inactive=True).all() assert len(items) == 3
def test_get_items_sorted_by_due_date(session): user = User(id=1) session.add_all( [ user, Item( id=1, user=user, next_iteration=datetime.datetime.utcnow() + datetime.timedelta(days=10), ), Item( id=2, user=user, next_iteration=datetime.datetime.utcnow() + datetime.timedelta(days=1), ), ] ) items = get_items_for_user(session, user).all() assert [x.id for x in items] == [2, 1]
def test_get_todo_items(session): user = User(id=1) session.add_all( [ user, Item(id=1, user=user, next_iteration=None), Item( id=2, user=user, next_iteration=datetime.datetime.utcnow() - datetime.timedelta(seconds=1), ), Item( id=3, user=user, next_iteration=datetime.datetime.utcnow() + datetime.timedelta(days=1), ), ] ) items = get_items_for_user(session, user, todo=True).all() assert [x.id for x in items] == [1, 2]
def test_train_view_cycles_through_pending_items(flask_client, session): url = url_for("train") now = datetime.datetime.utcnow() session.add_all([ Item( user_id=1, word="barbazfoo", next_iteration=now - datetime.timedelta(days=2), ), Item( user_id=1, word="bazfoobar", next_iteration=now - datetime.timedelta(days=1), ), User(id=2), Item( user_id=2, # this item should be skipped! word="foobarbaz", next_iteration=now - datetime.timedelta(days=3), ), ]) session.commit() response = flask_client.get(url) assert b"barbazfoo" in response.data assert b"foobarbaz" not in response.data response = flask_client.post(url, data={"grade": "5"}) assert response.status_code == 302 response = flask_client.get(url) assert b"bazfoobar" in response.data assert b"foobarbaz" not in response.data response = flask_client.post(url, data={"grade": "5"}) assert response.status_code == 302 response = flask_client.get(url) assert b"foobarbaz" not in response.data
def test_get_token(): user = User() user.get_token() assert user.token is not None assert user.token_expires is not None