-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
75 lines (54 loc) · 2.06 KB
/
tests.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
from flask.ext.testing import TestCase
from SteamScout import app, db
from SteamScout.models import User, Games, Preferences
from admin import reset_game_db
import unittest
import os
class DatabaseAndForms(TestCase):
_basedir = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(_basedir, 'test_db.sqlite')
TESTING = True
def create_app(self):
# Changes the app config to the testing settings before returning it.
app.config.from_object('config.TestingConfig')
return app
def setUp(self):
db.create_all()
def test_add_user(self):
users = User.query.filter_by(username='test_user').count()
self.assertEqual(users, 0)
user = User('test_user', '[email protected]', 'password')
db.session.add(user)
db.session.commit()
users = User.query.filter_by(username='test_user').count()
self.assertEqual(users, 1)
def test_add_games(self):
games_count = Games.query.count()
assert games_count == 0
reset_game_db()
games_count = Games.query.count()
assert games_count >= 1
def tearDown(self):
db.session.remove()
db.drop_all()
class Templates(TestCase):
def create_app(self):
# Changes the app config to the testing settings before returning it.
app.config.from_object('config.TestingConfig')
return app
render_templates = False
def test_templates_renders(self):
# Home Page
response = self.client.get("/")
self.assert_template_used('home.html')
# Games Page
response = self.client.get("/games")
self.assert_template_used('games.html')
# Developers Page
response = self.client.get("/developers")
self.assert_template_used('developers.html')
# Contact Page
response = self.client.get("/contact")
self.assert_template_used('contact.html')
if __name__ == '__main__':
unittest.main()