Skip to content

Commit

Permalink
Merge pull request #94 from codersforcauses/colour
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
Anay-Joshi26 authored Feb 17, 2024
2 parents 3a3ff90 + 38486b0 commit 38a2174
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
Empty file added app/core/__init__.py
Empty file.
Empty file added app/tests/__init__.py
Empty file.
61 changes: 61 additions & 0 deletions app/tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pytest

from core.utils import sanitise_gamedata
from backend.database import *


def test_sanitise():
control_game_mode = "city"
control_usern = "testuser"
control_totalscore = 0

# TEST THE GAME MODE VALIDITY
valid_gamemodes = ["city", "discoveries", "sleuth", "landmark"]
for game in valid_gamemodes:
assert sanitise_gamedata(game, control_usern, control_totalscore)[0] == game

invaid_gamemode = "THIS IS NOT A GAMEMODE"
assert sanitise_gamedata(invaid_gamemode, control_usern, control_totalscore)[0] == "city"

# TEST THE USERNAME VALIDITY
valid_usernames = ["testuser", "test.user", "test_user", "test_user_123."]
for username in valid_usernames:
assert sanitise_gamedata(control_game_mode, username, control_totalscore)[1] == username

invalid_username = "f@ucky!ou"
assert sanitise_gamedata(control_game_mode, invalid_username, control_totalscore)[1] == "fuckyou"

# TEST TOTALSORE VALIDITY
valid_totalscores = [0, 2000, 300, 3043]
for score in valid_totalscores:
assert sanitise_gamedata(control_game_mode, control_usern, score)[2] == score

invalid_totalscore = "piss" #string is an invalid total score
assert sanitise_gamedata(control_game_mode, control_usern, invalid_totalscore)[2] == 0

def test_new_leaderboard_entry():

valid_username = "TEST_USERNAME_DB"
valid_gamemode = 'city'
valid_totalscore = 500

opt = update_game(valid_gamemode, valid_username, valid_totalscore)

assert opt == {"score":"complete", "alert":"no new high score"}

existing_username = "pinpoint_bot"
new_highscore = 500
assert update_game(valid_gamemode, existing_username, new_highscore) == {"score":"complete", "alert":"new high score"}

existing_username = "pinpoint_bot"
new_score = 400
assert update_game(valid_gamemode, existing_username, new_score) == {"score":"complete", "alert":"no new high score"}









3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
fastapi
uvicorn
jinja2
requests
requests
pytest
16 changes: 16 additions & 0 deletions test_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from app.core.utils import sanitise_gamedata

import pytest

def test_sanitise():
control_game_mode = "city"
control_usern = "testuser"
control_totalscore = 0

results = None

# TEST THE GAME MODE VALIDITY
valid_gamemodes = ["city", "discoveries", "sleuth", "landmark"]
for game in valid_gamemodes:
assert sanitise_gamedata(game, control_usern, control_totalscore) == results[0]

0 comments on commit 38a2174

Please sign in to comment.