-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
54 lines (41 loc) · 1.86 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from unittest import TestCase
from app import app
from flask import session
from boggle import Boggle
class FlaskTests(TestCase):
def setUp(self):
"""Stuff to do before every test."""
self.client = app.test_client()
app.config['TESTING'] = True
def test_homepage(self):
"""Make sure information is in the session and HTML is displayed"""
with self.client:
response = self.client.get('/')
self.assertIn('board', session)
self.assertIsNone(session.get('highscore'))
self.assertIsNone(session.get('nplays'))
self.assertIn(b'<p>High Score:', response.data)
self.assertIn(b'Score:', response.data)
self.assertIn(b'Seconds Left:', response.data)
def test_valid_word(self):
"""Test if word is valid by modifying the board in the session"""
with self.client as client:
with client.session_transaction() as sess:
sess['board'] = [["C", "A", "T", "T", "T"],
["C", "A", "T", "T", "T"],
["C", "A", "T", "T", "T"],
["C", "A", "T", "T", "T"],
["C", "A", "T", "T", "T"]]
response = self.client.get('/check-word?word=cat')
self.assertEqual(response.json['result'], 'ok')
def test_invalid_word(self):
"""Test if word is in the dictionary"""
self.client.get('/')
response = self.client.get('/check-word?word=impossible')
self.assertEqual(response.json['result'], 'not-on-board')
def non_english_word(self):
"""Test if word is on the board"""
self.client.get('/')
response = self.client.get(
'/check-word?word=fsjdakfkldsfjdslkfjdlksf')
self.assertEqual(response.json['result'], 'not-word')