예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 def test_row_proxy(self):
     result = encode(self.row_proxy)
     assert loads(result) == {
         'id': 1,
         'first_name': 'Jonathan',
         'last_name': 'LaCour'
     }
예제 #4
0
 def test_sa_object(self):
     result = encode(self.sa_object)
     assert loads(result) == {
         'id': 1,
         'first_name': 'Jonathan',
         'last_name': 'LaCour'
     }
예제 #5
0
    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'}
예제 #6
0
    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'}
예제 #7
0
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
예제 #8
0
 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'
         }]
     }
예제 #9
0
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
예제 #10
0
    def test_decimal(self):
        # XXX Testing for float match which is inexact

        d = Decimal('1.1')
        result = encode(d)
        assert loads(result) == float(d)
예제 #11
0
 def test_row_proxy(self):
     result = encode(self.row_proxy)
     assert loads(result) == {
         'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour'
     }
예제 #12
0
 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'}
     ]}
예제 #13
0
 def test_sa_object(self):
     result = encode(self.sa_object)
     assert loads(result) == {
         'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour'
     }
예제 #14
0
 def test_multidict(self):
     md = MultiDict()
     md.add('arg', 'foo')
     md.add('arg', 'bar')
     result = encode(md)
     assert loads(result) == {'arg': ['foo', 'bar']}
예제 #15
0
    def test_decimal(self):
        # XXX Testing for float match which is inexact

        d = Decimal('1.1')
        result = encode(d)
        assert loads(result) == float(d)
예제 #16
0
 def test_multidict(self):
     md = MultiDict()
     md.add('arg', 'foo')
     md.add('arg', 'bar')
     result = encode(md)
     assert loads(result) == {'arg': ['foo', 'bar']}