Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
0
 def test_row_proxy(self):
     result = encode(self.row_proxy)
     assert loads(result) == {
         'id': 1,
         'first_name': 'Jonathan',
         'last_name': 'LaCour'
     }
Ejemplo n.º 4
0
 def test_sa_object(self):
     result = encode(self.sa_object)
     assert loads(result) == {
         'id': 1,
         'first_name': 'Jonathan',
         'last_name': 'LaCour'
     }
Ejemplo n.º 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'}
Ejemplo n.º 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'}
Ejemplo n.º 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
Ejemplo n.º 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'
         }]
     }
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 11
0
 def test_row_proxy(self):
     result = encode(self.row_proxy)
     assert loads(result) == {
         'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour'
     }
Ejemplo n.º 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'}
     ]}
Ejemplo n.º 13
0
 def test_sa_object(self):
     result = encode(self.sa_object)
     assert loads(result) == {
         'id': 1, 'first_name': 'Jonathan', 'last_name': 'LaCour'
     }
Ejemplo n.º 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']}
Ejemplo n.º 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)
Ejemplo n.º 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']}