convert remaining functions to snake_case
This commit is contained in:
parent
f15291031a
commit
81fc987f89
@ -1,7 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
import pytest
|
|
||||||
from truthseeker import APP
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from truthseeker import APP
|
||||||
test_app = APP.test_client()
|
test_app = APP.test_client()
|
||||||
|
|
||||||
class TestException(Exception):
|
class TestException(Exception):
|
||||||
@ -26,7 +27,7 @@ class User:
|
|||||||
self.username = username
|
self.username = username
|
||||||
self.isAdmin = False
|
self.isAdmin = False
|
||||||
|
|
||||||
def createGame(user:User):
|
def create_game(user:User):
|
||||||
data = {"username":user.username}
|
data = {"username":user.username}
|
||||||
responseObject = test_app.post("/api/v1/createGame",data=data)
|
responseObject = test_app.post("/api/v1/createGame",data=data)
|
||||||
if responseObject.status_code != 200:
|
if responseObject.status_code != 200:
|
||||||
@ -40,7 +41,7 @@ def createGame(user:User):
|
|||||||
return content["game_id"]
|
return content["game_id"]
|
||||||
|
|
||||||
|
|
||||||
def joinGame(user:User,game_id:str):
|
def join_game(user:User,game_id:str):
|
||||||
data = {"username":user.username,"game_id":game_id}
|
data = {"username":user.username,"game_id":game_id}
|
||||||
responseObject = test_app.post("/api/v1/joinGame",data=data)
|
responseObject = test_app.post("/api/v1/joinGame",data=data)
|
||||||
if responseObject.status_code != 200:
|
if responseObject.status_code != 200:
|
||||||
@ -52,7 +53,7 @@ def joinGame(user:User,game_id:str):
|
|||||||
raise TestException("backend returned an error: "+content["msg"])
|
raise TestException("backend returned an error: "+content["msg"])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def startGame(user:User):
|
def start_game(user:User):
|
||||||
responseObject = test_app.post("/api/v1/startGame")
|
responseObject = test_app.post("/api/v1/startGame")
|
||||||
if responseObject.status_code != 200:
|
if responseObject.status_code != 200:
|
||||||
raise TestException("status code is not 200")
|
raise TestException("status code is not 200")
|
||||||
@ -78,20 +79,20 @@ def startGame(user:User):
|
|||||||
|
|
||||||
def test_that_people_can_create_a_game():
|
def test_that_people_can_create_a_game():
|
||||||
user = User("neotaku")
|
user = User("neotaku")
|
||||||
assert createGame(user) != False
|
assert create_game(user) != False
|
||||||
|
|
||||||
def test_that_two_person_creating_two_games_results_in_two_distincts_game():
|
def test_that_two_person_creating_two_games_results_in_two_distincts_game():
|
||||||
userOne = User("neorage")
|
userOne = User("neorage")
|
||||||
userTwo = User("neobergine")
|
userTwo = User("neobergine")
|
||||||
gameOne = createGame(userOne)
|
gameOne = create_game(userOne)
|
||||||
gameTwo = createGame(userTwo)
|
gameTwo = create_game(userTwo)
|
||||||
assert gameOne != gameTwo
|
assert gameOne != gameTwo
|
||||||
|
|
||||||
def test_that_two_person_having_the_same_pseudo_creating_two_games_results_in_two_distincts_games():
|
def test_that_two_person_having_the_same_pseudo_creating_two_games_results_in_two_distincts_games():
|
||||||
userOne = User("neo")
|
userOne = User("neo")
|
||||||
userTwo = User("neo")
|
userTwo = User("neo")
|
||||||
gameOne = createGame(userOne)
|
gameOne = create_game(userOne)
|
||||||
gameTwo = createGame(userTwo)
|
gameTwo = create_game(userTwo)
|
||||||
assert gameOne != gameTwo
|
assert gameOne != gameTwo
|
||||||
|
|
||||||
|
|
||||||
@ -104,17 +105,17 @@ def test_that_not_sending_a_username_results_in_an_error():
|
|||||||
def test_that_sending_a_empty_username_results_in_an_error():
|
def test_that_sending_a_empty_username_results_in_an_error():
|
||||||
user = User("")
|
user = User("")
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
createGame(user)
|
create_game(user)
|
||||||
|
|
||||||
def test_that_a_too_long_username_results_in_an_error():
|
def test_that_a_too_long_username_results_in_an_error():
|
||||||
user = User("Le test unitaire est un moyen de vérifier qu’un extrait de code fonctionne correctement. C’est l’une des procédures mises en oeuvre dans le cadre d’une méthodologie de travail agile. ")
|
user = User("Le test unitaire est un moyen de vérifier qu’un extrait de code fonctionne correctement. C’est l’une des procédures mises en oeuvre dans le cadre d’une méthodologie de travail agile. ")
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
createGame(user)
|
create_game(user)
|
||||||
|
|
||||||
def test_that_username_that_contains_non_alphanumerics_results_in_an_error():
|
def test_that_username_that_contains_non_alphanumerics_results_in_an_error():
|
||||||
user = User("я русский пират")
|
user = User("я русский пират")
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
createGame(user)
|
create_game(user)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# #
|
# #
|
||||||
@ -128,23 +129,23 @@ def test_that_username_that_contains_non_alphanumerics_results_in_an_error():
|
|||||||
# (game_id) l'utilisateur indentifié par son pseudo (username)
|
# (game_id) l'utilisateur indentifié par son pseudo (username)
|
||||||
|
|
||||||
def test_that_people_can_join_a_game():
|
def test_that_people_can_join_a_game():
|
||||||
game_id = createGame(User("neoracle"))
|
game_id = create_game(User("neoracle"))
|
||||||
assert joinGame(User("neobjectif"),game_id) == True
|
assert join_game(User("neobjectif"),game_id) == True
|
||||||
|
|
||||||
def test_that_two_person_can_join_a_game():
|
def test_that_two_person_can_join_a_game():
|
||||||
game_id = createGame(User("neomblic"))
|
game_id = create_game(User("neomblic"))
|
||||||
joueur1_a_join = joinGame(User("neobjectif"),game_id)
|
joueur1_a_join = join_game(User("neobjectif"),game_id)
|
||||||
joueur2_a_join = joinGame(User("neorgane"),game_id)
|
joueur2_a_join = join_game(User("neorgane"),game_id)
|
||||||
assert joueur1_a_join == True and joueur2_a_join == True
|
assert joueur1_a_join == True and joueur2_a_join == True
|
||||||
|
|
||||||
def test_that_people_cant_join_if_the_username_is_already_used():
|
def test_that_people_cant_join_if_the_username_is_already_used():
|
||||||
game_id = createGame(User("neoreille"))
|
game_id = create_game(User("neoreille"))
|
||||||
joinGame(User("neosomse"),game_id)
|
join_game(User("neosomse"),game_id)
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
joinGame(User("neosomse"),game_id)
|
join_game(User("neosomse"),game_id)
|
||||||
|
|
||||||
def test_that_people_joining_without_sending_any_data_results_in_an_error():
|
def test_that_people_joining_without_sending_any_data_results_in_an_error():
|
||||||
game_id = createGame(User("neoxyde"))
|
game_id = create_game(User("neoxyde"))
|
||||||
responseObject = test_app.post("/api/v1/joinGame")
|
responseObject = test_app.post("/api/v1/joinGame")
|
||||||
assert responseObject.status_code == 200
|
assert responseObject.status_code == 200
|
||||||
assert responseObject.json["error"] != 0
|
assert responseObject.json["error"] != 0
|
||||||
@ -156,32 +157,32 @@ def test_that_people_joining_without_sending_a_game_id_results_in_an_error():
|
|||||||
assert responseObject.json["error"] != 0
|
assert responseObject.json["error"] != 0
|
||||||
|
|
||||||
def test_that_people_joining_without_sending_an_username_still_results_in_an_error():
|
def test_that_people_joining_without_sending_an_username_still_results_in_an_error():
|
||||||
game_id = createGame(User("neonyx"))
|
game_id = create_game(User("neonyx"))
|
||||||
data={"game_id":game_id}
|
data={"game_id":game_id}
|
||||||
responseObject = test_app.post("/api/v1/joinGame",data=data)
|
responseObject = test_app.post("/api/v1/joinGame",data=data)
|
||||||
assert responseObject.status_code == 200
|
assert responseObject.status_code == 200
|
||||||
assert responseObject.json["error"] != 0
|
assert responseObject.json["error"] != 0
|
||||||
|
|
||||||
def test_that_people_joining_with_an_empty_username_still_results_in_an_error():
|
def test_that_people_joining_with_an_empty_username_still_results_in_an_error():
|
||||||
game_id = createGame(User("neodeur"))
|
game_id = create_game(User("neodeur"))
|
||||||
user = User("")
|
user = User("")
|
||||||
|
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
joinGame(user,game_id)
|
join_game(user,game_id)
|
||||||
|
|
||||||
def test_that_people_joining_aving_an_username_that_contains_non_alphanumerics_still_results_in_an_error():
|
def test_that_people_joining_aving_an_username_that_contains_non_alphanumerics_still_results_in_an_error():
|
||||||
game_id = createGame(User("neobservateur"))
|
game_id = create_game(User("neobservateur"))
|
||||||
user = User("Я брат русского пирата")
|
user = User("Я брат русского пирата")
|
||||||
|
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
joinGame(user,game_id)
|
join_game(user,game_id)
|
||||||
|
|
||||||
def test_that_people_joining_aving_a_too_long_username_still_results_in_an_error():
|
def test_that_people_joining_aving_a_too_long_username_still_results_in_an_error():
|
||||||
game_id = createGame(User("neordre"))
|
game_id = create_game(User("neordre"))
|
||||||
user = User("Les tests unitaires sont généralement effectués pendant la phase de développement des applications mobiles ou logicielles. Ces tests sont normalement effectués par les développeurs, bien qu’à toutes fins pratiques, ils puissent également être effectués par les responsables en assurance QA.")
|
user = User("Les tests unitaires sont généralement effectués pendant la phase de développement des applications mobiles ou logicielles. Ces tests sont normalement effectués par les développeurs, bien qu’à toutes fins pratiques, ils puissent également être effectués par les responsables en assurance QA.")
|
||||||
|
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
joinGame(user,game_id)
|
join_game(user,game_id)
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -199,20 +200,20 @@ def test_that_people_joining_aving_a_too_long_username_still_results_in_an_error
|
|||||||
|
|
||||||
def test_that_people_can_start_a_game():
|
def test_that_people_can_start_a_game():
|
||||||
owner = User("neAUBERGINE")
|
owner = User("neAUBERGINE")
|
||||||
game_id = createGame(owner)
|
game_id = create_game(owner)
|
||||||
startGame(owner)
|
start_game(owner)
|
||||||
|
|
||||||
def test_that_a_started_game_cannot_be_started_again():
|
def test_that_a_started_game_cannot_be_started_again():
|
||||||
owner = User("neosteopathie")
|
owner = User("neosteopathie")
|
||||||
game_id = createGame(owner)
|
game_id = create_game(owner)
|
||||||
startGame(owner)
|
start_game(owner)
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
startGame(owner)
|
start_game(owner)
|
||||||
|
|
||||||
def test_that_non_owners_cant_start_a_game():
|
def test_that_non_owners_cant_start_a_game():
|
||||||
owner = User("neosteopathie")
|
owner = User("neosteopathie")
|
||||||
notOwner = User("neorphelin")
|
notOwner = User("neorphelin")
|
||||||
game_id = createGame(owner)
|
game_id = create_game(owner)
|
||||||
joinGame(notOwner,game_id)
|
join_game(notOwner,game_id)
|
||||||
with pytest.raises(TestException) as e:
|
with pytest.raises(TestException) as e:
|
||||||
startGame(notOwner)
|
start_game(notOwner)
|
||||||
|
@ -66,7 +66,7 @@ class Game:
|
|||||||
self.members.append(self.owner)
|
self.members.append(self.owner)
|
||||||
return self.owner
|
return self.owner
|
||||||
|
|
||||||
def generateGameResults(self) -> None:
|
def generate_game_results(self) -> None:
|
||||||
"""
|
"""
|
||||||
TODO + TODO RET TYPE
|
TODO + TODO RET TYPE
|
||||||
"""
|
"""
|
||||||
@ -88,7 +88,7 @@ class Game:
|
|||||||
TODO
|
TODO
|
||||||
"""
|
"""
|
||||||
#TODO Get language from player
|
#TODO Get language from player
|
||||||
self.gamedata, self.reaction_table = generateGameData("FR")
|
self.gamedata, self.reaction_table = generate_game_data("FR")
|
||||||
|
|
||||||
def get_member(self, username: str) -> Union[Member, None]:
|
def get_member(self, username: str) -> Union[Member, None]:
|
||||||
"""
|
"""
|
||||||
@ -123,7 +123,7 @@ class Game:
|
|||||||
reaction_id = self.reaction_table[npc_id][int(reaction)]
|
reaction_id = self.reaction_table[npc_id][int(reaction)]
|
||||||
return read_image(f"./truthseeker/static/images/npc/{npc_id}/{reaction_id}.png")
|
return read_image(f"./truthseeker/static/images/npc/{npc_id}/{reaction_id}.png")
|
||||||
|
|
||||||
def getPlayerResults(self, responses: dict) -> None:
|
def get_player_results(self, responses: dict) -> None:
|
||||||
"""
|
"""
|
||||||
TODO + TODO RETTYPE
|
TODO + TODO RETTYPE
|
||||||
"""
|
"""
|
||||||
@ -198,14 +198,14 @@ def check_username(username: str) -> bool:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def generateNpcText(npc: tables.Npc, lang: str) -> dict:
|
def generate_npc_text(npc: tables.Npc, lang: str) -> dict:
|
||||||
data = {}
|
data = {}
|
||||||
data["name"] = get_text_from_lid(lang, npc.NAME_LID)
|
data["name"] = get_text_from_lid(lang, npc.NAME_LID)
|
||||||
data["QA_0"] = get_text_from_lid(lang, get_npc_random_answer(npc,0).TEXT_LID)
|
data["QA_0"] = get_text_from_lid(lang, get_npc_random_answer(npc,0).TEXT_LID)
|
||||||
data["QA_1"] = get_text_from_lid(lang, get_npc_random_answer(npc,1).TEXT_LID)
|
data["QA_1"] = get_text_from_lid(lang, get_npc_random_answer(npc,1).TEXT_LID)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def generateNpcReactions(npc: tables.Npc) ->list:
|
def generate_npc_reactions(npc: tables.Npc) ->list:
|
||||||
return get_npc_random_trait_id(npc)
|
return get_npc_random_trait_id(npc)
|
||||||
|
|
||||||
def generate_place_data(npcs: list, places: list, lang: str) -> dict:
|
def generate_place_data(npcs: list, places: list, lang: str) -> dict:
|
||||||
@ -221,7 +221,7 @@ def generate_place_data(npcs: list, places: list, lang: str) -> dict:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def generateGameData(LANG):
|
def generate_game_data(LANG):
|
||||||
data = {}
|
data = {}
|
||||||
data["npcs"] = {}
|
data["npcs"] = {}
|
||||||
reactions_table = {}
|
reactions_table = {}
|
||||||
@ -231,8 +231,8 @@ def generateGameData(LANG):
|
|||||||
if npc not in npcs :
|
if npc not in npcs :
|
||||||
npcs.append(npc)
|
npcs.append(npc)
|
||||||
for npc in npcs:
|
for npc in npcs:
|
||||||
data["npcs"][str(npc.NPC_ID)] = generateNpcText(npc,LANG)
|
data["npcs"][str(npc.NPC_ID)] = generate_npc_text(npc,LANG)
|
||||||
reactions_table[str(npc.NPC_ID)] = generateNpcReactions(npc)
|
reactions_table[str(npc.NPC_ID)] = generate_npc_reactions(npc)
|
||||||
|
|
||||||
places = []
|
places = []
|
||||||
while len(places) != 3:
|
while len(places) != 3:
|
||||||
|
@ -185,14 +185,14 @@ def checkAnwser():
|
|||||||
if playerResponses == None:
|
if playerResponses == None:
|
||||||
return {"error": 1, "msg": "no responses were sent"}
|
return {"error": 1, "msg": "no responses were sent"}
|
||||||
|
|
||||||
results = game.getPlayerResults(json.loads(playerResponses))
|
results = game.get_player_results(json.loads(playerResponses))
|
||||||
if results == False:
|
if results == False:
|
||||||
return {"error": 1, "msg": "invalid npc sent"}
|
return {"error": 1, "msg": "invalid npc sent"}
|
||||||
|
|
||||||
member.has_submitted = True
|
member.has_submitted = True
|
||||||
member.results = results
|
member.results = results
|
||||||
if game.has_finished():
|
if game.has_finished():
|
||||||
jsonGameResults = game.generateGameResults()
|
jsonGameResults = game.generate_game_results()
|
||||||
APP.socketio_app.emit("gamefinshed",jsonGameResults,room="game."+game.game_id)
|
APP.socketio_app.emit("gamefinshed",jsonGameResults,room="game."+game.game_id)
|
||||||
response = {"error": 0}
|
response = {"error": 0}
|
||||||
return response
|
return response
|
||||||
|
Loading…
Reference in New Issue
Block a user