-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
79 lines (64 loc) · 2.15 KB
/
test.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import subprocess
from nose.tools import eq_, ok_
from app import app
import os
import signal
def test_zulip():
proc = subprocess.Popen(["python3", "-u", "bots/goodbot.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
outs, errs = proc.communicate(timeout=10)
except subprocess.TimeoutExpired:
proc.kill()
outs, errs = proc.communicate()
outs = outs.decode()
errs = errs.decode()
eq_(len(errs), 0, errs)
ok_("Begin bot init" in outs, "Bot init failed")
ok_("Subscription complete" in outs, "Subscription failed")
ok_("Bot init complete" in outs, "Bot init could not be completed")
def test_irc():
proc = subprocess.Popen(["python3", "-u", "bots/ircbot.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid)
try:
outs, errs = proc.communicate(timeout=15)
except subprocess.TimeoutExpired:
os.killpg(os.getpgid(proc.pid), signal.SIGKILL) # force os to kill child processes
outs, errs = proc.communicate()
outs = outs.decode()
errs = errs.decode()
eq_(len(errs), 0, errs)
ok_("Begin ircbot init" in outs, "ircbot init failed")
ok_("Connected to IRC server" in outs, "Could not connect to IRC server")
ok_("Joined IRC channel" in outs, "Could not join IRC channel")
ok_("Connected to Zulip" in outs, "Could not connect to Zulip")
class test_flask():
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def setUp(self):
# creates a test client
self.app = app.test_client()
# propagate the exceptions to the test client
self.app.testing = True
def tearDown(self):
pass
def test_index_status_code(self):
# sends HTTP GET request to the application
# on the specified path
result = self.app.get("/")
# assert the status code of the response
eq_(result.status_code, 200)
def test_bad_deploy_post(self):
# sends HTTP request to the application
# on the specified path
result = self.app.post("/deploy")
# assert the response data
eq_(result.status_code, 400)
def test_good_deploy_post(self):
# sends HTTP request to the application
# on the specified path
result = self.app.post("/deploy", data="{}")
# assert the response data
eq_(result.status_code, 200)