-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
50 lines (35 loc) · 1.73 KB
/
test_app.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
from unittest import TestCase
from app import app
from flask import session
from boggle import Boggle
app.config['TESTING'] = True
class FlaskTests(TestCase):
# TODO -- write tests for every view function / feature!
def setUp(self):
self.game = Boggle()
def test_make_board(self):
"""Tests for 200 response"""
with app.test_client() as client:
res = client.get('/')
self.assertEqual(res.status_code, 200)
def test_session_board(self):
"""Tests that board is created and stored in session['board']"""
with app.test_client() as client:
client.get('/')
self.assertEqual(len(session['board']), 5)
def test_check_not_word(self):
"""Tests that response for none word value equal to 'not-word'"""
with app.test_client() as client:
client.get('/')
res = Boggle.check_valid_word(self.game, session['board'], 'nklfvdsahjkpvdas')
self.assertEqual(res, 'not-word')
def test_check_word_response_correct(self):
"""Checks Boggle.check_valid_word returns correct json"""
board = [["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"]]
res = Boggle.check_valid_word(self.game, board, 'yes')
self.assertEqual(res, 'ok')
def test_check_word_response_incorrect(self):
"""Checks Boggle.check_valid_word returns correct json"""
board = [["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"], ["Y", "E", "S", "Y", "E"]]
res = Boggle.check_valid_word(self.game, board, 'no')
self.assertEqual(res, 'not-on-board')