-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl_test.py
176 lines (124 loc) · 5.8 KB
/
impl_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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import implementation
import json
import database
import os
if os.path.isfile("temp.db"):
os.remove("temp.db")
db = database.Database("sqlite:///temp.db")
impl = implementation.Implementation(db.models, db.session)
impl.delete_all_rounds()
blob = json.loads(impl.new_user( "Sir Humphrey Applegate", "Jazz123", "[email protected]" ))
assert(blob['success'] == True)
humphrey_id = blob['id']
blob = json.loads(impl.user_info( "Sir Humphrey Applegate" ))
assert(blob['id'] == humphrey_id)
assert(blob['username'] == "Sir Humphrey Applegate")
assert(blob['email'] == "[email protected]")
r = impl.sign_in("Sir Humphrey Applegate", "Jazz123")
assert(r.success)
assert(len(r.key) > 10)
assert(json.loads(r.blob)["user_id"] == humphrey_id)
r = impl.sign_in("Sir Humphrey Applegate", "WrongPassword")
assert(not r.success)
assert(r.key == "")
assert(not json.loads(r.blob).has_key("user_id"))
assert(json.loads(r.blob)["success"] == False)
blob = json.loads(impl.new_user( "Sybil Fawlty", "Splendid11", "[email protected]" ))
assert(blob['success'] == True)
sybil_id = blob['id']
blob = json.loads(impl.new_user( "Sybil Fawlty", "Splendid11", "[email protected]" ))
assert(blob['success'] == False)
blob = json.loads(impl.new_user( "Sybil", "Splendid11", "[email protected]" ))
assert(blob['success'] == False)
blob = json.loads(impl.new_user( "Sybil ", "Splendid11", "[email protected]" ))
assert(blob['success'] == False)
blob = json.loads(impl.new_user( " Leading whitespace", "Splendid12", "[email protected]" ))
assert(blob['success'] == False)
assert(blob['reason'] == "Username invalid.")
blob = json.loads(impl.new_user( "Trailing whitespace ", "Splendid12", "[email protected]" ))
assert(blob['success'] == False)
assert(blob['reason'] == "Username invalid.")
blob = json.loads(impl.new_user( "(contains paren", "Splendid12", "[email protected]" ))
assert(blob['success'] == False)
assert(blob['reason'] == "Username invalid.")
blob = json.loads(impl.new_user( "", "Splendid12", "[email protected]" ))
assert(blob['success'] == False)
assert(blob['reason'] == "Username invalid.")
blob = json.loads(impl.new_user( "Jack the Ripper", "Jack123", "[email protected]" ))
assert(blob['success'] == True)
jack_id = blob['id']
blob = json.loads(impl.delete_user("23gwgwe\n\n\n"))
assert(blob['success'] == False)
blob = json.loads(impl.delete_user("0"))
assert(blob['success'] == False)
blob = json.loads(impl.delete_user(jack_id))
assert(blob['success'] == True)
assert(blob['deleted']==[jack_id])
blob = json.loads(impl.delete_user(str(jack_id)))
assert(blob['success'] == False)
assert( sybil_id > 0 and humphrey_id > 0 and sybil_id != humphrey_id )
print( "humphrey_id = " + str(humphrey_id) )
print( "sybil_id = " + str(sybil_id) )
blob = json.loads( impl.new_game(humphrey_id, "Chess", "A Musical from the 80s") )
assert(blob['success'] == True)
chess_id = blob['id']
blob = json.loads( impl.new_game(humphrey_id, "Chess", "A DIFFERENT Musical with the same name from the 80s") )
assert(blob['success'] == False)
blob = json.loads( impl.games({"username":"Sir Humphrey Applegate"}) )
assert(len(blob['games']) == 1)
assert(blob['games'][0]['title'] == u"Chess")
blob = json.loads( impl.new_game(sybil_id, "Checkers", "Dog given to Nixon as bribe") )
assert(blob['success'] == True)
checkers_id = blob['id']
print("chess_id = " + str(chess_id))
print("checkers_id = " + str(checkers_id))
blob = json.loads( impl.new_game(1000, "Checkers", "A game. A freakin game.") )
assert(blob['success'] == False)
blob = json.loads(impl.delete_game(checkers_id))
assert(blob['success'] == True)
assert(blob['deleted']==[checkers_id])
blob = json.loads(impl.delete_game(checkers_id))
assert(not blob['success'])
blob = json.loads( impl.new_round(sybil_id, chess_id, ','.join(map(str, [humphrey_id, sybil_id]))) )
assert(blob['success'] == True)
chess_round_id = blob['id']
print("chess_round_id = " + str(chess_round_id))
blob = json.loads( impl.rounds({"game_id":chess_id}) )
assert(len(blob['rounds']) == 1)
assert(blob['rounds'][0]['game_id'] == chess_id)
blob = json.loads( impl.new_round(sybil_id, chess_id, ','.join(map(str, [humphrey_id]))) )
assert(blob['success'] == True)
wrong_round_id = blob['id']
blob = json.loads(impl.new_round(sybil_id, chess_id, "asdf"))
assert(blob['success'] == False)
blob = json.loads(impl.new_round(1000, chess_id, str(humphrey_id)))
assert(blob['success'] == False)
blob = json.loads(impl.new_round(sybil_id, 1000, str(humphrey_id)))
assert(blob['success'] == False)
blob = json.loads( impl.delete_round(wrong_round_id) )
assert(blob['success'] == True)
assert(blob['deleted']==[wrong_round_id])
print("deleted rounds: "+str(wrong_round_id))
blob = json.loads( impl.delete_round(wrong_round_id) )
assert(blob['success'] == False)
blob = json.loads( impl.new_move(chess_round_id, sybil_id, "Knight to C3") )
assert(blob['success'] == True)
blob = json.loads( impl.new_move(chess_round_id, humphrey_id, "Pawn to J4") )
assert(blob['success'] == True)
blob = json.loads( impl.new_move(chess_round_id, sybil_id, "You sunk my battleship") )
assert(blob['success'] == True)
blob = json.loads( impl.moves({"round_id":chess_round_id}) )
assert( blob['moves'][0]['content'] == "Knight to C3" )
assert( blob['moves'][1]['content'] == "Pawn to J4" )
assert( blob['moves'][2]['content'] == "You sunk my battleship" )
print( blob['moves'][0]['content'] )
print( blob['moves'][1]['content'] )
print( blob['moves'][2]['content'] )
assert( list(db.models.Game.query.all()) != [] )
assert( list(db.models.Round.query.all()) != [] )
assert( list(db.models.Move.query.all()) != [] )
blob = json.loads( impl.delete_game(chess_id) )
assert( list(db.models.Game.query.all()) == [] )
assert( list(db.models.Round.query.all()) == [] )
assert( list(db.models.Move.query.all()) == [] )
print("PASS")