summaryrefslogtreecommitdiff
path: root/src/leap/mx/tests/tester.py
blob: 05d2d052d016978783826731cabe1ef14752b28b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import ConfigParser
import sys
import os

from twisted.internet import reactor, defer
from twisted.python import filepath, log

from leap.mx import couchdbhelper
from leap.mx.mail_receiver import MailReceiver

if __name__ == "__main__":
    log.startLogging(sys.stdout)
    fullpath = os.path.realpath(sys.argv[1])

    log.msg("Starting test for %s..." % (fullpath,))

    config_file = "/etc/leap/mx.conf"

    config = ConfigParser.ConfigParser()
    config.read(config_file)

    user = config.get("couchdb", "user")
    password = config.get("couchdb", "password")

    server = config.get("couchdb", "server")
    port = config.get("couchdb", "port")

    cdb = couchdbhelper.ConnectedCouchDB(server,
                                         port=port,
                                         dbName="identities",
                                         username=user,
                                         password=password)

    # Mail receiver
    mail_couch_url_prefix = "http://%s:%s@%s:%s" % (user,
                                                    password,
                                                    server,
                                                    port)

    mr = MailReceiver(mail_couch_url_prefix, cdb, [])
    fpath = filepath.FilePath(fullpath)

    d = mr._process_incoming_email(None, fpath, 0)
    d.addCallback(lambda x: reactor.stop())

    reactor.run()