def test_getdict(): class TestCls: a = 1 b: int def __init__(self): self.c = 3 @property def d(self): return 4 def __getattr__(self, key): if key == 'e': return 5 else: raise AttributeError() t = TestCls() gd = GetterDict(t) assert gd.keys() == set() assert gd.get('a', None) == 1 assert gd.get('b', None) is None assert gd.get('b', 1234) == 1234 assert gd.get('c', None) == 3 assert gd.get('d', None) == 4 assert gd.get('e', None) == 5 assert gd.get('f', 'missing') == 'missing'
def test_getdict(): class TestCls: a = 1 b: int def __init__(self): self.c = 3 @property def d(self): return 4 def __getattr__(self, key): if key == 'e': return 5 else: raise AttributeError() t = TestCls() gd = GetterDict(t) assert gd.keys() == ['a', 'c', 'd'] assert gd.get('a', None) == 1 assert gd.get('b', None) is None assert gd.get('b', 1234) == 1234 assert gd.get('c', None) == 3 assert gd.get('d', None) == 4 assert gd.get('e', None) == 5 assert gd.get('f', 'missing') == 'missing' assert list(gd.values()) == [1, 3, 4] assert list(gd.items()) == [('a', 1), ('c', 3), ('d', 4)] assert list(gd) == ['a', 'c', 'd'] assert gd == {'a': 1, 'c': 3, 'd': 4} assert 'a' in gd assert len(gd) == 3 assert str(gd) == "<GetterDict(TestCls) {'a': 1, 'c': 3, 'd': 4}>"
def test_camera(self): camera = models_school.Camera.objects.first() pp.pprint(camera.to_mongo()) foo = GetterDict(camera) pp.pprint(foo.keys()) pp.pprint(foo['id']) out_cam = schemas_school.Camera.from_orm(camera) pp.pprint(out_cam.dict()) pp.pprint(out_cam.to_json())