This repository was archived by the owner on Feb 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtools.py
More file actions
50 lines (42 loc) · 1.3 KB
/
tools.py
File metadata and controls
50 lines (42 loc) · 1.3 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
"""
Tools to help test StudyGroup.
"""
from flask.ext.testing import TestCase
from studygroup.application import create_app, db, create_baseline_data
from studygroup.models import User
class StudyGroupTestCase(TestCase):
"""
Base class for all StudyGroup tests.
"""
def setUp(self):
db.create_all()
create_baseline_data()
self.alice_id = self.create_user(full_name='Alice B.')
self.admin_id = self.create_user(full_name='Bob Admin', is_admin=True)
def tearDown(self):
db.session.remove()
db.drop_all()
def create_app(self):
"""
Method required by Flask-Testing to create the app object.
"""
app = create_app()
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
# Use an in-memory SQLite db.
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
return app
def create_user(self, **kwargs):
"""
Make a new user, and return the user id.
"""
user = User(**kwargs)
db.session.add(user)
db.session.commit()
return user.id
def login(self, user_id):
"""
Log in a user by user id.
"""
with self.client.session_transaction() as session:
session['user_id'] = user_id