예제 #1
0
 def test_plain(self):
     mock = Mock()
     mock.headers = {HTTP_CONTENT_TYPE: 'text/plain'}
     mock.content = 'sdfsdf'
     mock.get = mock.headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertFalse(body)
     self.assertEqual(content, mock.content)
예제 #2
0
 def test_plain(self):
     mock = Mock()
     mock._headers = {HTTP_CONTENT_TYPE: 'text/plain'}
     mock.content = 'sdfsdf'
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertFalse(body)
     self.assertEqual(content, mock.content)
예제 #3
0
 def test_utf_plain(self):
     mock = Mock()
     mock._headers = {HTTP_CONTENT_TYPE: 'text/plain; charset=UTF-8'}
     mock.content = u'语'
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertFalse(body)
     self.assertEqual(content, mock.content)
예제 #4
0
 def test_invalid_encoding_json(self):
     mock = Mock()
     mock._headers = {HTTP_CONTENT_TYPE: 'application/json; charset=asdas-8'}
     d = {'x': u'语'}
     mock.content = json.dumps(d).encode('UTF-8')
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertDictEqual(json.loads(body, encoding='UTF-8'), d)
     self.assertEqual(mock.content.decode('UTF-8'), content)
예제 #5
0
 def test_utf_json_not_encoded(self):
     mock = Mock()
     mock._headers = {HTTP_CONTENT_TYPE: 'application/json; charset=UTF-8'}
     d = {'x': u'语'}
     mock.content = json.dumps(d)
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertDictEqual(json.loads(body), d)
     self.assertEqual(content, mock.content)
예제 #6
0
 def test_utf_json_encoded(self):
     mock = Mock()
     mock._headers = {HTTP_CONTENT_TYPE: 'application/json; charset=UTF-8'}
     d = {'x': u'语'}
     mock.content = json.dumps(d)
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertDictEqual(json.loads(body), d)
     self.assertEqual(content, mock.content)
예제 #7
0
 def test_utf_json_encoded_no_charset(self):
     """default to UTF-8"""
     mock = Mock()
     mock._headers = {HTTP_CONTENT_TYPE: 'application/json'}
     d = {'x': u'语'}
     mock.content = json.dumps(d).encode('UTF-8')
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertDictEqual(json.loads(body), d)
     self.assertEqual(content, mock.content.decode('UTF-8'))
예제 #8
0
 def test_utf_json_encoded_no_charset(self):
     """default to UTF-8"""
     mock = Mock()
     mock._headers = {HTTP_CONTENT_TYPE: 'application/json'}
     d = {'x': u'语'}
     mock.content = json.dumps(d).encode('UTF-8')
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertDictEqual(json.loads(body), d)
     self.assertEqual(content, mock.content.decode('UTF-8'))
예제 #9
0
 def test_bytes_compat(self):
     """
     Test ResponseModelFactory formats json with bytes content
     """
     mock = Mock()
     mock.headers = {HTTP_CONTENT_TYPE: 'application/json;'}
     d = {'k': 'v'}
     mock.content = bytes(json.dumps(d), 'utf-8')
     mock.get = mock.headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertDictEqual(json.loads(body), d)
예제 #10
0
 def test_invalid_encoding_json(self):
     mock = Mock()
     mock._headers = {
         HTTP_CONTENT_TYPE: 'application/json; charset=asdas-8'
     }
     d = {'x': u'语'}
     mock.content = json.dumps(d).encode('UTF-8')
     mock.get = mock._headers.get
     factory = ResponseModelFactory(mock)
     body, content = factory.body()
     self.assertDictEqual(json.loads(body, encoding='UTF-8'), d)
     self.assertEqual(mock.content.decode('UTF-8'), content)
예제 #11
0
 def test_python2_unicode_content_compat(self):
     """
     Test ResponseModelFactory formats json for unicode
     """
     if sys.version_info < (3, 0, 0):
         mock = Mock()
         mock._headers = {HTTP_CONTENT_TYPE: 'application/json;'}
         d = u'{"k": "v"}'
         mock.content = d
         mock.get = mock._headers.get
         factory = ResponseModelFactory(mock)
         body, content = factory.body()
         self.assertDictEqual(json.loads(body), json.loads(d))
예제 #12
0
 def test_python2_str_content_compat(self):
     """
     Test ResponseModelFactory formats json for str
     """
     if sys.version_info < (3, 0, 0):
         mock = Mock()
         mock._headers = {HTTP_CONTENT_TYPE: 'application/json;'}
         d = {'k': 'v'}
         mock.content = str(json.dumps(d))
         mock.get = mock._headers.get
         factory = ResponseModelFactory(mock)
         body, content = factory.body()
         self.assertDictEqual(json.loads(body), d)
예제 #13
0
 def test_python2_unicode_content_compat(self):
     """
     Test ResponseModelFactory formats json for unicode
     """
     if sys.version_info < (3, 0, 0):
         mock = Mock()
         mock._headers = {HTTP_CONTENT_TYPE: 'application/json;'}
         d = u'{"k": "v"}'
         mock.content = d
         mock.get = mock._headers.get
         factory = ResponseModelFactory(mock)
         body, content = factory.body()
         self.assertDictEqual(json.loads(body), json.loads(d))
예제 #14
0
 def test_python2_str_content_compat(self):
     """
     Test ResponseModelFactory formats json for str
     """
     if sys.version_info < (3, 0, 0):
         mock = Mock()
         mock._headers = {HTTP_CONTENT_TYPE: 'application/json;'}
         d = {'k': 'v'}
         mock.content = str(json.dumps(d))
         mock.get = mock._headers.get
         factory = ResponseModelFactory(mock)
         body, content = factory.body()
         self.assertDictEqual(json.loads(body), d)
예제 #15
0
 def test_python2_bytes_content_compat(self):
     """
     Test that ResponseModelFactory returns correct json string for a
     bytestring content
     """
     if sys.version_info < (3, 0, 0):
         mock = Mock()
         mock._headers = {HTTP_CONTENT_TYPE: 'application/json;'}
         d = {'k': 'v'}
         mock.content = bytes(json.dumps(d))
         mock.get = mock._headers.get
         factory = ResponseModelFactory(mock)
         body, content = factory.body()
         self.assertDictEqual(json.loads(body), d)
예제 #16
0
 def test_python2_bytes_content_compat(self):
     """
     Test that ResponseModelFactory returns correct json string for a
     bytestring content
     """
     if sys.version_info < (3, 0, 0):
         mock = Mock()
         mock._headers = {HTTP_CONTENT_TYPE: 'application/json;'}
         d = {'k': 'v'}
         mock.content = bytes(json.dumps(d))
         mock.get = mock._headers.get
         factory = ResponseModelFactory(mock)
         body, content = factory.body()
         self.assertDictEqual(json.loads(body), d)