forked from B-LAB/panyabot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.py
More file actions
executable file
·83 lines (70 loc) · 2.76 KB
/
Copy pathtests.py
File metadata and controls
executable file
·83 lines (70 loc) · 2.76 KB
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
#!flask/bin/python
import os
import unittest
from config import DATA
from app import app, db, bcrypt
from app.models import User, Robot
class TestCase(unittest.TestCase):
def setUp(self):
print 'Setting configuration settings',
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(DATA, 'test.db')
print '- Done!'
print 'Creating test database',
self.app = app.test_client()
db.create_all()
print '- Done!'
print 'Creating validated user and robot profiles',
u = User(firstname='John', lastname='Doe', nickname='Jay', password=bcrypt.generate_password_hash('JD'))
r = Robot(alias='Ninja', macid='10:14:06:30:19:86', owner=User.query.filter_by(nickname=u.nickname).first())
db.session.add(u)
db.session.add(r)
db.session.commit()
print '- Done!'
def tearDown(self):
print 'Tearing down database testing environment',
db.session.remove()
db.drop_all()
print '- Done!'
def login(self, nickname, password):
return self.app.post('/login', data=dict(nickname=nickname, password=password),
follow_redirects=True)
def blockly(self):
return self.app.get('/blockly', follow_redirects=True)
def logout(self):
return self.app.get('/logout', follow_redirects=True)
def register(self, firstname, lastname, nickname, mac, roname, pwd, confirm):
return self.app.post('register', data=dict(firstname=firstname,
lastname=lastname, nickname=nickname, robot_mac=mac,
robot_name=roname, password=pwd, confirm=confirm),
follow_redirects=True)
def test_registration(self):
result = self.register('John', 'Doe', 'Jay', '10:14:06:30:19:90',
'Geisha', 'JD', 'JD')
assert 'This nickname is already in use' in result.data
result = self.register('John', 'Doe', 'JayZ', '10:14:06:30:19:90',
'Geisha', 'JD', 'JDc')
assert 'Password must match' in result.data
result = self.register('John', 'Doe', 'Johnny', '10:14:06:30:19:86',
'Geisha', 'JD', 'JD')
assert 'This robot already has an owner' in result.data
result = self.register('John', 'Doe', 'Johnny', '10:14:06:30:19:90',
'Ninja', 'JD', 'JD')
assert 'This robot name is already in use' in result.data
result = self.register('admin', 'admin', 'admin', '10:14:06:30:19:90',
'robot', 'default', 'default')
assert 'account has been created' in result.data
def test_login_logout(self):
result = self.login('Jay','JD')
assert 'Welcome' in result.data
result = self.logout()
assert 'You have been logged out' in result.data
result = self.login('admin', 'default')
assert 'Invalid login' in result.data
def test_block_run(self):
self.login('Jay','JD')
result = self.blockly()
assert 'blocklyArea' in result.data
if __name__ == '__main__':
unittest.main()