-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e99eca
commit 65defb6
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest import TestCase | ||
import sqlalchemy | ||
from alcherializer import Serializer | ||
|
||
|
||
class TestSerializerData(TestCase): | ||
|
||
def test_data_single_instance(self) -> None: | ||
class MyModel: | ||
name = sqlalchemy.Column(sqlalchemy.String, nullable=False) | ||
|
||
class MySerializer(Serializer): | ||
class Meta: | ||
model = MyModel | ||
|
||
model = MyModel() | ||
model.name = "hello world" | ||
|
||
serializer = MySerializer(model) | ||
self.assertDictEqual(serializer.data, { | ||
"name": "hello world" | ||
}) | ||
|
||
def test_data_multiple_instances(self) -> None: | ||
class MyModel: | ||
name = sqlalchemy.Column(sqlalchemy.String, nullable=False) | ||
|
||
class MySerializer(Serializer): | ||
class Meta: | ||
model = MyModel | ||
|
||
model = MyModel() | ||
model.name = "hello world" | ||
|
||
serializer = MySerializer([model], many=True) | ||
self.assertListEqual(serializer.data, [ | ||
{"name": "hello world"} | ||
]) |