-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestAssert.py
108 lines (95 loc) · 3.75 KB
/
testAssert.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import stat
import os
from sys import executable
import unittest
from subprocess import call, Popen, PIPE
from time import sleep
from socket import socket, error
from errno import EADDRINUSE
TIMEOUT = 5
def socket_status(host, port):
try:
socket().bind((host, port),)
# False if the is free
return False
except error, (num, err):
if num == EADDRINUSE:
# True if the isn't free
return True
class BuildoutTestCase(unittest.TestCase):
"""Test all features of buildout profiles"""
def test_redis(self):
try:
call('./bin/redisctl start', shell=True)
sleep(TIMEOUT)
self.assertEquals(socket_status('localhost', 6973), True)
finally:
call('./bin/redisctl stop', shell=True)
def test_redis_client(self):
try:
call('./bin/redisclientctl start', shell=True)
sleep(TIMEOUT)
self.assertEquals(socket_status('localhost', 8888), True)
finally:
call('./bin/redisclientctl stop', shell=True)
def test_sam(self):
try:
call('./bin/samctl start', shell=True)
sleep(TIMEOUT)
self.assertEquals(socket_status('localhost', 6973), True)
self.assertEquals(socket_status('localhost', 8888), True)
finally:
call('./bin/samctl stop', shell=True)
def test_lib_txredisapi(self):
stdout, stderr = Popen('./bin/python -c "import txredisapi"',
shell=True,
stdout=PIPE,
stderr=PIPE).communicate()
self.assertEquals(stdout, '')
self.assertEquals(stderr, '')
def test_lib_twisted(self):
stdout, stderr = Popen('./bin/python -c "import twisted"',
shell=True,
stdout=PIPE,
stderr=PIPE).communicate()
self.assertEquals(stdout, '')
self.assertEquals(stderr, '')
def test_lib_nsisam(self):
stdout, stderr = Popen('./bin/python -c "import nsisam"',
shell=True,
stdout=PIPE,
stderr=PIPE).communicate()
self.assertEquals(stdout, '')
self.assertEquals(stderr, '')
def test_permissions_file(self):
filemode = stat.S_IMODE(os.stat('./bin/redisctl').st_mode)
self.assertEquals(filemode in [448, 493], True)
filemode = stat.S_IMODE(os.stat('./bin/redisclientctl').st_mode)
self.assertEquals(filemode in [448, 493], True)
filemode = stat.S_IMODE(os.stat('./bin/samctl').st_mode)
self.assertEquals(filemode in [448, 493], True)
filemode = stat.S_IMODE(os.stat('./bin/redis-server').st_mode)
self.assertEquals(filemode in [448, 493], True)
def test_add_user(self):
add_user_command = [executable,
'./bin/add-user.py',
'test', 'test']
del_user_command = [executable,
'./bin/del-user.py',
'test']
try:
stdout, stderr = Popen(' '.join(add_user_command),
shell=True,
stdout=PIPE,
stderr=PIPE).communicate()
self.assertEquals(stdout, '')
self.assertEquals(stderr, '')
finally:
stdout, stderr = Popen(' '.join(del_user_command),
shell=True,
stdout=PIPE,
stderr=PIPE).communicate()
self.assertEquals(stdout, '')
self.assertEquals(stderr, '')
if __name__ == "__main__":
unittest.main()