Skip to content

Commit

Permalink
Merge branch 'main' into 276-bug-error-handling-after-last-trick-of-hand
Browse files Browse the repository at this point in the history
  • Loading branch information
Segelzwerg authored Nov 8, 2022
2 parents 2d19a41 + 68c947f commit 77ddac1
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.9', '3.10' ]
python-version: [ '3.9', '3.10', '3.11' ]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -29,7 +29,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.9', '3.10' ]
python-version: [ '3.9', '3.10', '3.11' ]
mongodb-version: [ '4.4', '5.0', '6.0' ]
fail-fast: false
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ GITHUB_REDIRECT_URL=http://HOST:PORT/oauth2/github/ # Only required for Browser

If you want to use Splunk you require an environment variable with the authentication token:
`SPLUNK_TOKEN` and you have to start the server with optional arguments `--splunk_host` and
`--splunk-port`-
`--splunk-port`.

In order to run the application it must be started like this:

```shell
python -m whist_server --reload --admin_name=root --admin_pwd=password 0.0.0.0 8080
```

:warning: A mongodb instance is required to run before launching the `Whist-Server`.
:warning: A mongodb instance is required to run before launching the `Whist-Server`.
38 changes: 21 additions & 17 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ whist-server = "whist_server.cli:main"

[tool.poetry.dependencies]
python = "^3.9"
whist-core = "^0.4"
fastapi = { version = "^0.85", extras = ["all"] }
whist-core = ">=0.4,<0.6"
fastapi = { version = ">=0.85,<0.87", extras = ["all"] }
httpx = "^0.23"
pydantic = "^1.10"
pymongo = "^4.2"
Expand Down
12 changes: 6 additions & 6 deletions tests/whist_server/api/ranking/test_leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def setUp(self) -> None:
self.user: UserInDb = UserInDb(username='test', hashed_password='abc')
self.second_user = UserInDb(username='lower_ranking', rating=INITIAL_RATING - 10,
hashed_password='abc')
self.users_asc = [self.user.to_user(), self.second_user.to_user()]
self.users_desc = [self.second_user.to_user(), self.user.to_user()]
self.users_asc = [self.user.to_player(), self.second_user.to_player()]
self.users_desc = [self.second_user.to_player(), self.user.to_player()]
self.ranking_service_mock = MagicMock()
app.dependency_overrides[RankingService] = lambda: self.ranking_service_mock

Expand Down Expand Up @@ -61,19 +61,19 @@ def test_correct_asc_order(self):
self.assertEqual(self.users_asc, players)

def test_correct_asc_order_limited(self):
self.ranking_service_mock.select = MagicMock(return_value=[self.user.to_user()])
self.ranking_service_mock.select = MagicMock(return_value=[self.user.to_player()])
response = self.client.get(url='/leaderboard/?order=ascending&start=0&amount=1',
headers=self.headers)
players = [Player(**player) for player in response.json()]
self.assertEqual(response.status_code, 200, msg=response.content)
self.ranking_service_mock.select.assert_called_with('ascending', 1, 0)
self.assertEqual([self.user.to_user()], players)
self.assertEqual([self.user.to_player()], players)

def test_correct_asc_order_index(self):
self.ranking_service_mock.select = MagicMock(return_value=[self.second_user.to_user()])
self.ranking_service_mock.select = MagicMock(return_value=[self.second_user.to_player()])
response = self.client.get(url='/leaderboard/?order=ascending&start=1&amount=0',
headers=self.headers)
players = [Player(**player) for player in response.json()]
self.assertEqual(response.status_code, 200, msg=response.content)
self.ranking_service_mock.select.assert_called_with('ascending', 0, 1)
self.assertEqual([self.second_user.to_user()], players)
self.assertEqual([self.second_user.to_player()], players)
2 changes: 1 addition & 1 deletion tests/whist_server/base_token_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class TestCaseWithToken(unittest.TestCase):
def setUp(self) -> None:
self.player_mock = Player(username='marcel', rating=2000)
user_mock = MagicMock(name='user', to_user=self.player_mock)
user_mock = MagicMock(name='user', to_player=self.player_mock)
self.user_service_mock = MagicMock(get=MagicMock(return_value=user_mock))
self.room_service_mock = MagicMock(save=MagicMock(), add=MagicMock(return_value='1'))
self.password_service_mock = MagicMock(verify=MagicMock(),
Expand Down
2 changes: 1 addition & 1 deletion tests/whist_server/database/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_verify_fail(self):

def test_user(self):
user = Player(username=self.user.username, rating=INITIAL_RATING)
self.assertEqual(user, self.user.to_user())
self.assertEqual(user, self.user.to_player())

def test_github_user(self):
user = UserInDb(github_username='abc', username='abc')
Expand Down
4 changes: 2 additions & 2 deletions tests/whist_server/services/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def test_get_current_user():
user = _create_user()
token = create_access_token(data={'sub': user.username})
result_user = await get_current_user(token, user_db_service=UserDatabaseService())
assert user.to_user() == result_user
assert user.to_player() == result_user


@pytest.mark.integtest
Expand All @@ -52,7 +52,7 @@ async def test_get_current_user_with_delta():
expires_delta = timedelta(days=2)
token = create_access_token(data={'sub': user.username}, expires_delta=expires_delta)
result_user = await get_current_user(token, user_db_service=UserDatabaseService())
assert user.to_user() == result_user
assert user.to_player() == result_user

@pytest.mark.integtest
@pytest.mark.asyncio
Expand Down
8 changes: 4 additions & 4 deletions tests/whist_server/services/test_ranking_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def setUp(self) -> None:

def test_correct_des_order(self):
ranking = self.ranking_service.select('descending', 0, 0)
self.assertEqual([self.user.to_user(), self.second_user.to_user()], ranking)
self.assertEqual([self.user.to_player(), self.second_user.to_player()], ranking)

def test_correct_asc_order(self):
ranking = self.ranking_service.select('ascending', 0, 0)
self.assertEqual([self.second_user.to_user(), self.user.to_user()], ranking)
self.assertEqual([self.second_user.to_player(), self.user.to_player()], ranking)

def test_n_first(self):
ranking = self.ranking_service.select(order='descending', amount=1, start=0)
self.assertEqual([self.user.to_user()], ranking)
self.assertEqual([self.user.to_player()], ranking)

def test_start_second(self):
ranking = self.ranking_service.select(order='descending', amount=0, start=1)
self.assertEqual([self.second_user.to_user()], ranking)
self.assertEqual([self.second_user.to_player()], ranking)
2 changes: 1 addition & 1 deletion whist_server/database/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def verify_password(self, password) -> bool:
"""
return PasswordService.verify(password, self.hashed_password)

def to_user(self) -> Player:
def to_player(self) -> Player:
"""
Converts the DO to DAO.
:return: User with no password saved in object.
Expand Down
2 changes: 1 addition & 1 deletion whist_server/services/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def get_current_user(token: str = Depends(oauth2_scheme),
"""
token_data = await _get_token_data(token)
user = user_db_service.get(token_data.username)
return user.to_user()
return user.to_player()


async def check_credentials(username: str, password: str) -> bool:
Expand Down

0 comments on commit 77ddac1

Please sign in to comment.