-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
80 lines (61 loc) · 2.33 KB
/
manage.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
import os
import unittest
from datetime import datetime
from hashlib import sha256
from flask.ext.script import Manager
from server import create_app
from server.models import db
from server.models import Lecturer, Course, Lecture, Comment, CommentRating
manager = Manager(create_app)
@manager.command
def init_db():
""" Initialize database: drop and create all columns """
db.drop_all()
db.create_all()
@manager.command
def mock_db():
""" Insert mock data into database """
init_db()
simon = Lecturer('simon@hig.no', sha256('1234'.encode('utf-8')).hexdigest(), 'Simon', 'McCallum')
simon.admin = True
db.session.add(simon)
magnus = Lecturer('magnus@hig.no', sha256('12345'.encode('utf-8')).hexdigest(), 'Magnus', 'Vik')
db.session.add(magnus)
imt3601 = Course('IMT3601 - Game Programming', simon)
db.session.add(imt3601)
imt3601_l1 = Lecture('Lecture 1', imt3601)
db.session.add(imt3601_l1)
imt3601_l1_c1 = Comment('This is boring', datetime(2015, 11, 26, 10, 30), imt3601_l1)
db.session.add(imt3601_l1_c1)
imt3601_l1_c2 = Comment('This is fun!', datetime(2015, 11, 26, 10, 40), imt3601_l1)
db.session.add(imt3601_l1_c2)
imt3601_l1_c3 = Comment('Help?', datetime(2015, 11, 26, 10, 50), imt3601_l1)
db.session.add(imt3601_l1_c3)
imt3601_l1_c4 = Comment(
'A bit longer comment for your convenience',
datetime(2015, 11, 26, 10, 10),
imt3601_l1)
db.session.add(imt3601_l1_c4)
imt3601_l1_r1 = CommentRating(1, 1, imt3601_l1_c1, imt3601_l1)
db.session.add(imt3601_l1_r1)
imt3601_l1_r2 = CommentRating(1, 2, imt3601_l1_c1, imt3601_l1)
db.session.add(imt3601_l1_r2)
imt3601_l1_r3 = CommentRating(1, 3, imt3601_l1_c1, imt3601_l1)
db.session.add(imt3601_l1_r3)
imt3601_l1_r4 = CommentRating(-1, 1, imt3601_l1_c3, imt3601_l1)
db.session.add(imt3601_l1_r4)
imt3601_l1_r5 = CommentRating(1, 1, imt3601_l1_c4, imt3601_l1)
db.session.add(imt3601_l1_r5)
db.session.flush()
@manager.command
def test():
tests_path = os.path.join(os.path.dirname(__file__), 'server', 'tests')
tests = unittest.defaultTestLoader.discover(tests_path)
runner = unittest.TextTestRunner()
result = runner.run(tests)
if result.wasSuccessful():
return 0
else:
return 1
if __name__ == '__main__':
manager.run()