-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
37 lines (28 loc) · 1.35 KB
/
test.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
from unittest import TestCase
from app import app
from flask import session, jsonify
from boggle import Boggle
class FlaskTests(TestCase):
def test_homepage(self):
with app.test_client() as client:
res = client.get('/')
html = res.get_data(as_text=True)
self.assertEqual(res.status_code, 200)
self.assertIn('<h2 class="title" id="title">Boggle!</h2>', html)
def test_check_word(self):
with app.test_client() as client:
with client.session_transaction() as client_session:
client_session['board'] = [['Q', 'Q', 'Q', 'Q', 'Q'],
['Q', 'Q', 'Q', 'Q', 'Q'],
['Q', 'Q', 'Q', 'Q', 'Q'],
['Q', 'Q', 'Q', 'Q', 'Q'],
['W', 'O', 'R', 'K', 'S']]
res = client.post('/check_word', json={'word': 'works'})
self.assertEqual(res.status_code, 200)
self.assertEqual(res.json['result'], 'ok')
def test_score_board(self):
with app.test_client() as client:
res = client.get('/score_board')
self.assertEqual(res.status_code, 200)
self.assertEqual(res.json['highScore'], 0)
self.assertEqual(res.json['numPlayed'], 0)