~dustin-spy/twisted/dustin

« back to all changes in this revision

Viewing changes to admin/accepttests

  • Committer: carmstro
  • Date: 2002-03-16 22:54:55 UTC
  • Revision ID: vcs-imports@canonical.com-20020316225455-53a8cf46dc4267e2
new doc-generator, admin/ directory, class renamings, slight doc update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
import os, sys, shutil, time, string
 
3
 
 
4
 
 
5
def cmd(st):
 
6
    c = os.path.join(twistedBinDir,'') + st
 
7
    print "Running Command: %s" % repr(c)
 
8
    return os.system(c)
 
9
 
 
10
def browse(url):
 
11
    scmd(webbrowser+" "+url)
 
12
    if block:
 
13
        print "Hit enter to continue:"
 
14
        raw_input()
 
15
 
 
16
def scmd(st):
 
17
    print 'Running System Command: %s' % repr(st)
 
18
    return os.system(st)
 
19
 
 
20
def message(*m):
 
21
    print '/------'
 
22
    print '|####'
 
23
    for line in m:
 
24
        print '|####', line
 
25
    print '|####'
 
26
    print '\------'
 
27
 
 
28
def twistdf(f):
 
29
    cmd("twistd -f %s.tap" %f)
 
30
    time.sleep(0.5)
 
31
 
 
32
def twistdg(g):
 
33
    cmd("twistd -g %s" %g)
 
34
    time.sleep(0.5)
 
35
 
 
36
def killit():
 
37
    scmd("kill `cat twistd.pid`")
 
38
    # Give it a sec to come down.
 
39
    time.sleep(0.5)
 
40
 
 
41
def pause():
 
42
    print "Hit enter to continue."
 
43
    raw_input()
 
44
 
 
45
def basicWebTest():
 
46
    message("Running Basic Web Test")
 
47
    cmd("mktap web")
 
48
    twistdf("web")
 
49
    message("You should see a rather complex bunch of widgetry now.")
 
50
    browse("http://localhost:8080/")
 
51
    killit()
 
52
 
 
53
def staticWebTest():
 
54
    message("Running Static Web Test")
 
55
    cmd("mktap web --static %s/../static" % twistedBinDir)
 
56
    twistdf("web")
 
57
    message("You should see an 'it worked' page now.",
 
58
            "(depending on your browser, you may need to reload)")
 
59
    browse("http://localhost:8080/")
 
60
    message("This is Python CGI test output.")
 
61
    browse("http://localhost:8080/test.cgi")
 
62
    killit()
 
63
 
 
64
 
 
65
def distWebTest():
 
66
    message("Running Distributed Web Test")
 
67
    # make directories to stage the test
 
68
    scmd("mkdir Personal")
 
69
    scmd("mkdir User")
 
70
    # make & start personal server
 
71
    os.chdir("Personal")
 
72
    cmd("mktap web --personal")
 
73
    twistdf("web")
 
74
    os.chdir("..")
 
75
    # make & start the user server
 
76
    os.chdir("User")
 
77
    cmd("mktap web --user")
 
78
    twistdf("web")
 
79
    os.chdir("..")
 
80
    # browse a dead web page
 
81
    message("This should say 'Unable to connect to distributed server'",
 
82
            "If it doesn't finish loading, it's broken.  Reload a few times..")
 
83
    browse("http://localhost:8080/nobody.twistd")
 
84
    # browse a live web page
 
85
    message("This should be a bunch-of-widgets test page.")
 
86
    browse("http://localhost:8080/%s.twistd" % username)
 
87
    # clean up
 
88
    os.chdir("User")
 
89
    killit()
 
90
    os.chdir("../Personal")
 
91
    killit()
 
92
    os.chdir("..")
 
93
    shutil.rmtree("User")
 
94
    shutil.rmtree("Personal")
 
95
 
 
96
def runTelnetTest():
 
97
    message("Running Telnet Test")
 
98
    cmd("mktap telnet -p 8023 -u username -w password")
 
99
    twistdf("telnet")
 
100
    message("Log in with the username 'username', password 'password'.",
 
101
            "You should be able to execute python code.",
 
102
            "Log out with '^]close'")
 
103
    scmd("telnet localhost 8023")
 
104
    killit()
 
105
 
 
106
def runManholeTest():
 
107
    message("Running Manhole Test")
 
108
    cmd("mktap manhole -u username -w password")
 
109
    twistdf("manhole")
 
110
    message("Log in with the username 'username', password 'password'.",
 
111
            "and bask in the l33tness of direct manipulation.")
 
112
    cmd("manhole")
 
113
    killit()
 
114
 
 
115
def runWordsTest():
 
116
    message("Running Words Test")
 
117
    cmd("mktap words")
 
118
    twistdf("words")
 
119
    message("Create yourself an account, username 'test' password 'testing'.")
 
120
    browse("http://localhost:8080/create")
 
121
    message("You will have to '/msg *login* testing' to log in.")
 
122
    scmd(ircclient+" test localhost")
 
123
    if block:
 
124
        print "Hit enter to continue:"
 
125
        raw_input()
 
126
    message("Now let's test the 'im' interface.")
 
127
    cmd("im")
 
128
    message("And t-im...")
 
129
    cmd("t-im")
 
130
    killit()
 
131
 
 
132
def runRealityTest():
 
133
    message("Running Reality Test")
 
134
    for mapname, loginname, password in [('TRDemo', 'guest', 'guest'),
 
135
                                         ('Inheritance', 'Damien', 'admin'),
 
136
                                         ('Divunal', 'guest', 'guest')]:
 
137
        if os.path.exists(mapname):
 
138
            twistdg(mapname)
 
139
            message("Log in now, username %s password %s" %
 
140
                    (repr(loginname), repr(password)))
 
141
            cmd("faucet")
 
142
            message("Now again, with the TK interface.")
 
143
            cmd("faucet --toolkit tk")
 
144
            message("Log in again on the telnet interface.")
 
145
            scmd("telnet localhost 4040")
 
146
            message("Now take a look at the website, after logging in")
 
147
            browse("http://localhost:8080/")
 
148
            killit()
 
149
        else:
 
150
            message("reality map %s not found, skipping" % mapname)
 
151
 
 
152
def runExampleTest():
 
153
    examplesDir = twistedBinDir+'/../doc/examples'
 
154
    os.environ['PYTHONPATH'] = '%s:%s' % (os.environ.get('PYTHONPATH') or '',
 
155
                                          examplesDir)
 
156
    scmd("python %s/pbecho.py" % examplesDir)
 
157
    twistdf("pbecho-start")
 
158
    message("You should see a 'hello world'")
 
159
    scmd("python %s/pbechoclient.py" % examplesDir)
 
160
    pause()
 
161
    killit()
 
162
 
 
163
def runMailTest():
 
164
    message("Starting mail test")
 
165
    os.mkdir("dump")
 
166
    os.mkdir("dump2")
 
167
    scmd("mktap mail --domain foo.bar=dump --user postmaster=postmaster")
 
168
    scmd("mktap --append mail.tap mail --relay 127.0.0.1,8025=dump2"
 
169
         "      --smtp 8026 --pop 8111")
 
170
    twistdf("mail")
 
171
    import smtplib, poplib
 
172
    s = smtplib.SMTP('127.0.0.1', 8026)
 
173
    s.sendmail("m@moshez.org", ['postmaster@foo.bar'], '''\
 
174
Subject: How are you gentlemen?
 
175
 
 
176
All your base are belong to us
 
177
''')
 
178
    s.quit()
 
179
    time.sleep(10)
 
180
    p = poplib.POP3('127.0.0.1', 8110)
 
181
    p.apop('postmaster@foo.bar', 'postmaster')
 
182
    print string.join(p.retr(1)[1], '\n')
 
183
    p.quit()
 
184
    killit()
 
185
 
 
186
 
 
187
def runAllTests():
 
188
    message("Starting test.")
 
189
    basicWebTest()
 
190
    staticWebTest()
 
191
    distWebTest()
 
192
    runManholeTest()
 
193
    runTelnetTest()
 
194
    runWordsTest()
 
195
    runRealityTest()
 
196
    runExampleTest()
 
197
    runMailTest()
 
198
    message('All tests run.')
 
199
 
 
200
 
 
201
twistedBinDir = os.path.dirname(sys.argv[0]) or '.'
 
202
try:
 
203
    block = sys.argv[1] == "-b"
 
204
except IndexError:
 
205
    block = None
 
206
try:
 
207
    webbrowser = os.environ['WEBBROWSER']
 
208
    username = os.environ['USER']
 
209
    ircclient = os.environ['IRCCLIENT']
 
210
except KeyError:
 
211
    message("Required Environment Variables:",
 
212
            "  * WEBBROWSER: a command which will run a web browser.",
 
213
            "                (If this doesn't block until the window is closed,",
 
214
            "                 pass '-b' as an argument to the script.)",
 
215
            "  * IRCCLIENT: an IRC client in the style of ircii (use -b in the",
 
216
            "               same situation as above)",
 
217
            "  * USER: your UNIX username.")
 
218
else:
 
219
    runAllTests()