diff --git a/__pycache__/oo_package.cpython-311.pyc b/__pycache__/oo_package.cpython-311.pyc index 3e194cc..22e1903 100644 Binary files a/__pycache__/oo_package.cpython-311.pyc and b/__pycache__/oo_package.cpython-311.pyc differ diff --git a/__pycache__/test_api_auto.cpython-311-pytest-7.2.2.pyc b/__pycache__/test_api_auto.cpython-311-pytest-7.2.2.pyc index e8f95ed..5cdbbc3 100644 Binary files a/__pycache__/test_api_auto.cpython-311-pytest-7.2.2.pyc and b/__pycache__/test_api_auto.cpython-311-pytest-7.2.2.pyc differ diff --git a/database.db b/database.db index 3e2c03a..f403d4a 100644 Binary files a/database.db and b/database.db differ diff --git a/oo_package.py b/oo_package.py index 4dfdc67..673a245 100644 --- a/oo_package.py +++ b/oo_package.py @@ -2,6 +2,7 @@ from main import app import json import os +import time client = TestClient(app=app) @@ -77,6 +78,17 @@ def print_status(self): scoreboard = Scoreboard(teams_data = teams_data) scoreboard.print_status(self.team_name) + def live(self): + if self.__logged_in == False: + print('login first') + return + teams_data = self.get_teams_table() + scoreboard = Scoreboard(teams_data = teams_data) + scoreboard.print_rankings() + time.sleep(1) + os.system('cls' if os.name == 'nt' else 'clear') + self.live() + def interactive_menu(self): if self.__logged_in == False: print('login first') @@ -118,16 +130,26 @@ def interactive_menu(self): class Team(): - def __init__(self, name, score, solved_questions=[]): + def __init__(self, name, score, solved_questions=[],color='\033[1m'): self.name = name self.score = score self.solved_questions = solved_questions + self.color = color def __str__(self): - if len(self.name) < 8: - answer = "TEAM NAME: "+ self.name + "\t\t SCORE: " + str(self.score) + "\t ANSWERED QUESTIONS: " + str(len(self.solved_questions)) + c = self.color + b = '\033[1m' + nb = '\033[0m' + first = "| "+ c + "NAME: "+b+ self.name + nb + second = "| "+ c + "SCORE: " + b + str(self.score) + nb + third = "| "+ c + "ANSWERED QUESTIONS: " + b + str(len(self.solved_questions)) + nb + "\t|" + '\033[0m' + + if len(first) <= 8: + answer = first + "\t\t" + second + "\t\t" + third + elif len(first) <= 16: + answer = first + "\t" + second + "\t\t" + third else: - answer = "TEAM NAME: "+ self.name + "\t SCORE: " + str(self.score) + + "\t ANSWERED QUESTIONS: " + str(len(self.solved_questions)) + answer = first + "\t\t\t" + second + "\t\t" + third return answer @@ -140,15 +162,19 @@ def __init__(self,teams_data): def load_teams(self): for team in self.teams_data['teams']: solved_qs = json.loads(team[3]) - self.teams.append(Team(name=team[0],score=team[2],solved_questions=solved_qs)) + color = team[4] + self.teams.append(Team(name=team[0],score=team[2],solved_questions=solved_qs,color=color)) def print_rankings(self): #this function needs to add colors to the teams which are read from the json file #os.system('cls' if os.name == 'nt' else 'clear') ordered_teams = sorted(self.teams, key=lambda x: x.score, reverse=True) + headline = '\033[1m' + 'HERE IS THE CURRENT SCOREBOARD' + '\033[0m' + print(headline.center(97,'.')) + print('-'*89) for team in ordered_teams: print(team) - + print('-'*89) def print_status(self,team_name): for team in self.teams: if team.name == team_name: diff --git a/reset_db.py b/reset_db.py index 35a1a72..d0ed282 100644 --- a/reset_db.py +++ b/reset_db.py @@ -55,10 +55,10 @@ solved_qs = json.dumps([]) print(solved_qs, type(solved_qs)) -c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('team1', 'team1', 0, solved_qs, 'red', False)) -c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('team2', 'team2', 0, solved_qs, 'blue', False)) -c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('team3', 'team3', 0, solved_qs, 'green', False)) -c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('team4', 'team4', 0, solved_qs, 'yellow', False)) +c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('Mount Waverley', 'abc', 0, solved_qs, '\033[33m', False)) +c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('Box Hill', 'abc', 0, solved_qs, '\033[34m', False)) +c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('Melbourne High', 'abc', 0, solved_qs, '\033[92m', False)) +c.execute("INSERT INTO teams VALUES (?, ?, ?, ?, ?, ?)", ('Wantirna', 'abc', 0, solved_qs, '\033[35m', False)) conn.commit() conn.close() diff --git a/test_api_auto.py b/test_api_auto.py index a1d826a..98eae5e 100644 --- a/test_api_auto.py +++ b/test_api_auto.py @@ -1,7 +1,8 @@ from fastapi.testclient import TestClient -from main import app +import sys import time - +sys.path.insert(0, 'G:\My Drive\PROJECTS\FAST_API_TEST\APP') +from app import main client = TestClient(app=app) @@ -26,31 +27,31 @@ def test_question_contains_attachment(): def test_submit_answer(): - response = client.post("/submit_answer", json={"id": "1", "answer": "Sanjin", "team_name": "team1"}) + response = client.post("/submit_answer", json={"id": "1", "answer": "Sanjin", "team_name": "Mount Waverley"}) assert response.status_code == 200 assert "Correct" in response.json()["message"] def test_submit_second_answer(): - response = client.post("/submit_answer", json={"id": "2", "answer": "38", "team_name": "team1"}) + response = client.post("/submit_answer", json={"id": "2", "answer": "38", "team_name": "Mount Waverley"}) assert response.status_code == 200 assert "Correct" in response.json()["message"] def test_submit_answer_again(): - response = client.post("/submit_answer", json={"id": "1", "answer": "Sanjin", "team_name": "team1"}) + response = client.post("/submit_answer", json={"id": "1", "answer": "Sanjin", "team_name": "Mount Waverley"}) assert response.status_code == 200 assert "Already solved" in response.json()["message"] def test_submit_answer_wrong(): - response = client.post("/submit_answer", json={"id": "1", "answer": "Bob", "team_name": "team1"}) + response = client.post("/submit_answer", json={"id": "1", "answer": "Bob", "team_name": "Mount Waverley"}) assert response.status_code == 200 assert response.json() == {"message": "Incorrect"} def test_submit_answer_nonexisting(): - response = client.post("/submit_answer", json={"id": "10000", "answer": "Bob", "team_name": "team1"}) + response = client.post("/submit_answer", json={"id": "10000", "answer": "Bob", "team_name": "Mount Waverley"}) assert response.status_code == 200 assert response.json() == {"message": "Question not found"} @@ -68,13 +69,13 @@ def test_download_starter_code(): def test_valid_login(): - response = client.post("/login", json={"name": "team1", "password": "team1"}) + response = client.post("/login", json={"name": "Mount Waverley", "password": "abc"}) assert response.status_code == 200 assert "Login successful" in response.json()["message"] def test_invalid_login(): - response = client.post("/login", json={"name": "team1", "password": "xxxxx"}) + response = client.post("/login", json={"name": "Mount Waverley", "password": "xxxxx"}) print(response.json()) assert response.status_code == 200 assert "Login failed" in response.json()["message"] @@ -83,26 +84,16 @@ def test_invalid_login(): def test_get_teams_table(): response = client.get("/get_teams_table") assert response.status_code == 200 - assert "team1" in response.json()["teams"][0][0] - assert "team2" in response.json()["teams"][1][0] - assert "team3" in response.json()["teams"][2][0] - assert "team4" in response.json()["teams"][3][0] + assert "Mount Waverley" in response.json()["teams"][0][0] + assert "Box Hill" in response.json()["teams"][1][0] + assert "Melbourne High" in response.json()["teams"][2][0] + assert "Wantirna" in response.json()["teams"][3][0] assert response.json()["teams"][0][2] == 20 assert response.json()["teams"][1][2] == 0 assert response.json()["teams"][2][2] == 0 assert response.json()["teams"][3][2] == 0 assert response.json()["teams"][0][3] == '[1, 2]' -def submit_answer1(): - response = client.post("/submit_answer", json={"id": "1", "answer": "Sanjin", "team_name": "team1"}) - print(response.json()) - print(response.status_code) - print(response.content) - -def get_teams_table(): - response = client.get("/get_teams_table") - print(response.json()) - #this always needs to be the last test def reset_db_just_run_file(): @@ -112,5 +103,4 @@ def reset_db_just_run_file(): time.sleep(1) -reset_db_just_run_file() -get_teams_table() +reset_db_just_run_file() \ No newline at end of file diff --git a/test_live_score.py b/test_live_score.py new file mode 100644 index 0000000..606d32a --- /dev/null +++ b/test_live_score.py @@ -0,0 +1,5 @@ +from oo_package import Quiz + +competition = Quiz(team_name='Mount Waverley',team_password='abc') + +competition.interactive_menu() \ No newline at end of file diff --git a/test_oo_sim.py b/test_oo_sim.py index fa4bd4f..f8946f5 100644 --- a/test_oo_sim.py +++ b/test_oo_sim.py @@ -2,25 +2,25 @@ import time time.sleep(1) -with open("reset_db.py") as f: - exec(f.read()) +#with open("reset_db.py") as f: +# exec(f.read()) time.sleep(1) -competition = Quiz(team_name='team1',team_password='team1') - +competition = Quiz(team_name='Mount Waverley',team_password='abc') +print(competition.get_question(1)) competition.submit_answer(1,'Sanjin') competition.print_rankings() time.sleep(2) -competition = Quiz(team_name='team2',team_password='team2') +competition = Quiz(team_name='Box Hill',team_password='abc') competition.submit_answer(2,'38') competition.submit_answer(3,'Python') competition.print_rankings() time.sleep(2) -competition = Quiz(team_name='team3',team_password='team3') +competition = Quiz(team_name='Melbourne High',team_password='abc') competition.submit_answer(2,'38') competition.submit_answer(3,'Python') sol = '''cerpxazeceaqacth @@ -31,7 +31,7 @@ time.sleep(2) -competition = Quiz(team_name='team4',team_password='team4') +competition = Quiz(team_name='Wantirna',team_password='abc') competition.submit_answer(1,'Sanjin') competition.submit_answer(2,'38') competition.submit_answer(3,'Python')