Fix last_login_at default value

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-04 12:57:11 -03:00
commit bf76ba660f
2 changed files with 13 additions and 30 deletions

View file

@ -19,7 +19,7 @@ class User(SQLModel, table=True):
is_superuser: bool = Field(default=False)
create_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(default_factory=datetime.utcnow)
last_login_at: Optional[datetime] = Field(nullable=True)
last_login_at: Optional[datetime] = Field(default=None, nullable=True)
api_keys: list["ApiKey"] = Relationship(
back_populates="user",
sa_relationship_kwargs={"cascade": "delete"},

View file

@ -1,6 +1,7 @@
from datetime import datetime
import pytest
from langflow.services.auth.utils import create_super_user, get_password_hash
from langflow.services.database.models.user import UserUpdate
from langflow.services.database.models.user.model import User
@ -116,7 +117,7 @@ def test_inactive_user(client):
username="inactiveuser",
password=get_password_hash("testpassword"),
is_active=False,
last_login_at="2023-01-01T00:00:00", # Set to a valid datetime string
last_login_at=datetime.now(),
)
session.add(user)
session.commit()
@ -199,20 +200,11 @@ def test_patch_user_wrong_id(client, active_user, logged_in_headers):
response = client.patch(f"/api/v1/users/{user_id}", json=update_data.model_dump(), headers=logged_in_headers)
assert response.status_code == 422, response.json()
assert response.json() == {
"detail": [
{
"type": "uuid_parsing",
"loc": ["path", "user_id"],
"msg": "Input should be a valid UUID, invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `w` at 1", # noqa
"input": "wrong_id",
"ctx": {
"error": "invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `w` at 1" # noqa
},
"url": "https://errors.pydantic.dev/2.4/v/uuid_parsing",
}
]
}
json_response = response.json()
detail = json_response["detail"]
assert detail[0]["type"] == "uuid_parsing"
assert detail[0]["loc"] == ["path", "user_id"]
assert detail[0]["input"] == "wrong_id"
def test_delete_user(client, test_user, super_user_headers):
@ -226,20 +218,11 @@ def test_delete_user_wrong_id(client, test_user, super_user_headers):
user_id = "wrong_id"
response = client.delete(f"/api/v1/users/{user_id}", headers=super_user_headers)
assert response.status_code == 422
assert response.json() == {
"detail": [
{
"type": "uuid_parsing",
"loc": ["path", "user_id"],
"msg": "Input should be a valid UUID, invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `w` at 1", # noqa
"input": "wrong_id",
"ctx": {
"error": "invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-fA-F-], found `w` at 1" # noqa
},
"url": "https://errors.pydantic.dev/2.4/v/uuid_parsing",
}
]
}
json_response = response.json()
detail = json_response["detail"]
assert detail[0]["type"] == "uuid_parsing"
assert detail[0]["loc"] == ["path", "user_id"]
assert detail[0]["input"] == "wrong_id"
def test_normal_user_cant_delete_user(client, test_user, logged_in_headers):