refactor into descriptors, cleanup, docs update
This commit is contained in:
@ -55,7 +55,7 @@ class BinaryThing(ormar.Model):
|
||||
bt: bytes = ormar.LargeBinary(
|
||||
max_length=1000,
|
||||
choices=[blob3, blob4, blob5, blob6],
|
||||
represent_as_base64_str=True
|
||||
represent_as_base64_str=True,
|
||||
)
|
||||
|
||||
|
||||
@ -84,5 +84,8 @@ def test_read_main():
|
||||
response = client.post(
|
||||
"/things", data=json.dumps({"bt": base64.b64encode(blob3).decode()})
|
||||
)
|
||||
print(response.content)
|
||||
assert response.status_code == 200
|
||||
response = client.get("/things")
|
||||
assert response.json()[0]["bt"] == base64.b64encode(blob3).decode()
|
||||
thing = BinaryThing(**response.json()[0])
|
||||
assert thing.__dict__["bt"] == blob3
|
||||
|
||||
@ -55,6 +55,7 @@ def test_fields_access():
|
||||
# basic access
|
||||
assert Product.id._field == Product.Meta.model_fields["id"]
|
||||
assert Product.id.id == Product.Meta.model_fields["id"]
|
||||
assert Product.pk.id == Product.id.id
|
||||
assert isinstance(Product.id._field, BaseField)
|
||||
assert Product.id._access_chain == "id"
|
||||
assert Product.id._source_model == Product
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import datetime
|
||||
import os
|
||||
import uuid
|
||||
@ -53,7 +54,7 @@ class LargeBinaryStr(ormar.Model):
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
test_binary: str = ormar.LargeBinary(
|
||||
max_length=100000, choices=[blob3, blob4], represent_as_base64=True
|
||||
max_length=100000, choices=[blob3, blob4], represent_as_base64_str=True
|
||||
)
|
||||
|
||||
|
||||
@ -174,6 +175,9 @@ async def test_json_column():
|
||||
assert items[0].test_json == dict(aa=12)
|
||||
assert items[1].test_json == dict(aa=12)
|
||||
|
||||
items[0].test_json = "[1, 2, 3]"
|
||||
assert items[0].test_json == [1, 2, 3]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_binary_column():
|
||||
@ -187,6 +191,9 @@ async def test_binary_column():
|
||||
assert items[0].test_binary == blob
|
||||
assert items[1].test_binary == blob2
|
||||
|
||||
items[0].test_binary = "test2icac89uc98"
|
||||
assert items[0].test_binary == b"test2icac89uc98"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_binary_str_column():
|
||||
@ -197,8 +204,11 @@ async def test_binary_str_column():
|
||||
|
||||
items = await LargeBinaryStr.objects.all()
|
||||
assert len(items) == 2
|
||||
assert items[0].test_binary == blob3
|
||||
assert items[1].test_binary == blob4
|
||||
assert items[0].test_binary == base64.b64encode(blob3).decode()
|
||||
items[0].test_binary = base64.b64encode(blob4).decode()
|
||||
assert items[0].test_binary == base64.b64encode(blob4).decode()
|
||||
assert items[1].test_binary == base64.b64encode(blob4).decode()
|
||||
assert items[1].__dict__["test_binary"] == blob4
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user