-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
94 lines (83 loc) · 2.88 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import unittest
from app import db, models, factory, app
from config import basedir
class TestCase(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' \
+ os.path.join(basedir, 'test.db')
self.app = app.test_client()
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
def test_phrases_with_black_cards(self):
b = models.BlackCard(orig_id=1, text='THIS IS A TEST ____ BLACK CARD 1'
, num_to_draw=1)
w = models.WhiteCard(orig_id=1, text='this is a test white card 1',
watermark='watermelon')
print b, w
db.session.add(w)
db.session.add(b)
db.session.commit()
rb = factory.get_random_black_card()
print rb
if rb is None:
print 'rb is none!'
rb = b
p = models.Phrase()
rb.phrases.append(p)
rw = factory.get_random_white_card()
if rw is None:
print 'rw is none!'
rw = w
fb = models.FilledBlank()
# Adds the filled blank to the phrase
p.filled_blanks.append(fb)
# Adds the filled blank to the white card
rw.filled_blanks.append(fb)
db.session.add(fb)
db.session.add(p)
db.session.commit()
b2 = models.BlackCard(orig_id=1, text='THIS IS A TEST ____ BLACK CARD 2'
, num_to_draw=1)
w2 = models.WhiteCard(orig_id=1, text='this is a test white card 2',
watermark='watermelon')
db.session.add(w2)
db.session.add(b2)
db.session.commit()
# creates the final phrase!
# p.find_text()
# Testing uniqueness of phrase.text.
p2 = models.Phrase()
db.session.add(p2)
fb2 = models.FilledBlank()
rw.filled_blanks.append(fb2)
p2.filled_blanks.append(fb2)
db.session.commit()
rb.phrases.append(p2)
b3 = models.BlackCard(orig_id=1, text='THIS IS A TEST ____ BLACK CARD 3'
, num_to_draw=1)
w3 = models.WhiteCard(orig_id=1, text='this is a test white card 3',
watermark='watermelon')
db.session.add(w3)
db.session.add(b3)
db.session.commit()
# p2.find_text()
# Doesn't have to be unique, because text is changed after the phrase is
# added.
print p
phrs = rb.phrases
for c in phrs:
print 'reached 1'
print c
fblnks = rw.filled_blanks
for fblnk in fblnks:
print 'reached 2'
print fblnk.phrase
if __name__ == '__main__':
unittest.main()