| 969 | The DTP instances in these tests are generated using |
| 970 | DTPFactory.buildProtocol() |
| 971 | """ |
| 972 | |
| 973 | def setUp(self): |
| 974 | """ |
| 975 | Create a fake protocol interpreter, a L{ftp.DTPFactory} instance, |
| 976 | and dummy transport to help with tests. |
| 977 | """ |
| 978 | self.reactor = task.Clock() |
| 979 | |
| 980 | class ProtocolInterpreter(object): |
| 981 | dtpInstance = None |
| 982 | |
| 983 | self.protocolInterpreter = ProtocolInterpreter() |
| 984 | self.factory = ftp.DTPFactory( |
| 985 | self.protocolInterpreter, None, self.reactor) |
| 986 | self.transport = proto_helpers.StringTransportWithDisconnection() |
| 987 | |
| 988 | |
| 989 | def test_sendLine_newline(self): |
| 990 | """ |
| 991 | Whend sending a line, the newline delimiter will be autoamtically |
| 992 | added. |
| 993 | """ |
| 994 | dtp_instance = self.factory.buildProtocol(None) |
| 995 | dtp_instance.makeConnection(self.transport) |
| 996 | line_content = 'line content' |
| 997 | |
| 998 | dtp_instance.sendLine(line_content) |
| 999 | |
| 1000 | data_sent = self.transport.value() |
| 1001 | self.assertEqual(line_content + '\r\n', data_sent) |
| 1002 | |
| 1003 | |
| 1004 | def test_sendLine_unicode(self): |
| 1005 | """ |
| 1006 | When sending an unicode line, it will be converted to str. |
| 1007 | """ |
| 1008 | dtp_instance = self.factory.buildProtocol(None) |
| 1009 | dtp_instance.makeConnection(self.transport) |
| 1010 | line_content = u'my resum\xe9' |
| 1011 | |
| 1012 | dtp_instance.sendLine(line_content) |
| 1013 | |
| 1014 | data_sent = self.transport.value() |
| 1015 | self.assertTrue(isinstance(data_sent, str)) |
| 1016 | # Please advise what test to use. |
| 1017 | # self.assertEqual('my resum\xc3\xa9' + '\r\n', data_sent) |
| 1018 | self.assertEqual(line_content.encode('utf-8') + '\r\n', data_sent) |
| 1019 | |
| 1020 | |