Permalink
Browse files

Added beginnings of black box tests

  • Loading branch information...
1 parent 47e0534 commit fb2af3a5bc5f1352404bd378b90a998384c24851 Euan Goddard committed May 27, 2011
Showing with 153 additions and 1 deletion.
  1. +4 −1 .gitignore
  2. +16 −0 tests/black-box/README
  3. +116 −0 tests/black-box/sequential.py
  4. +17 −0 tests/black-box/test-server.js
View
5 .gitignore
@@ -1 +1,4 @@
-.project
+.project
+.pydevproject
+.settings/
+*.pyc
View
16 tests/black-box/README
@@ -0,0 +1,16 @@
+The tests in this section are "black box" tests or, put another way, tests
+which test the system as a whole without concerning the code behind the module.
+
+To run the tests, you will need to have node installed (obviously!) and have a
+version of python as the SMTP client uses the built in one in python's standard
+library. The tests have all been verified with python 2.5.
+
+The tests require the testing server to be running. In the current directory:
+
+$ node test-server.js
+
+Then you can run the tests that you want:
+
+$ python <name of test>.py.
+
+For unit tests, see the "unit tests" section.
View
116 tests/black-box/sequential.py
@@ -0,0 +1,116 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from smtplib import SMTP
+from telnetlib import Telnet
+import unittest
+
+class SequentialTests(unittest.TestCase):
+
+ addrs = [
+ 'bob@example.com', 'sheila@example.com', 'kurt@example.com',
+ 'wendy@example.com', 'tim@example.com'
+ ]
+
+ def testFiveSequentialMessages(self):
+ """5 sequential messages can be sent in the same connection."""
+
+ server = SMTP('localhost', 1025)
+
+ for from_addr, to_addr in zip(self.addrs, reversed(self.addrs)):
+
+ response = server.sendmail(
+ from_addr, [to_addr],
+ 'This is a test message\nSecond line.\nFinal line here.'
+ )
+
+ self.assertEqual(response, {})
+
+ server.quit()
+
+ def testFiveSequentialConnections(self):
+ """5 sequential connections can be used to send messages."""
+
+ for from_addr, to_addr in zip(self.addrs, reversed(self.addrs)):
+ server = SMTP('localhost', 1025)
+
+ response = server.sendmail(
+ from_addr, [to_addr],
+ 'This is a test message\nSecond line.\nFinal line here.'
+ )
+
+ self.assertEqual(response, {})
+
+ server.quit()
+
+ def testUnicode(self):
+ """Unicode characters are correctly received"""
+
+ server = SMTP('localhost', 1025)
+
+ response = server.sendmail(
+ 'ryu@example.jp', 'akira@example.jp',
+ u'こんにちは彰、どのようにして、今日ですか?リュ'.encode('utf8')
+ )
+
+ self.assertEqual(response, {})
+
+ def testWelcomeMessage(self):
+ """On connecting the server sends a 220 response with a welcome message."""
+ client = Telnet('localhost', 1025)
+ self.assertEqual(client.read_some(), '220 test node.js SMTP server\r\n')
+ client.close()
+
+ def testIllegalHelo(self):
+ """HELO takes a single argument."""
+
+ client = Telnet('localhost', 1025)
+ client.read_some()
+ client.write('HELO')
+ self.assertEqual(client.read_some(), '501 Syntax: HELO hostname\r\n')
+ client.close()
+
+ def testLegalHelo(self):
+ """The server responds to a valid HELO command."""
+
+ client = Telnet('localhost', 1025)
+ client.read_some()
+ client.write('HELO localhost')
+ self.assertEqual(client.read_some(), '250 test Hello 127.0.0.1\r\n')
+ client.close()
+
+ def testIllegalNoop(self):
+ """The NOOP command fails if any argument is passed."""
+
+ client = Telnet('localhost', 1025)
+ client.read_some()
+ client.write('NOOP something else here')
+ self.assertEqual(client.read_some(), '501 Syntax: NOOP\r\n')
+ client.close()
+
+ def testLegalNoop(self):
+ """The NOOP command takes no arguments."""
+
+ client = Telnet('localhost', 1025)
+ client.read_some()
+ client.write('NOOP')
+ self.assertEqual(client.read_some(), '250 Ok\r\n')
+ client.close()
+
+ def testQuit(self):
+ """The QUIT command doesn't care about arguments - the connection is
+ closed regardless."""
+
+ client = Telnet('localhost', 1025)
+ client.read_some()
+ client.write('QUIT')
+ self.assertEqual(client.read_some(), '221 test closing connection\r\n')
+
+ client = Telnet('localhost', 1025)
+ client.read_some()
+ client.write('QUIT See you later')
+ self.assertEqual(client.read_some(), '221 test closing connection\r\n')
+
+
+if __name__ == "__main__":
+ unittest.main()
View
17 tests/black-box/test-server.js
@@ -0,0 +1,17 @@
+/**
+ * Test server for black box tests.
+ * @author Euan Goddard
+ */
+
+var smtpevent = require('../../smtpevent.js'),
+
+ server = new smtpevent.SMTPServer('test');
+
+server.listen(1025, "127.0.0.1");
+server.on('incoming-mail', function (peer, from, to, message) {
+ console.log('Received test message from: '+ peer);
+ console.log('Message from: '+ from + ' to: '+ to);
+ console.log('---------------------');
+ console.log(message);
+ console.log('---------------------');
+});

0 comments on commit fb2af3a

Please sign in to comment.