bump version, update docs
This commit is contained in:
@ -87,10 +87,10 @@ class User(ormar.Model):
|
||||
database = database
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
email: str = ormar.String(max_length=255, nullable=False)
|
||||
email: str = ormar.String(max_length=255)
|
||||
password: str = ormar.String(max_length=255, nullable=True)
|
||||
first_name: str = ormar.String(max_length=255, nullable=False)
|
||||
last_name: str = ormar.String(max_length=255, nullable=False)
|
||||
first_name: str = ormar.String(max_length=255)
|
||||
last_name: str = ormar.String(max_length=255)
|
||||
category: str = ormar.String(max_length=255, nullable=True)
|
||||
|
||||
|
||||
@ -102,10 +102,13 @@ class User2(ormar.Model):
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
email: str = ormar.String(max_length=255, nullable=False)
|
||||
password: str = ormar.String(max_length=255, nullable=False)
|
||||
first_name: str = ormar.String(max_length=255, nullable=False)
|
||||
last_name: str = ormar.String(max_length=255, nullable=False)
|
||||
password: str = ormar.String(max_length=255)
|
||||
first_name: str = ormar.String(max_length=255)
|
||||
last_name: str = ormar.String(max_length=255)
|
||||
category: str = ormar.String(max_length=255, nullable=True)
|
||||
timestamp: datetime.datetime = ormar.DateTime(
|
||||
pydantic_only=True, default=datetime.datetime.now
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
@ -150,6 +153,12 @@ async def create_user6(user: RandomModel):
|
||||
return user.dict()
|
||||
|
||||
|
||||
@app.post("/random3/", response_model=RandomModel, response_model_exclude={"full_name"})
|
||||
async def create_user7(user: RandomModel):
|
||||
user = await user.save()
|
||||
return user.dict()
|
||||
|
||||
|
||||
def test_excluding_fields_in_endpoints():
|
||||
client = TestClient(app)
|
||||
with client as client:
|
||||
@ -184,6 +193,32 @@ def test_excluding_fields_in_endpoints():
|
||||
response = client.post("/users3/", json=user)
|
||||
assert list(response.json().keys()) == ["email", "first_name", "last_name"]
|
||||
|
||||
timestamp = datetime.datetime.now()
|
||||
|
||||
user3 = {
|
||||
"email": "test@domain.com",
|
||||
"password": "^*^%A*DA*IAAA",
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"timestamp": str(timestamp),
|
||||
}
|
||||
response = client.post("/users4/", json=user3)
|
||||
assert list(response.json().keys()) == [
|
||||
"id",
|
||||
"email",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"category",
|
||||
"timestamp",
|
||||
]
|
||||
assert response.json().get("timestamp") == str(timestamp).replace(" ", "T")
|
||||
resp_dict = response.json()
|
||||
resp_dict.update({"password": "random"})
|
||||
user_instance = User2(**resp_dict)
|
||||
assert user_instance.timestamp is not None
|
||||
assert isinstance(user_instance.timestamp, datetime.datetime)
|
||||
assert user_instance.timestamp == timestamp
|
||||
|
||||
response = client.post("/users4/", json=user)
|
||||
assert list(response.json().keys()) == [
|
||||
"id",
|
||||
@ -191,13 +226,16 @@ def test_excluding_fields_in_endpoints():
|
||||
"first_name",
|
||||
"last_name",
|
||||
"category",
|
||||
"timestamp",
|
||||
]
|
||||
assert response.json().get("timestamp") != str(timestamp).replace(" ", "T")
|
||||
assert response.json().get("timestamp") is not None
|
||||
|
||||
|
||||
def test_adding_fields_in_endpoints():
|
||||
client = TestClient(app)
|
||||
with client as client:
|
||||
user3 = {"last_name": "Test"}
|
||||
user3 = {"last_name": "Test", "full_name": "deleted"}
|
||||
response = client.post("/random/", json=user3)
|
||||
assert list(response.json().keys()) == [
|
||||
"id",
|
||||
@ -238,3 +276,19 @@ def test_adding_fields_in_endpoints2():
|
||||
"full_name",
|
||||
]
|
||||
assert response.json().get("full_name") == "John Test"
|
||||
|
||||
|
||||
def test_excluding_property_field_in_endpoints2():
|
||||
client = TestClient(app)
|
||||
with client as client:
|
||||
RandomModel.Meta.include_props_in_dict = True
|
||||
user3 = {"last_name": "Test"}
|
||||
response = client.post("/random3/", json=user3)
|
||||
assert list(response.json().keys()) == [
|
||||
"id",
|
||||
"password",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"created_date",
|
||||
]
|
||||
assert response.json().get("full_name") is None
|
||||
|
||||
Reference in New Issue
Block a user