def test_EmailResponse_read_three_bytes(self): """EmailResponse.read(3) should read three bytes from the file.""" response = autoresponder.EmailResponse() response.write(self.body) response.rewind() contents = str(response.read(3)).replace('\x00', '') self.assertEqual(contents, self.body[:3])
def test_EmailResponse_close(self): """Calling EmailResponse.close() should close the ``mailfile`` and set ``closed=True``. """ response = autoresponder.EmailResponse() self.assertEqual(response.closed, False) response.close() self.assertEqual(response.closed, True) self.assertRaises(ValueError, response.write, self.body)
def test_EmailResponse_write(self): """Calling EmailResponse.write() should write to the mailfile.""" response = autoresponder.EmailResponse() response.write(self.body) contents = str(response.readContents()).replace('\x00', '') # The newlines in the email body should have been replaced with # ``EmailResponse.delimiter``. delimited = self.body.replace('\n', response.delimiter) \ + response.delimiter self.assertEqual(delimited, contents)
def test_EmailResponse_additionalHeaders(self): response = autoresponder.EmailResponse() response.writeHeaders(self.fromAddr, self.clientAddr, subject="Re: echelon", inReplyTo="NSA", X_been_there="They were so 2004") contents = str(response.readContents()).replace('\x00', '') self.assertIsInstance(response.mailfile, (io.BytesIO, io.StringIO)) self.assertSubstring("In-Reply-To: NSA", contents) self.assertSubstring("X-been-there: They were so 2004", contents)
def test_EmailResponse_write_withRetNewlines(self): """Calling EmailResponse.write() with '\r\n' in the lines should call writelines(), which splits up the lines and then calls write() again. """ response = autoresponder.EmailResponse() response.write(self.body.replace('\n', '\r\n')) contents = str(response.readContents()).replace('\x00', '') # The newlines in the email body should have been replaced with # ``EmailResponse.delimiter``. delimited = self.body.replace('\n', response.delimiter) \ + response.delimiter self.assertEqual(delimited, contents)