Пример #1
0
class TestSerializer(TestCase):

    def setUp(self):
        self.s = Serializer()

    def test_json(self):
        eq_(self.s.deserialize(json.dumps({'foo': 'bar'}),
                               'application/json'),
            {'foo': 'bar'})

    def test_decimal(self):
        eq_(self.s.serialize({'foo': Decimal('5.00')}),
            json.dumps({'foo': '5.00'}))

    def test_url(self):
        eq_(self.s.deserialize(urlencode({'foo': 'bar'}),
                               'application/x-www-form-urlencoded'),
            {'foo': 'bar'})

        eq_(self.s.deserialize(urlencode({'foo': u'baré'}),
                               'application/x-www-form-urlencoded'),
            {'foo': u'baré'})

    def test_from_url(self):
        with self.assertRaises(UnsupportedFormat):
            self.s.to_urlencode({})

    def test_deserialization_error(self):
        try:
            self.s.deserialize('')
        except DeserializationError, e:
            self.assertIsInstance(e.original, JSONDecodeError)
        else:
Пример #2
0
class TestSerializer(TestCase):
    def setUp(self):
        self.s = Serializer()

    def test_json(self):
        eq_(self.s.deserialize(json.dumps({'foo': 'bar'}), 'application/json'),
            {'foo': 'bar'})

    def test_decimal(self):
        eq_(self.s.serialize({'foo': Decimal('5.00')}),
            json.dumps({'foo': '5.00'}))

    def test_url(self):
        eq_(
            self.s.deserialize(urlencode({'foo': 'bar'}),
                               'application/x-www-form-urlencoded'),
            {'foo': 'bar'})

        eq_(
            self.s.deserialize(urlencode({'foo': u'baré'}),
                               'application/x-www-form-urlencoded'),
            {'foo': u'baré'})

    def test_from_url(self):
        with self.assertRaises(UnsupportedFormat):
            self.s.to_urlencode({})

    def test_deserialization_error(self):
        try:
            self.s.deserialize('')
        except DeserializationError, e:
            self.assertIsInstance(e.original, JSONDecodeError)
        else:
Пример #3
0
class TestSerializer(TestCase):
    def setUp(self):
        self.s = Serializer()

    def test_json(self):
        eq_(self.s.deserialize(json.dumps({'foo': 'bar'}), 'application/json'),
            {'foo': 'bar'})

    def test_url(self):
        eq_(
            self.s.deserialize(urllib.urlencode({'foo': 'bar'}),
                               'application/x-www-form-urlencoded'),
            {'foo': 'bar'})

    def test_from_url(self):
        with self.assertRaises(UnsupportedFormat):
            self.s.to_urlencode({})
Пример #4
0
class TestSerializer(TestCase):

    def setUp(self):
        self.s = Serializer()

    def test_json(self):
        eq_(self.s.deserialize(json.dumps({'foo': 'bar'}),
                               'application/json'),
            {'foo': 'bar'})

    def test_url(self):
        eq_(self.s.deserialize(urllib.urlencode({'foo': 'bar'}),
                               'application/x-www-form-urlencoded'),
            {'foo': 'bar'})

    def test_from_url(self):
        with self.assertRaises(UnsupportedFormat):
            self.s.to_urlencode({})
Пример #5
0
class TestSerializer(TestCase):
    def setUp(self):
        self.s = Serializer()

    def test_json(self):
        eq_(self.s.deserialize(json.dumps({"foo": "bar"}), "application/json"), {"foo": "bar"})

    def test_decimal(self):
        eq_(self.s.serialize({"foo": Decimal("5.00")}), json.dumps({"foo": "5.00"}))

    def test_url(self):
        eq_(self.s.deserialize(urllib.urlencode({"foo": "bar"}), "application/x-www-form-urlencoded"), {"foo": "bar"})

    def test_from_url(self):
        with self.assertRaises(UnsupportedFormat):
            self.s.to_urlencode({})

    def test_deserialization_error(self):
        try:
            self.s.deserialize("")
        except DeserializationError, e:
            self.assertIsInstance(e.original, JSONDecodeError)
        else:
Пример #6
0
 def setUp(self):
     self.s = Serializer()
Пример #7
0
 def setUp(self):
     self.s = Serializer()
Пример #8
0
 class Meta(object):
     authorization = Authorization()
     serializer = Serializer()
     object_class = dict