Example #1
0
 def test_json_by_qs(self):
     request = FakeRequest('/hiihoo', '{"a": 1}', format='json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
     request = FakeRequest('/hiihoo.yaml', '{"a": 1}', format='json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
Example #2
0
File: tests.py Project: pdh/devil
 def test_json_by_qs(self):
     request = FakeRequest('/hiihoo', '{"a": 1}', format='json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
     request = FakeRequest('/hiihoo.yaml', '{"a": 1}', format='json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
Example #3
0
 def test_no_data(self):
     request = FakeRequest('/hiihoo.json')
     self.assertRaises(TypeError, datamapper.parse, request, self.foores)
     request = FakeRequest('/hiihoo.json', '')
     self.assertRaises(errors.BadRequest, datamapper.parse, 'hiihoo',
                       request, self.foores)
     request = FakeRequest('/hiihoo.json', '{}')
     self.assertEquals({}, datamapper.parse('{}', request, self.foores))
     request = FakeRequest('/hiihoo.json', '[]')
     self.assertEquals([], datamapper.parse('[]', request, self.foores))
Example #4
0
File: tests.py Project: pdh/devil
 def test_json_by_content_type(self):
     request = FakeRequest('/hiihoo', '{"a": 1}', 'application/json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
     request = FakeRequest('/hiihoo.yaml', '{"a": 1}', 'application/json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
     request = FakeRequest('/hiihoo.yaml', '{"a": 1}', 'application/json', format='yaml')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
Example #5
0
File: tests.py Project: pdh/devil
 def test_no_data(self):
     request = FakeRequest('/hiihoo.json')
     self.assertRaises(
         TypeError, datamapper.parse, request, self.foores)
     request = FakeRequest('/hiihoo.json', '')
     self.assertRaises(
         errors.BadRequest, datamapper.parse, 'hiihoo', request, self.foores)
     request = FakeRequest('/hiihoo.json', '{}')
     self.assertEquals({}, datamapper.parse('{}', request, self.foores))
     request = FakeRequest('/hiihoo.json', '[]')
     self.assertEquals([], datamapper.parse('[]', request, self.foores))
Example #6
0
 def test_json_by_content_type(self):
     request = FakeRequest('/hiihoo', '{"a": 1}', 'application/json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
     request = FakeRequest('/hiihoo.yaml', '{"a": 1}', 'application/json')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
     request = FakeRequest('/hiihoo.yaml',
                           '{"a": 1}',
                           'application/json',
                           format='yaml')
     self.assertEquals({'a': 1},
                       datamapper.parse('{"a": 1}', request, self.foores))
Example #7
0
 def test_json_by_extension(self):
     request = FakeRequest('/hiihoo.json', '{"a": 3, "b": 4}')
     self.assertEquals(
         datamapper.parse('{"a": 3, "b": 4}', request, self.foores), {
             'a': 3,
             'b': 4
         })
Example #8
0
 def test_default_parser(self):
     request = FakeRequest('/hiihoo', '{"a": 1}')
     self.assertEquals('{"a": 1}',
                       datamapper.parse('{"a": 1}', request, self.foores))
Example #9
0
File: tests.py Project: pdh/devil
 def test_json_by_extension(self):
     request = FakeRequest('/hiihoo.json', '{"a": 3, "b": 4}')
     self.assertEquals(datamapper.parse('{"a": 3, "b": 4}', request, self.foores),
                       {'a': 3, 'b': 4})
Example #10
0
File: tests.py Project: pdh/devil
 def test_default_parser(self):
     request = FakeRequest('/hiihoo', '{"a": 1}')
     self.assertEquals('{"a": 1}',
                       datamapper.parse('{"a": 1}', request, self.foores))