def test_spamc_tcp_exp3(self): with mock.patch.object(SpamC, 'get_connection') as mock_conn: mock_conn.return_value._s = None mock_conn.return_value.send.side_effect = socket.error('xxxx') spamc_tcp = SpamC( host='127.0.0.1', port=10060) with self.assertRaises(SpamCError): spamc_tcp.ping()
def test_spamc_tcp_exp1(self): with mock.patch.object(SpamC, 'get_connection') as mock_conn: mock_conn.return_value.socket.return_value.makefile\ .return_value.read.return_value = '' spamc_tcp = SpamC(host='127.0.0.1', port=10060) with self.assertRaises(SpamCResponseError): spamc_tcp.ping() mock_conn.return_value.socket.return_value.makefile\ .return_value.read.assert_called_once_with()
def test_spamc_tcp_exp1(self): with mock.patch.object(SpamC, 'get_connection') as mock_conn: mock_conn.return_value.socket.return_value.makefile\ .return_value.read.return_value = '' spamc_tcp = SpamC( host='127.0.0.1', port=10060) with self.assertRaises(SpamCResponseError): spamc_tcp.ping() mock_conn.return_value.socket.return_value.makefile\ .return_value.read.assert_called_once_with()
def runit(): """run things""" parser = OptionParser() parser.add_option('-s', '--server', help='The spamassassin spamd server to connect to', dest='server', type='str', default='standalone.home.topdog-software.com') parser.add_option('-p', '--port', help='The spamassassin spamd server port to connect to', dest='port', type='int', default=783) parser.add_option('-u', '--unix-socket', help='The spamassassin spamd unix socket to connect to', dest='socket_path', type='str') parser.add_option('-t', '--tls', help='Use TLS', dest='tls', action='store_true', default=False) parser.add_option('-z', '--use-zlib-compression', help='Use Zlib compression', dest='gzip', action='store_true', default=False) parser.add_option('-l', '--zlib-compression-level', help='Zlib compression level', dest='compress_level', type='choice', choices=[str(val) for val in range(0, 10)], default=6) parser.add_option('-a', '--user', help=('''Username of the user on whose behalf''' '''this scan is being performed'''), dest='user', type='str', default='exim') options, _ = parser.parse_args() sslopts = {} if options.tls: sslopts = dict(ssl_version=PROTOCOL_TLSv1) if options.socket_path and os.path.exists(options.socket_path): options.server = None client = SpamC( options.server, port=options.port, socket_file=options.socket_path, user=options.user, gzip=options.gzip, compress_level=int(options.compress_level), is_ssl=options.tls, **sslopts) pprint.pprint(client.ping()) path = os.path.dirname(__file__) for test in FILES: filename = os.path.join(path, test['name']) print "File => %s" % filename fileobj = open(filename) print "=" * 10, "client.check()" pprint.pprint(client.check(fileobj)) print "=" * 10, "client.symbols()" pprint.pprint(client.symbols(fileobj)) print "=" * 10, "client.report()" pprint.pprint(client.report(fileobj)) print "=" * 10, "client.report_ifspam()" pprint.pprint(client.report_ifspam(fileobj)) print "=" * 10, "client.process()" pprint.pprint(client.process(fileobj)) print "=" * 10, "client.headers()" pprint.pprint(client.headers(fileobj)) print "=" * 10, "client.learn()" pprint.pprint(client.learn(fileobj, test['type'])) print "=" * 10, "client.tell()" pprint.pprint(client.tell(fileobj, 'forget')) print "=" * 10, "client.revoke()" pprint.pprint(client.revoke(fileobj))