convert remaining functions to snake_case

This commit is contained in:
Thomas Rubini 2023-01-13 13:53:20 +01:00
parent f15291031a
commit 81fc987f89
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
3 changed files with 48 additions and 47 deletions

View File

@ -1,7 +1,8 @@
import json
import pytest
from truthseeker import APP
import pytest
from truthseeker import APP
test_app = APP.test_client()
class TestException(Exception):
@ -26,7 +27,7 @@ class User:
self.username = username
self.isAdmin = False
def createGame(user:User):
def create_game(user:User):
data = {"username":user.username}
responseObject = test_app.post("/api/v1/createGame",data=data)
if responseObject.status_code != 200:
@ -40,7 +41,7 @@ def createGame(user:User):
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}
responseObject = test_app.post("/api/v1/joinGame",data=data)
if responseObject.status_code != 200:
@ -52,7 +53,7 @@ def joinGame(user:User,game_id:str):
raise TestException("backend returned an error: "+content["msg"])
return True
def startGame(user:User):
def start_game(user:User):
responseObject = test_app.post("/api/v1/startGame")
if responseObject.status_code != 200:
raise TestException("status code is not 200")
@ -78,20 +79,20 @@ def startGame(user:User):
def test_that_people_can_create_a_game():
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():
userOne = User("neorage")
userTwo = User("neobergine")
gameOne = createGame(userOne)
gameTwo = createGame(userTwo)
gameOne = create_game(userOne)
gameTwo = create_game(userTwo)
assert gameOne != gameTwo
def test_that_two_person_having_the_same_pseudo_creating_two_games_results_in_two_distincts_games():
userOne = User("neo")
userTwo = User("neo")
gameOne = createGame(userOne)
gameTwo = createGame(userTwo)
gameOne = create_game(userOne)
gameTwo = create_game(userTwo)
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():
user = User("")
with pytest.raises(TestException) as e:
createGame(user)
create_game(user)
def test_that_a_too_long_username_results_in_an_error():
user = User("Le test unitaire est un moyen de vérifier quun extrait de code fonctionne correctement. Cest lune des procédures mises en oeuvre dans le cadre dune méthodologie de travail agile. ")
with pytest.raises(TestException) as e:
createGame(user)
create_game(user)
def test_that_username_that_contains_non_alphanumerics_results_in_an_error():
user = User("я русский пират")
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)
def test_that_people_can_join_a_game():
game_id = createGame(User("neoracle"))
assert joinGame(User("neobjectif"),game_id) == True
game_id = create_game(User("neoracle"))
assert join_game(User("neobjectif"),game_id) == True
def test_that_two_person_can_join_a_game():
game_id = createGame(User("neomblic"))
joueur1_a_join = joinGame(User("neobjectif"),game_id)
joueur2_a_join = joinGame(User("neorgane"),game_id)
game_id = create_game(User("neomblic"))
joueur1_a_join = join_game(User("neobjectif"),game_id)
joueur2_a_join = join_game(User("neorgane"),game_id)
assert joueur1_a_join == True and joueur2_a_join == True
def test_that_people_cant_join_if_the_username_is_already_used():
game_id = createGame(User("neoreille"))
joinGame(User("neosomse"),game_id)
game_id = create_game(User("neoreille"))
join_game(User("neosomse"),game_id)
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():
game_id = createGame(User("neoxyde"))
game_id = create_game(User("neoxyde"))
responseObject = test_app.post("/api/v1/joinGame")
assert responseObject.status_code == 200
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
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}
responseObject = test_app.post("/api/v1/joinGame",data=data)
assert responseObject.status_code == 200
assert responseObject.json["error"] != 0
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("")
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():
game_id = createGame(User("neobservateur"))
game_id = create_game(User("neobservateur"))
user = User("Я брат русского пирата")
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():
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.")
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():
owner = User("neAUBERGINE")
game_id = createGame(owner)
startGame(owner)
game_id = create_game(owner)
start_game(owner)
def test_that_a_started_game_cannot_be_started_again():
owner = User("neosteopathie")
game_id = createGame(owner)
startGame(owner)
game_id = create_game(owner)
start_game(owner)
with pytest.raises(TestException) as e:
startGame(owner)
start_game(owner)
def test_that_non_owners_cant_start_a_game():
owner = User("neosteopathie")
notOwner = User("neorphelin")
game_id = createGame(owner)
joinGame(notOwner,game_id)
game_id = create_game(owner)
join_game(notOwner,game_id)
with pytest.raises(TestException) as e:
startGame(notOwner)
start_game(notOwner)

View File

@ -66,7 +66,7 @@ class Game:
self.members.append(self.owner)
return self.owner
def generateGameResults(self) -> None:
def generate_game_results(self) -> None:
"""
TODO + TODO RET TYPE
"""
@ -88,7 +88,7 @@ class Game:
TODO
"""
#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]:
"""
@ -123,7 +123,7 @@ class Game:
reaction_id = self.reaction_table[npc_id][int(reaction)]
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
"""
@ -198,14 +198,14 @@ def check_username(username: str) -> bool:
return True
def generateNpcText(npc: tables.Npc, lang: str) -> dict:
def generate_npc_text(npc: tables.Npc, lang: str) -> dict:
data = {}
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_1"] = get_text_from_lid(lang, get_npc_random_answer(npc,1).TEXT_LID)
return data
def generateNpcReactions(npc: tables.Npc) ->list:
def generate_npc_reactions(npc: tables.Npc) ->list:
return get_npc_random_trait_id(npc)
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
def generateGameData(LANG):
def generate_game_data(LANG):
data = {}
data["npcs"] = {}
reactions_table = {}
@ -231,8 +231,8 @@ def generateGameData(LANG):
if npc not in npcs :
npcs.append(npc)
for npc in npcs:
data["npcs"][str(npc.NPC_ID)] = generateNpcText(npc,LANG)
reactions_table[str(npc.NPC_ID)] = generateNpcReactions(npc)
data["npcs"][str(npc.NPC_ID)] = generate_npc_text(npc,LANG)
reactions_table[str(npc.NPC_ID)] = generate_npc_reactions(npc)
places = []
while len(places) != 3:

View File

@ -185,14 +185,14 @@ def checkAnwser():
if playerResponses == None:
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:
return {"error": 1, "msg": "invalid npc sent"}
member.has_submitted = True
member.results = results
if game.has_finished():
jsonGameResults = game.generateGameResults()
jsonGameResults = game.generate_game_results()
APP.socketio_app.emit("gamefinshed",jsonGameResults,room="game."+game.game_id)
response = {"error": 0}
return response