-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.py
More file actions
41 lines (34 loc) · 1.15 KB
/
Copy pathmanage.py
File metadata and controls
41 lines (34 loc) · 1.15 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
import os
import unittest
import csv
from flask_script import Manager # class for handling a set of commands
from flask_migrate import Migrate, MigrateCommand
from app import db, app #from app import models
#app = create_app(config_name=os.getenv('APP_SETTINGS'))
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.command
def test():
"""Runs the unit tests without test coverage."""
tests = unittest.TestLoader().discover('./tests', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
@manager.command
def importcsv(file):
with open(file, 'r') as csvfile:
spamreader = csv.reader(csvfile, delimiter='|')#, quotechar='|')
from app.models import Question
for row in spamreader:
question = Question(
question=row[0],
answer=row[1],
distractor=row[2],
created_by=None
)
question.save()
return 0
if __name__ == '__main__':
manager.run()