def test_marshal_tuple_with_envelope(self): fields = OrderedDict({'foo': flask_restbolt.fields.Raw}) marshal_fields = OrderedDict([('foo', 'bar'), ('bat', 'baz')]) output = flask_restbolt.marshal((marshal_fields, ), fields, envelope='hey') self.assertEquals(output, {'hey': [{'foo': 'bar'}]})
def test_marshal_list(self): fields = OrderedDict([ ('foo', flask_restbolt.fields.Raw), ('fee', flask_restbolt.fields.List(flask_restbolt.fields.String)) ]) marshal_fields = OrderedDict([('foo', 'bar'), ('bat', 'baz'), ('fee', ['fye', 'fum'])]) output = flask_restbolt.marshal(marshal_fields, fields) expected = OrderedDict([('foo', 'bar'), ('fee', (['fye', 'fum']))]) self.assertEquals(output, expected)
def test_marshal_nested_with_null(self): fields = OrderedDict([('foo', flask_restbolt.fields.Raw), ('fee', flask_restbolt.fields.Nested(OrderedDict([ ('fye', flask_restbolt.fields.String), ('blah', flask_restbolt.fields.String) ]), allow_null=True))]) marshal_fields = OrderedDict([('foo', 'bar'), ('bat', 'baz'), ('fee', None)]) output = flask_restbolt.marshal(marshal_fields, fields) expected = OrderedDict([('foo', 'bar'), ('fee', None)]) self.assertEquals(output, expected)
def test_marshal_list_of_nesteds(self): fields = OrderedDict([('foo', flask_restbolt.fields.Raw), ('fee', flask_restbolt.fields.List( flask_restbolt.fields.Nested( {'fye': flask_restbolt.fields.String})))]) marshal_fields = OrderedDict([('foo', 'bar'), ('bat', 'baz'), ('fee', { 'fye': 'fum' })]) output = flask_restbolt.marshal(marshal_fields, fields) expected = OrderedDict([('foo', 'bar'), ('fee', [OrderedDict([('fye', 'fum')])])]) self.assertEquals(output, expected)
def test_marshal_nested_dict(self): fields = OrderedDict([ ('foo', flask_restbolt.fields.Raw), ('bar', OrderedDict([ ('a', flask_restbolt.fields.Raw), ('b', flask_restbolt.fields.Raw), ])), ]) marshal_fields = OrderedDict([('foo', 'foo-val'), ('bar', 'bar-val'), ('bat', 'bat-val'), ('a', 1), ('b', 2), ('c', 3)]) output = flask_restbolt.marshal(marshal_fields, fields) expected = OrderedDict([('foo', 'foo-val'), ('bar', OrderedDict([('a', 1), ('b', 2)]))]) self.assertEquals(output, expected)
def test_marshal_decorator_with_envelope(self): fields = OrderedDict([('foo', flask_restbolt.fields.Raw)]) @flask_restbolt.marshal_with(fields, envelope='hey') def try_me(): return OrderedDict([('foo', 'bar'), ('bat', 'baz')]) self.assertEquals(try_me(), {'hey': {'foo': 'bar'}})
def test_allow_null_presents_data(self): fields = OrderedDict([('foo', flask_restbolt.fields.Raw), ('fee', flask_restbolt.fields.Nested(OrderedDict([ ('fye', flask_restbolt.fields.String), ('blah', flask_restbolt.fields.String) ]), allow_null=True))]) marshal_fields = OrderedDict([('foo', 'bar'), ('bat', 'baz'), ('fee', { 'blah': 'cool' })]) output = flask_restbolt.marshal(marshal_fields, fields) expected = OrderedDict([('foo', 'bar'), ('fee', OrderedDict([('fye', None), ('blah', 'cool')]))]) self.assertEquals(output, expected)
def test_marshal_decorator_tuple(self): fields = OrderedDict([('foo', flask_restbolt.fields.Raw)]) @flask_restbolt.marshal_with(fields) def try_me(): return OrderedDict([('foo', 'bar'), ('bat', 'baz')]), 200, { 'X-test': 123 } self.assertEquals(try_me(), ({'foo': 'bar'}, 200, {'X-test': 123}))
def test_marshal_nested_property(self): class TestObject(object): @property def fee(self): return {'blah': 'cool'} fields = OrderedDict([('foo', flask_restbolt.fields.Raw), ('fee', flask_restbolt.fields.Nested(OrderedDict([ ('fye', flask_restbolt.fields.String), ('blah', flask_restbolt.fields.String) ]), allow_null=True))]) obj = TestObject() obj.foo = 'bar' obj.bat = 'baz' output = flask_restbolt.marshal([obj], fields) expected = [ OrderedDict([('foo', 'bar'), ('fee', OrderedDict([('fye', None), ('blah', 'cool')]))]) ] self.assertEquals(output, expected)
def test_marshal_tuple(self): fields = OrderedDict({'foo': flask_restbolt.fields.Raw}) marshal_fields = OrderedDict([('foo', 'bar'), ('bat', 'baz')]) output = flask_restbolt.marshal((marshal_fields, ), fields) self.assertEquals(output, [{'foo': 'bar'}])
def try_me(): return OrderedDict([('foo', 'bar'), ('bat', 'baz')]), 200, { 'X-test': 123 }
def try_me(): return OrderedDict([('foo', 'bar'), ('bat', 'baz')])
def test_marshal_with_envelope(self): fields = OrderedDict([('foo', flask_restbolt.fields.Raw)]) marshal_dict = OrderedDict([('foo', 'bar'), ('bat', 'baz')]) output = flask_restbolt.marshal(marshal_dict, fields, envelope='hey') self.assertEquals(output, {'hey': {'foo': 'bar'}})
def test_marshal(self): fields = OrderedDict([('foo', flask_restbolt.fields.Raw)]) marshal_dict = OrderedDict([('foo', 'bar'), ('bat', 'baz')]) output = flask_restbolt.marshal(marshal_dict, fields) self.assertEquals(output, {'foo': 'bar'})