Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
FIX and REFACTOR
Browse files Browse the repository at this point in the history
  • Loading branch information
claussmann committed Feb 20, 2024
1 parent e27d119 commit 673b513
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Open Web Quiz
# pyTeamQuiz

This is a small webservice for makeing a local quiz with your friends.
This is a small webservice for making a local quiz with your friends.
Run the webservice on a computer and open it in the browser of your smart TV or other device.

## Run in development
Expand Down
43 changes: 11 additions & 32 deletions pyteamquiz/test/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pyteamquiz.game import *
import os

def get_catalogue_1():
def catalogue_1():
content = """
What is correct 1?;;A;;B;;C;;D
What is correct 2?;;A;;B;;C;;D;;E
Expand All @@ -17,7 +17,7 @@ def get_catalogue_1():
os.remove(filename)
return catalogue

def get_catalogue_2():
def catalogue_2():
content = """
Foo?;;A;;B;;C;;D
Bar?;;A;;B;;C
Expand All @@ -31,19 +31,13 @@ def get_catalogue_2():
return catalogue

def test_game_teams_turn():
g = Game(
{get_catalogue_1(), get_catalogue_2()},
{"Team A", "Team B"}
)
g = Game({catalogue_1(), catalogue_2()}, {"Team A", "Team B"}, 1)
whose_turn = g.whose_turn()
assert g.submit_answer("A") == (True, "A")
assert whose_turn != g.whose_turn()

def test_game_error_when_questions_empty():
g = Game(
{get_catalogue_1(), get_catalogue_2()},
{"Team A", "Team B"}
)
g = Game({catalogue_1(), catalogue_2()}, {"Team A", "Team B"}, 2)
assert g.submit_answer("A") == (True, "A")
assert g.has_next()
g.get_question()
Expand All @@ -58,24 +52,15 @@ def test_game_error_when_questions_empty():
g.get_question()

def test_game_exception_when_too_few_questions():
# Fewer questions than teams
with pytest.raises(NotEnoughQuestionsError):
g = Game(
{},
{"Team A", "Team B", "Team C"}
)
# Every team must get at least one question
g = Game({}, {"Team A", "Team B", "Team C"}, 0)
with pytest.raises(NotEnoughQuestionsError):
g = Game(
{get_catalogue_1()},
{"Team A", "Team B", "Team C"}
)
g = Game({catalogue_1()}, {"Team A", "Team B", "Team C"}, 1)

def test_game_every_player_same_number_questions():
# Only 4 questions for 3 teams
g = Game(
{get_catalogue_1(), get_catalogue_2()},
{"Team A", "Team B", "Team C"}
)
# 1 question for each of 3 teams
g = Game({catalogue_1(), catalogue_2()}, {"Team A", "Team B", "Team C"}, 1)
g.submit_answer("A")
g.get_question()
g.submit_answer("A")
Expand All @@ -85,12 +70,6 @@ def test_game_every_player_same_number_questions():

def test_game_at_least_two_teams():
with pytest.raises(NotEnoughTeamsError):
g = Game(
{get_catalogue_1()},
{}
)
g = Game({catalogue_1()}, {}, 1)
with pytest.raises(NotEnoughTeamsError):
g = Game(
{get_catalogue_1()},
{"Team A"}
)
g = Game({catalogue_1()}, {"Team A"}, 1)
6 changes: 3 additions & 3 deletions pyteamquiz/test/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os


def get_catalogue_1():
def catalogue_1():
content = """
What is correct?;;A;;B;;C;;D
What is correct?;;A;;B;;C;;D;;E
Expand All @@ -22,6 +22,6 @@ def get_catalogue_1():
return catalogue

def test_game_creation():
catalogues["Example.txt"] = get_catalogue_1()
token = service.new_game({"Example.txt"}, {"Team A", "Team B"})
catalogues["Example"] = catalogue_1()
token = service.new_game({"Example"}, {"Team A", "Team B"}, 1)
assert service.get_current_question_text(token) == "What is correct?"

0 comments on commit 673b513

Please sign in to comment.