forked from jokamjohn/bucket_api_heroku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
74 lines (62 loc) · 1.79 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
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from app import app, db, models
from app.models import User, Bucket, BucketItem
import unittest
import coverage
import os
import forgery_py as faker
from random import randint
from sqlalchemy.exc import IntegrityError
# Initializing the manager
manager = Manager(app)
# Initialize Flask Migrate
migrate = Migrate(app, db)
# Add the flask migrate
manager.add_command('db', MigrateCommand)
# Test coverage configuration
COV = coverage.coverage(
branch=True,
include='app/*',
omit=[
'app/auth/__init__.py',
'app/bucket/__init__.py',
'app/bucketitems/__init__.py'
]
)
COV.start()
# Add test command
@manager.command
def test():
"""
Run tests without coverage
:return:
"""
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 dummy():
# Create a user if they do not exist.
user = User.query.filter_by(email="[email protected]").first()
if not user:
user = User("[email protected]", "123456")
user.save()
for i in range(100):
# Add buckets to the database
bucket = Bucket(faker.name.industry(), user.id)
bucket.save()
for buck in range(1000):
# Add items to the bucket
buckt = Bucket.query.filter_by(id=randint(1, Bucket.query.count() - 1)).first()
item = BucketItem(faker.name.company_name(), faker.lorem_ipsum.word(), buckt.id)
db.session.add(item)
try:
db.session.commit()
except IntegrityError:
db.session.rollback()
# Run the manager
if __name__ == '__main__':
manager.run()