def test_datetime(self): today = date.today() now = datetime.now() result = encode(today) assert loads(result) == str(today) result = encode(now) assert loads(result) == str(now)
def test_row_proxy(self): result = encode(self.row_proxy) assert loads(result) == { 'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour' }
def test_sa_object(self): result = encode(self.sa_object) assert loads(result) == { 'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour' }
def test_json_callable(self): class JsonCallable(object): def __init__(self, arg): self.arg = arg def __json__(self): return {"arg":self.arg} result = encode(JsonCallable('foo')) assert loads(result) == {'arg':'foo'}
def test_json_callable(self): class JsonCallable(object): def __init__(self, arg): self.arg = arg def __json__(self): return {"arg": self.arg} result = encode(JsonCallable('foo')) assert loads(result) == {'arg': 'foo'}
def test_simple_rule(): Person = make_person() # create a Person instance p = Person('Jonathan', 'LaCour') # register a generic JSON rule @jsonify.when_type(Person) def jsonify_person(obj): return dict(name=obj.name) # encode the object using our new rule result = loads(encode(p)) assert result['name'] == 'Jonathan LaCour' assert len(result) == 1
def test_result_proxy(self): result = encode(self.result_proxy) assert loads(result) == { 'count': 2, 'rows': [{ 'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour' }, { 'id': 2, 'first_name': 'Yoann', 'last_name': 'Roman' }] }
def test_simple_rule(): Person = make_person() # create a Person instance p = Person('Jonathan', 'LaCour') # register a generic JSON rule @jsonify.when_type(Person) def jsonify_person(obj): return dict( name=obj.name ) # encode the object using our new rule result = loads(encode(p)) assert result['name'] == 'Jonathan LaCour' assert len(result) == 1
def test_decimal(self): # XXX Testing for float match which is inexact d = Decimal('1.1') result = encode(d) assert loads(result) == float(d)
def test_result_proxy(self): result = encode(self.result_proxy) assert loads(result) == {'count': 2, 'rows': [ {'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour'}, {'id': 2, 'first_name': 'Yoann', 'last_name': 'Roman'} ]}
def test_multidict(self): md = MultiDict() md.add('arg', 'foo') md.add('arg', 'bar') result = encode(md) assert loads(result) == {'arg': ['foo', 'bar']}