This repository has been archived by the owner on Aug 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[types] make load_into a classmethod, add testing for types
- Loading branch information
1 parent
25f1b2d
commit 359795e
Showing
2 changed files
with
37 additions
and
3 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,33 @@ | ||
from unittest import TestCase | ||
from disco.types.base import Model, Field | ||
|
||
|
||
class _M(Model): | ||
a = Field(int) | ||
b = Field(float) | ||
c = Field(str) | ||
|
||
|
||
class TestModel(TestCase): | ||
def test_model_simple_loading(self): | ||
inst = _M(dict(a=1, b=1.1, c='test')) | ||
self.assertEquals(inst.a, 1) | ||
self.assertEquals(inst.b, 1.1) | ||
self.assertEquals(inst.c, 'test') | ||
|
||
def test_model_load_into(self): | ||
inst = _M() | ||
_M.load_into(inst, dict(a=1, b=1.1, c='test')) | ||
self.assertEquals(inst.a, 1) | ||
self.assertEquals(inst.b, 1.1) | ||
self.assertEquals(inst.c, 'test') | ||
|
||
def test_model_loading_consume(self): | ||
obj = dict(a=5, b=33.33, c='wtf') | ||
inst = _M() | ||
inst.load(obj, consume=True) | ||
|
||
self.assertEquals(obj, {}) | ||
self.assertEquals(inst.a, 5) | ||
self.assertEquals(inst.b, 33.33) | ||
self.assertEquals(inst.c, 'wtf') |