def test_accepts_string_string(self): data = 'spam' result = _typecheck_or_convert_data(data, 'string') self.assertEqual(result, data)
def test_accepts_pyobj_pyobj(self): data = {'spam': ['ham'], 'eggs': True} result = _typecheck_or_convert_data(data, 'pyobj') self.assertEqual(result, data)
def test_accepts_bytes_raw(self): data = b'spam' result = _typecheck_or_convert_data(data, 'raw') self.assertEqual(result, data)
def test_accepts_list_of_bytes_multipart(self): data = [b'spam', b'ham'] result = _typecheck_or_convert_data(data, 'multipart') self.assertEqual(result, data)
def test_turns_None_into_empty_bytestring_multipart(self): result = _typecheck_or_convert_data(None, 'multipart') self.assertEqual(result, [b''])
def test_wraps_bytestring_into_list_multipart(self): data = b'spam' result = _typecheck_or_convert_data(data, 'multipart') self.assertEqual(result, [data])
def test_turns_None_into_empty_bytestring_raw(self): result = _typecheck_or_convert_data(None, 'raw') self.assertEqual(result, b'')
def test_rejects_invalid_send_type(self): data = {'spam': ['ham'], 'eggs': True} with self.assertRaises(ValueError): _typecheck_or_convert_data(data, 'invalid_send_type')
def test_rejects_pyobj_string(self): data = {'spam': ['ham'], 'eggs': True} with self.assertRaises(TypeError): _typecheck_or_convert_data(data, 'string')
def test_rejects_string_multipart(self): data = [b'spam', 'ham'] with self.assertRaises(TypeError): _typecheck_or_convert_data(data, 'multipart')
def test_rejects_string_raw(self): data = 'spam' with self.assertRaises(TypeError): _typecheck_or_convert_data(data, 'raw')