From 0240a634d49df9916f833888a3e81c29a2bcfd0f Mon Sep 17 00:00:00 2001 From: iTitus Date: Tue, 19 Jul 2022 23:10:40 +0200 Subject: [PATCH 01/48] prepare python 3.11 --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 427bd75c..8a892478 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ 3.9, '3.10' ] + python-version: [ 3.9, '3.10', '3.11.0-beta.4' ] mongodb-version: [ 4.4, 5.0 ] test-type: [ 'integtest', '"not integtest"' ] fail-fast: false From 31b18118539f780d4621594a4e73aa3f1fbe98b2 Mon Sep 17 00:00:00 2001 From: Segelzwerg Date: Sun, 14 Nov 2021 12:03:28 +0100 Subject: [PATCH 02/48] ADD: 3.11 to supported versions --- setup.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..e69de29b From 3bff6ef5e5d17eb9ad6181a24bc252990374e6cc Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:38:51 +0200 Subject: [PATCH 03/48] UPDATE: use mocks instead of db calls Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/base_token_case.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/whist_server/base_token_case.py b/tests/whist_server/base_token_case.py index 6f689c2c..a4808bdb 100644 --- a/tests/whist_server/base_token_case.py +++ b/tests/whist_server/base_token_case.py @@ -5,7 +5,6 @@ from whist_core.user.player import Player from whist_server import app -from whist_server.database import db from whist_server.services.authentication import get_current_user from whist_server.services.channel_service import ChannelService from whist_server.services.password import PasswordService @@ -15,8 +14,6 @@ class TestCaseWithToken(unittest.TestCase): def setUp(self) -> None: - db.room.drop() - db.user.drop() self.player_mock = Player(username='marcel', rating=2000) user_mock = MagicMock(name='user', to_user=self.player_mock) user_service = MagicMock(get=MagicMock(return_value=user_mock)) @@ -31,14 +28,8 @@ def setUp(self) -> None: self.client = TestClient(app) self.app = app - self.headers = self.create_and_auth_user('marcel', 'abc') + self.headers = self.create_and_auth_user() - def create_and_auth_user(self, user: str, password): - login_creds = {'username': user, 'password': password} - _ = self.client.post(url='/user/create', json=login_creds) - token = self.client.post(url='/user/auth', data=login_creds).json()['access_token'] + def create_and_auth_user(self): + token = '1' * 24 return {'Authorization': f'Bearer {token}'} - - def tearDown(self) -> None: - db.room.drop() - db.user.drop() From 88289c27c13cc8c204c38a14124746009a315fda Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:39:19 +0200 Subject: [PATCH 04/48] UPDATE: package import Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- whist_server/api/user/auth.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/whist_server/api/user/auth.py b/whist_server/api/user/auth.py index abec97b2..1425c3d3 100644 --- a/whist_server/api/user/auth.py +++ b/whist_server/api/user/auth.py @@ -4,7 +4,8 @@ from fastapi.security import OAuth2PasswordRequestForm from whist_server.database.access_token import AccessToken -from whist_server.services.authentication import create_access_token, check_credentials +from whist_server.services import authentication +from whist_server.services.authentication import create_access_token from whist_server.services.error import UserNotFoundError router = APIRouter(prefix='/user/auth') @@ -22,7 +23,7 @@ async def auth(request: OAuth2PasswordRequestForm = Depends()): password = request.password try: - if not await check_credentials(username, password): + if not await authentication.check_credentials(username, password): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail='Incorrect password.', From 5d09a0c78c5cc42cda737ca6ece1f12a2c0ac357 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:39:44 +0200 Subject: [PATCH 05/48] REMOVE: no longer use parameters Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/api/game/test_action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/whist_server/api/game/test_action.py b/tests/whist_server/api/game/test_action.py index 48967e56..d8ff6e2f 100644 --- a/tests/whist_server/api/game/test_action.py +++ b/tests/whist_server/api/game/test_action.py @@ -12,7 +12,7 @@ class ActionGameTestCase(BaseCreateGameTestCase): def setUp(self) -> None: super().setUp() - self.second_player = self.create_and_auth_user('miles', 'abc') + self.second_player = self.create_and_auth_user() self.game_service = RoomDatabaseService() def test_start(self): From e25b32b1d4872e1b186857bbe203dff64bbad275 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:40:10 +0200 Subject: [PATCH 06/48] UPDATE: use base test and mocks Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/api/user/test_auth.py | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/whist_server/api/user/test_auth.py b/tests/whist_server/api/user/test_auth.py index e61995ca..b81ec9e1 100644 --- a/tests/whist_server/api/user/test_auth.py +++ b/tests/whist_server/api/user/test_auth.py @@ -1,28 +1,26 @@ -import unittest +from unittest.mock import patch -from starlette.testclient import TestClient +from tests.whist_server.base_token_case import TestCaseWithToken +from whist_server.services.error import UserNotFoundError -from whist_server import app -from whist_server.database import db - -class AuthTestCase(unittest.TestCase): +class AuthTestCase(TestCaseWithToken): def setUp(self) -> None: - self.client = TestClient(app) + super().setUp() self.login_creds = {'username': 'marcel', 'password': 'abc'} - _ = self.client.post(url='/user/create', json=self.login_creds) - - def tearDown(self) -> None: - db.user.drop() def test_auth_user(self): - response = self.client.post(url='/user/auth', data=self.login_creds) + with patch('whist_server.services.authentication.check_credentials', + return_value=True): + response = self.client.post(url='/user/auth', data=self.login_creds) self.assertEqual(response.status_code, 200, msg=response.content) self.assertTrue('access_token' in response.json()) def test_wrong_password(self): - response = self.client.post(url='/user/auth', - data={'username': 'marcel', 'password': 'abcd'}) + with patch('whist_server.services.authentication.check_credentials', + return_value=False): + response = self.client.post(url='/user/auth', + data={'username': 'marcel', 'password': 'abcd'}) self.assertEqual(response.status_code, 401, msg=response.content) self.assertFalse('access_token' in response.json()) @@ -37,7 +35,9 @@ def test_no_username(self): self.assertFalse('access_token' in response.json()) def test_wrong_username(self): - response = self.client.post(url='/user/auth', - data={'username': 'miles', 'password': 'abcd'}) + with patch('whist_server.services.authentication.check_credentials', + side_effect=UserNotFoundError()): + response = self.client.post(url='/user/auth', + data={'username': 'miles', 'password': 'abcd'}) self.assertEqual(response.status_code, 403, msg=response.content) self.assertFalse('access_token' in response.json()) From 8b118e9120b37ee7236c840effae26c1334f54a6 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:48:25 +0200 Subject: [PATCH 07/48] ADD: hash mock Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/base_token_case.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/whist_server/base_token_case.py b/tests/whist_server/base_token_case.py index a4808bdb..26ffb366 100644 --- a/tests/whist_server/base_token_case.py +++ b/tests/whist_server/base_token_case.py @@ -16,14 +16,15 @@ 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_service = MagicMock(get=MagicMock(return_value=user_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()) + self.password_service_mock = MagicMock(verify=MagicMock(), + hash=MagicMock(return_value='1' * 12)) self.channel_service_mock = MagicMock() app.dependency_overrides[ChannelService] = lambda: self.channel_service_mock app.dependency_overrides[RoomDatabaseService] = lambda: self.room_service_mock app.dependency_overrides[PasswordService] = lambda: self.password_service_mock - app.dependency_overrides[UserDatabaseService] = lambda: user_service + app.dependency_overrides[UserDatabaseService] = lambda: self.user_service_mock app.dependency_overrides[get_current_user] = lambda: self.player_mock self.client = TestClient(app) From 6e8e34592875c9bba743e607c448790327e39e01 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:48:46 +0200 Subject: [PATCH 08/48] UPDATE: use base class and mocks Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/api/user/test_create.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/whist_server/api/user/test_create.py b/tests/whist_server/api/user/test_create.py index 87f31b9c..225750b4 100644 --- a/tests/whist_server/api/user/test_create.py +++ b/tests/whist_server/api/user/test_create.py @@ -1,17 +1,7 @@ -import unittest +from tests.whist_server.base_token_case import TestCaseWithToken -from starlette.testclient import TestClient -from whist_server import app -from whist_server.database import db - - -class UserTestCase(unittest.TestCase): - def setUp(self): - self.client = TestClient(app) - - def tearDown(self) -> None: - db.user.drop() +class UserTestCase(TestCaseWithToken): def test_post_user(self): """ @@ -21,7 +11,7 @@ def test_post_user(self): response = self.client.post(url='/user/create', json=data) self.assertEqual(response.status_code, 200, msg=response.content) self.assertTrue('user_id' in response.json()) - self.assertEqual(1, db.user.estimated_document_count()) + self.user_service_mock.add.assert_called_once() def test_post_user_no_username(self): """ @@ -30,7 +20,7 @@ def test_post_user_no_username(self): data = {'password': 'abc'} response = self.client.post(url='/user/create', json=data) self.assertEqual(422, response.status_code) - self.assertEqual(0, db.user.estimated_document_count()) + self.user_service_mock.add.assert_not_called() def test_post_user_no_pwd(self): """ @@ -39,4 +29,4 @@ def test_post_user_no_pwd(self): data = {'username': 'test'} response = self.client.post(url='/user/create', json=data) self.assertEqual(422, response.status_code) - self.assertEqual(0, db.user.estimated_document_count()) + self.user_service_mock.add.assert_not_called() From 29353599513c2460d418ac3f808bc9f83a3fe176 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:54:08 +0200 Subject: [PATCH 09/48] UPDATE: mark integration tests Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/services/test_authentication.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/whist_server/services/test_authentication.py b/tests/whist_server/services/test_authentication.py index c046853b..4251aa1b 100644 --- a/tests/whist_server/services/test_authentication.py +++ b/tests/whist_server/services/test_authentication.py @@ -21,6 +21,7 @@ def _create_user(): return user +@pytest.mark.integtest @pytest.mark.asyncio async def test_get_current_user(): user = _create_user() @@ -29,6 +30,7 @@ async def test_get_current_user(): assert user.to_user() == result_user +@pytest.mark.integtest @pytest.mark.asyncio async def test_get_current_user_no_user(): token = create_access_token(data={'sub': 'a'}) @@ -43,6 +45,7 @@ async def test_get_current_user_no_username(): _ = await get_current_user(token) +@pytest.mark.integtest @pytest.mark.asyncio async def test_get_current_user_with_delta(): user = _create_user() @@ -51,7 +54,7 @@ async def test_get_current_user_with_delta(): result_user = await get_current_user(token, user_db_service=UserDatabaseService()) assert user.to_user() == result_user - +@pytest.mark.integtest @pytest.mark.asyncio async def test_check_credentials(): _ = _create_user() @@ -59,6 +62,7 @@ async def test_check_credentials(): assert is_valid +@pytest.mark.integtest @pytest.mark.asyncio async def test_check_wrong_credentials(): _ = _create_user() @@ -66,6 +70,7 @@ async def test_check_wrong_credentials(): assert not is_valid +@pytest.mark.integtest @pytest.mark.asyncio async def test_check_no_user(): _ = _create_user() From 1e1e820b8bb3beb4724f474e12ed162d899bbfda Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 19 Jul 2022 23:57:26 +0200 Subject: [PATCH 10/48] UPDATE: dependency injection Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- whist_server/api/user/create.py | 9 +++++---- whist_server/services/authentication.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/whist_server/api/user/create.py b/whist_server/api/user/create.py index 5f05f054..9f040fac 100644 --- a/whist_server/api/user/create.py +++ b/whist_server/api/user/create.py @@ -1,6 +1,6 @@ """'/user/create api""" -from fastapi import APIRouter +from fastapi import APIRouter, Depends from pydantic import BaseModel from whist_server.database.user import UserInDb @@ -19,15 +19,16 @@ class CreateUserArgs(BaseModel): @router.post('/create') -def create_user(request: CreateUserArgs): +def create_user(request: CreateUserArgs, pwd_service=Depends(PasswordService), + user_db_service=Depends(UserDatabaseService)): """ Creates a new user. :param request: Must contain a 'username' and a 'password' field. If one is missing it raises HTTP 400 error. + :param pwd_service: service to handle password requests. + :param user_db_service: service to handle request to the database storing users. :return: the ID of the user or an error message. """ - pwd_service = PasswordService() user = UserInDb(username=request.username, hashed_password=pwd_service.hash(request.password)) - user_db_service = UserDatabaseService() user_id = user_db_service.add(user) return {'user_id': user_id} diff --git a/whist_server/services/authentication.py b/whist_server/services/authentication.py index 6f8a9b0e..d4106cab 100644 --- a/whist_server/services/authentication.py +++ b/whist_server/services/authentication.py @@ -46,18 +46,19 @@ async def get_current_user(token: str = Depends(oauth2_scheme), return user.to_user() -async def check_credentials(username: str, password: str) -> bool: +async def check_credentials(username: str, password: str, pwd_service=Depends(PasswordService), + user_db_service=Depends(UserDatabaseService)) -> bool: """ Verifies the password for a given username. :param username: the name of the user as string :param password: the plain password to be checked as string. + :param pwd_service: service to handle password requests. + :param user_db_service: service to handle request to the database storing users. :return: True if credentials are valid else False. If user not found raises UserNotFoundError. """ - user_db_service = UserDatabaseService() user = user_db_service.get(username) - password_db_service = PasswordService() - return password_db_service.verify(password, user.hashed_password) + return pwd_service.verify(password, user.hashed_password) async def _get_token_data(token): From bb4921bef01656382cc0c191434edd7be2a3b78c Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 00:22:09 +0200 Subject: [PATCH 11/48] WIP: migrate room db tests to mocking Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- .../services/test_game_db_service.py | 159 ++++++++++-------- 1 file changed, 85 insertions(+), 74 deletions(-) diff --git a/tests/whist_server/services/test_game_db_service.py b/tests/whist_server/services/test_game_db_service.py index c5269636..cb88d5a7 100644 --- a/tests/whist_server/services/test_game_db_service.py +++ b/tests/whist_server/services/test_game_db_service.py @@ -1,101 +1,112 @@ -from unittest.mock import patch +from unittest.mock import patch, MagicMock from bson import ObjectId from whist_core.session.matcher import RandomMatcher, RoundRobinMatcher from whist_core.user.player import Player from tests.whist_server.base_player_test_case import BasePlayerTestCase -from whist_server.database import db from whist_server.services.error import RoomNotFoundError, RoomNotUpdatedError from whist_server.services.room_db_service import RoomDatabaseService class GameDdServiceTestCase(BasePlayerTestCase): def setUp(self) -> None: - db.room.drop() super().setUp() - self.service = RoomDatabaseService() - self.room = self.service.create_with_pwd(room_name='test', hashed_password='abc', - creator=self.player) + self.room_db_mock = MagicMock() + self.room = MagicMock(creator=self.player) + self.id_mock = MagicMock(inserted_id='1' * 24) + with patch('whist_server.database.db.room', self.room_db_mock): + self.service = RoomDatabaseService() def test_add(self): + self.room_db_mock.find_one = MagicMock(return_value=None) + self.room_db_mock.insert_one = MagicMock(return_value=self.id_mock) game_id = self.service.add(self.room) self.room.id = ObjectId(game_id) + self.room_db_mock.find_one = MagicMock(return_value=self.room) self.assertEqual(self.room, self.service.get(game_id)) - self.assertEqual(1, db.room.count_documents({})) - def test_add_duplicate(self): - game_id_first = self.service.add(self.room) - game_id_second = self.service.add(self.room) - self.assertEqual(game_id_first, game_id_second) - def test_not_existing(self): - game_id = '1' * 24 - error_msg = f'Room with id "{game_id}" not found.' - with self.assertRaisesRegex(RoomNotFoundError, error_msg): - self.service.get(game_id) +def test_add_duplicate(self): + game_id_first = self.service.add(self.room) + game_id_second = self.service.add(self.room) + self.assertEqual(game_id_first, game_id_second) - def test_get_by_name(self): - game_id = self.service.add(self.room) - self.room.id = ObjectId(game_id) - self.assertEqual(self.room, self.service.get_by_name('test')) - def test_save(self): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 3 - self.service.save(self.room) - game = self.service.get(game_id) - self.assertEqual(3, game.table.min_player) - - def test_save_wrong_id(self): - _ = self.service.add(self.room) - self.room.id = '1' * 24 - self.room.table.min_player = 3 - with self.assertRaises(RoomNotFoundError): - self.service.save(self.room) - - @patch('pymongo.results.UpdateResult.modified_count', return_value=1) - def test_save_update_error(self, result_mock): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 3 - with self.assertRaises(RoomNotUpdatedError): - self.service.save(self.room) +def test_not_existing(self): + game_id = '1' * 24 + error_msg = f'Room with id "{game_id}" not found.' + with self.assertRaisesRegex(RoomNotFoundError, error_msg): + self.service.get(game_id) - def test_save_started_table(self): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 2 - self.room.ready_player(self.player) - second_player = Player(username='miles', rating=3000) - self.room.join(second_player) - self.room.ready_player(second_player) - self.room.start(self.player, RandomMatcher) - self.service.save(self.room) - db_game = self.service.get(game_id) - self.assertTrue(self.room.table.started) - self.assertTrue(db_game.table.started) - def test_save_play_card(self): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 2 - self.room.ready_player(self.player) - second_player = Player(username='miles', rating=3000) - self.room.join(second_player) - self.room.ready_player(second_player) - self.room.start(self.player, RoundRobinMatcher) +def test_get_by_name(self): + game_id = self.service.add(self.room) + self.room.id = ObjectId(game_id) + self.assertEqual(self.room, self.service.get_by_name('test')) + + +def test_save(self): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 3 + self.service.save(self.room) + game = self.service.get(game_id) + self.assertEqual(3, game.table.min_player) + + +def test_save_wrong_id(self): + _ = self.service.add(self.room) + self.room.id = '1' * 24 + self.room.table.min_player = 3 + with self.assertRaises(RoomNotFoundError): self.service.save(self.room) - game = self.room.table.current_rubber.current_game() - player = game.get_player(self.player) - trick = game.next_hand().current_trick - trick.play_card(player, player.hand.cards[0]) + + +@patch('pymongo.results.UpdateResult.modified_count', return_value=1) +def test_save_update_error(self, result_mock): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 3 + with self.assertRaises(RoomNotUpdatedError): self.service.save(self.room) - def test_all(self): - game_id = self.service.add(self.room) - self.room.id = game_id - all_games = self.service.all() - self.assertEqual(1, len(all_games)) - self.assertEqual(game_id, str(all_games[0].id)) + +def test_save_started_table(self): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 2 + self.room.ready_player(self.player) + second_player = Player(username='miles', rating=3000) + self.room.join(second_player) + self.room.ready_player(second_player) + self.room.start(self.player, RandomMatcher) + self.service.save(self.room) + db_game = self.service.get(game_id) + self.assertTrue(self.room.table.started) + self.assertTrue(db_game.table.started) + + +def test_save_play_card(self): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 2 + self.room.ready_player(self.player) + second_player = Player(username='miles', rating=3000) + self.room.join(second_player) + self.room.ready_player(second_player) + self.room.start(self.player, RoundRobinMatcher) + self.service.save(self.room) + game = self.room.table.current_rubber.current_game() + player = game.get_player(self.player) + trick = game.next_hand().current_trick + trick.play_card(player, player.hand.cards[0]) + self.service.save(self.room) + + +def test_all(self): + game_id = self.service.add(self.room) + self.room.id = game_id + all_games = self.service.all() + self.assertEqual(1, len(all_games)) + self.assertEqual(game_id, str(all_games[0].id)) From f3bc8707e8185593f87f8c3c1128fcdd05c11fbb Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 00:22:31 +0200 Subject: [PATCH 12/48] REMOVE: no longer needed arguments Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/api/game/test_join.py | 2 +- tests/whist_server/web_socket/test_entry.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/whist_server/api/game/test_join.py b/tests/whist_server/api/game/test_join.py index a1887df4..8f7e5288 100644 --- a/tests/whist_server/api/game/test_join.py +++ b/tests/whist_server/api/game/test_join.py @@ -13,7 +13,7 @@ class JoinGameTestCase(BaseCreateGameTestCase): def test_join(self): - headers = self.create_and_auth_user('miles', 'abc') + headers = self.create_and_auth_user() self.password_service_mock.verify = MagicMock(return_value=True) response = self.client.post(url=f'/room/join/{self.room_mock.id}', diff --git a/tests/whist_server/web_socket/test_entry.py b/tests/whist_server/web_socket/test_entry.py index 501b2b50..2ab4334e 100644 --- a/tests/whist_server/web_socket/test_entry.py +++ b/tests/whist_server/web_socket/test_entry.py @@ -11,7 +11,7 @@ class EntryTestCase(TestCaseWithToken): def setUp(self) -> None: super().setUp() - self.token = self.create_and_auth_user('simon', 'abc')['Authorization'].rsplit('Bearer ')[1] + self.token = self.create_and_auth_user()['Authorization'].rsplit('Bearer ')[1] data = {'room_name': 'test', 'password': 'abc'} response = self.client.post(url='/room/create', json=data, headers=self.headers) self.room_id = response.json()['room_id'] From f41cb0375dd315c7a78a48180475fec3637d1c88 Mon Sep 17 00:00:00 2001 From: iTitus Date: Tue, 19 Jul 2022 23:22:07 +0200 Subject: [PATCH 13/48] try to fix github publish --- .github/workflows/docker-publish.yml | 1 + .github/workflows/github-publish.yml | 5 +++++ .github/workflows/python-publish.yml | 1 + 3 files changed, 7 insertions(+) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index e0504988..0ea25a57 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -3,6 +3,7 @@ name: Docker on: release: types: [ published ] + workflow_dispatch: env: IMAGE_NAME: whist-server diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index 3e829cd4..9ed182a9 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -3,6 +3,7 @@ name: Github Publish on: release: types: [ published ] + workflow_dispatch: env: IMAGE_NAME: whist-server @@ -19,6 +20,10 @@ jobs: runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index ff7b15ef..2e0897c2 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -3,6 +3,7 @@ name: Upload Python Package on: release: types: [ created ] + workflow_dispatch: jobs: deploy: From 57410e5c129e4e46b449c5faab23d336353017f0 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 00:28:54 +0200 Subject: [PATCH 14/48] FIX: typo Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- whist_server/services/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whist_server/services/authentication.py b/whist_server/services/authentication.py index d4106cab..72831146 100644 --- a/whist_server/services/authentication.py +++ b/whist_server/services/authentication.py @@ -19,7 +19,7 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str: """ Creates an access token for an user. - :param data: Expects a dictionary with with key 'sub' and an username as value. + :param data: Expects a dictionary with key 'sub' and a username as value. :param expires_delta: The amount of time until this token shall expire. :return: token as a str """ From 3ce0874a7c74ac70337a8e35200efaa3446fc8e8 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 00:32:17 +0200 Subject: [PATCH 15/48] REVERT: dependency injection Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- whist_server/services/authentication.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/whist_server/services/authentication.py b/whist_server/services/authentication.py index 72831146..8070526f 100644 --- a/whist_server/services/authentication.py +++ b/whist_server/services/authentication.py @@ -46,19 +46,18 @@ async def get_current_user(token: str = Depends(oauth2_scheme), return user.to_user() -async def check_credentials(username: str, password: str, pwd_service=Depends(PasswordService), - user_db_service=Depends(UserDatabaseService)) -> bool: +async def check_credentials(username: str, password: str) -> bool: """ Verifies the password for a given username. :param username: the name of the user as string :param password: the plain password to be checked as string. - :param pwd_service: service to handle password requests. - :param user_db_service: service to handle request to the database storing users. :return: True if credentials are valid else False. If user not found raises UserNotFoundError. """ + user_db_service = UserDatabaseService() user = user_db_service.get(username) - return pwd_service.verify(password, user.hashed_password) + password_db_service = PasswordService() + return password_db_service.verify(password, user.hashed_password) async def _get_token_data(token): From dc85d7690649de63e2927bb19e7d40eb42fe8b39 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 00:50:55 +0200 Subject: [PATCH 16/48] UPDATE: use integration test for db services Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- .../services/test_game_db_service.py | 151 ++++++++---------- .../services/test_ranking_service.py | 4 +- .../services/test_user_db_service.py | 3 + 3 files changed, 76 insertions(+), 82 deletions(-) diff --git a/tests/whist_server/services/test_game_db_service.py b/tests/whist_server/services/test_game_db_service.py index cb88d5a7..8fac7bcb 100644 --- a/tests/whist_server/services/test_game_db_service.py +++ b/tests/whist_server/services/test_game_db_service.py @@ -1,5 +1,6 @@ from unittest.mock import patch, MagicMock +import pytest from bson import ObjectId from whist_core.session.matcher import RandomMatcher, RoundRobinMatcher from whist_core.user.player import Player @@ -9,14 +10,11 @@ from whist_server.services.room_db_service import RoomDatabaseService +@pytest.mark.integtest class GameDdServiceTestCase(BasePlayerTestCase): def setUp(self) -> None: super().setUp() - self.room_db_mock = MagicMock() - self.room = MagicMock(creator=self.player) - self.id_mock = MagicMock(inserted_id='1' * 24) - with patch('whist_server.database.db.room', self.room_db_mock): - self.service = RoomDatabaseService() + self.service = RoomDatabaseService() def test_add(self): self.room_db_mock.find_one = MagicMock(return_value=None) @@ -26,87 +24,78 @@ def test_add(self): self.room_db_mock.find_one = MagicMock(return_value=self.room) self.assertEqual(self.room, self.service.get(game_id)) + def test_add_duplicate(self): + game_id_first = self.service.add(self.room) + game_id_second = self.service.add(self.room) + self.assertEqual(game_id_first, game_id_second) -def test_add_duplicate(self): - game_id_first = self.service.add(self.room) - game_id_second = self.service.add(self.room) - self.assertEqual(game_id_first, game_id_second) - - -def test_not_existing(self): - game_id = '1' * 24 - error_msg = f'Room with id "{game_id}" not found.' - with self.assertRaisesRegex(RoomNotFoundError, error_msg): - self.service.get(game_id) - - -def test_get_by_name(self): - game_id = self.service.add(self.room) - self.room.id = ObjectId(game_id) - self.assertEqual(self.room, self.service.get_by_name('test')) - - -def test_save(self): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 3 - self.service.save(self.room) - game = self.service.get(game_id) - self.assertEqual(3, game.table.min_player) + def test_not_existing(self): + game_id = '1' * 24 + error_msg = f'Room with id "{game_id}" not found.' + with self.assertRaisesRegex(RoomNotFoundError, error_msg): + self.service.get(game_id) + def test_get_by_name(self): + game_id = self.service.add(self.room) + self.room.id = ObjectId(game_id) + self.assertEqual(self.room, self.service.get_by_name('test')) -def test_save_wrong_id(self): - _ = self.service.add(self.room) - self.room.id = '1' * 24 - self.room.table.min_player = 3 - with self.assertRaises(RoomNotFoundError): + def test_save(self): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 3 self.service.save(self.room) + game = self.service.get(game_id) + self.assertEqual(3, game.table.min_player) + + def test_save_wrong_id(self): + _ = self.service.add(self.room) + self.room.id = '1' * 24 + self.room.table.min_player = 3 + with self.assertRaises(RoomNotFoundError): + self.service.save(self.room) + + @patch('pymongo.results.UpdateResult.modified_count', return_value=1) + def test_save_update_error(self, result_mock): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 3 + with self.assertRaises(RoomNotUpdatedError): + self.service.save(self.room) - -@patch('pymongo.results.UpdateResult.modified_count', return_value=1) -def test_save_update_error(self, result_mock): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 3 - with self.assertRaises(RoomNotUpdatedError): + def test_save_started_table(self): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 2 + self.room.ready_player(self.player) + second_player = Player(username='miles', rating=3000) + self.room.join(second_player) + self.room.ready_player(second_player) + self.room.start(self.player, RandomMatcher) self.service.save(self.room) + db_game = self.service.get(game_id) + self.assertTrue(self.room.table.started) + self.assertTrue(db_game.table.started) + def test_save_play_card(self): + game_id = self.service.add(self.room) + self.room.id = game_id + self.room.table.min_player = 2 + self.room.ready_player(self.player) + second_player = Player(username='miles', rating=3000) + self.room.join(second_player) + self.room.ready_player(second_player) + self.room.start(self.player, RoundRobinMatcher) + self.service.save(self.room) + game = self.room.table.current_rubber.current_game() + player = game.get_player(self.player) + trick = game.next_hand().current_trick + trick.play_card(player, player.hand.cards[0]) + self.service.save(self.room) -def test_save_started_table(self): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 2 - self.room.ready_player(self.player) - second_player = Player(username='miles', rating=3000) - self.room.join(second_player) - self.room.ready_player(second_player) - self.room.start(self.player, RandomMatcher) - self.service.save(self.room) - db_game = self.service.get(game_id) - self.assertTrue(self.room.table.started) - self.assertTrue(db_game.table.started) - - -def test_save_play_card(self): - game_id = self.service.add(self.room) - self.room.id = game_id - self.room.table.min_player = 2 - self.room.ready_player(self.player) - second_player = Player(username='miles', rating=3000) - self.room.join(second_player) - self.room.ready_player(second_player) - self.room.start(self.player, RoundRobinMatcher) - self.service.save(self.room) - game = self.room.table.current_rubber.current_game() - player = game.get_player(self.player) - trick = game.next_hand().current_trick - trick.play_card(player, player.hand.cards[0]) - self.service.save(self.room) - - -def test_all(self): - game_id = self.service.add(self.room) - self.room.id = game_id - all_games = self.service.all() - self.assertEqual(1, len(all_games)) - self.assertEqual(game_id, str(all_games[0].id)) + def test_all(self): + game_id = self.service.add(self.room) + self.room.id = game_id + all_games = self.service.all() + self.assertEqual(1, len(all_games)) + self.assertEqual(game_id, str(all_games[0].id)) diff --git a/tests/whist_server/services/test_ranking_service.py b/tests/whist_server/services/test_ranking_service.py index ef3e8d6f..e71f62be 100644 --- a/tests/whist_server/services/test_ranking_service.py +++ b/tests/whist_server/services/test_ranking_service.py @@ -1,9 +1,11 @@ -from tests.whist_server.base_user_test_case import UserBaseTestCase +import pytest +from tests.whist_server.base_user_test_case import UserBaseTestCase from whist_server.services.ranking_service import RankingService from whist_server.services.user_db_service import UserDatabaseService +@pytest.mark.integtest class LeaderboardTestCase(UserBaseTestCase): def setUp(self) -> None: super().setUp() diff --git a/tests/whist_server/services/test_user_db_service.py b/tests/whist_server/services/test_user_db_service.py index 2af63695..05266a7d 100644 --- a/tests/whist_server/services/test_user_db_service.py +++ b/tests/whist_server/services/test_user_db_service.py @@ -1,8 +1,11 @@ +import pytest + from tests.whist_server.base_user_test_case import UserBaseTestCase from whist_server.database import db from whist_server.services.error import UserNotFoundError, UserExistsError +@pytest.mark.integtest class UserDbTestCase(UserBaseTestCase): def test_add_user(self): From 07afaf6d0528bc409f4e4f79dc726ade58452be6 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 00:53:31 +0200 Subject: [PATCH 17/48] REMOVE: mocks Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- tests/whist_server/services/test_game_db_service.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/whist_server/services/test_game_db_service.py b/tests/whist_server/services/test_game_db_service.py index 8fac7bcb..6219a2b5 100644 --- a/tests/whist_server/services/test_game_db_service.py +++ b/tests/whist_server/services/test_game_db_service.py @@ -1,4 +1,4 @@ -from unittest.mock import patch, MagicMock +from unittest.mock import patch import pytest from bson import ObjectId @@ -6,6 +6,7 @@ from whist_core.user.player import Player from tests.whist_server.base_player_test_case import BasePlayerTestCase +from whist_server.database import db from whist_server.services.error import RoomNotFoundError, RoomNotUpdatedError from whist_server.services.room_db_service import RoomDatabaseService @@ -13,16 +14,17 @@ @pytest.mark.integtest class GameDdServiceTestCase(BasePlayerTestCase): def setUp(self) -> None: + db.room.drop() super().setUp() self.service = RoomDatabaseService() + self.room = self.service.create_with_pwd(room_name='test', hashed_password='abc', + creator=self.player) def test_add(self): - self.room_db_mock.find_one = MagicMock(return_value=None) - self.room_db_mock.insert_one = MagicMock(return_value=self.id_mock) game_id = self.service.add(self.room) self.room.id = ObjectId(game_id) - self.room_db_mock.find_one = MagicMock(return_value=self.room) self.assertEqual(self.room, self.service.get(game_id)) + self.assertEqual(1, db.room.count_documents({})) def test_add_duplicate(self): game_id_first = self.service.add(self.room) From 21f60f12659c84639bc52f9db1ace19e1bca8d9d Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 00:57:25 +0200 Subject: [PATCH 18/48] UPDATE: use db only in db tests Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- .github/workflows/python-app.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 8a892478..8dab91c4 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -40,6 +40,7 @@ jobs: uses: supercharge/mongodb-github-action@1.7.0 with: mongodb-version: ${{ matrix.mongodb-version }} + if: ${{ matrix.test-type }} == 'integtest' - name: Install dependencies run: poetry install --no-interaction From 7422a726510916d7d5d6e2b5ad9e08702292943f Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 00:24:10 +0200 Subject: [PATCH 19/48] change order of steps in ci --- .github/workflows/docker-publish.yml | 11 ++++------- .github/workflows/github-publish.yml | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 0ea25a57..be6ececc 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -9,9 +9,6 @@ env: IMAGE_NAME: whist-server jobs: - - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ push: strategy: matrix: @@ -23,6 +20,10 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Get Version + id: get_version + uses: battila7/get-version-action@v2 + - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -35,10 +36,6 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Get Version - id: get_version - uses: battila7/get-version-action@v2 - - name: Build and push id: docker_build uses: docker/build-push-action@v3 diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index 9ed182a9..d5c13e37 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -9,9 +9,6 @@ env: IMAGE_NAME: whist-server jobs: - - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ push: strategy: matrix: @@ -27,6 +24,10 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Get Version + id: get_version + uses: battila7/get-version-action@v2 + - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -40,10 +41,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Get Version - id: get_version - uses: battila7/get-version-action@v2 - - name: Build and push id: docker_build uses: docker/build-push-action@v3 From 5fdede3a04e79af5c360135f8ad99b404dcd1d5b Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 00:36:51 +0200 Subject: [PATCH 20/48] Use context instead of file --- .github/workflows/docker-image.yml | 5 ++++- .github/workflows/docker-publish.yml | 2 +- .github/workflows/github-publish.yml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index ce9248c5..deb84da2 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -28,8 +28,11 @@ jobs: id: docker_build uses: docker/build-push-action@v3 with: + context: . push: false - file: ./Dockerfile platforms: linux/${{ matrix.arch }} tags: | whist-team/whist-server:${{ matrix.arch }}-test + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index be6ececc..d658ad5d 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -40,8 +40,8 @@ jobs: id: docker_build uses: docker/build-push-action@v3 with: + context: . push: true - file: ./Dockerfile platforms: linux/${{ matrix.arch }} tags: | teamwhist/whist-server:${{ matrix.arch }}-latest diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index d5c13e37..08dad4af 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -45,8 +45,8 @@ jobs: id: docker_build uses: docker/build-push-action@v3 with: + context: . push: true - file: ./Dockerfile platforms: linux/${{ matrix.arch }} tags: | whist-team/whist-server:${{ matrix.arch }}-latest From 7ccee4eeab11d3955206bc959e09859f85a717ae Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 01:01:25 +0200 Subject: [PATCH 21/48] REMOVE: workflow separation try Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- .github/workflows/python-app.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 8dab91c4..8a892478 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -40,7 +40,6 @@ jobs: uses: supercharge/mongodb-github-action@1.7.0 with: mongodb-version: ${{ matrix.mongodb-version }} - if: ${{ matrix.test-type }} == 'integtest' - name: Install dependencies run: poetry install --no-interaction From 72f360a3be4544fcddfae6b56f2b78344c3fbbb8 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 01:21:46 +0200 Subject: [PATCH 22/48] Use metadata action to generate tags --- .github/workflows/docker-image.yml | 38 ------------------ .github/workflows/docker-publish.yml | 45 +++++++++++---------- .github/workflows/github-publish.yml | 58 +++++++++++++++------------- 3 files changed, 56 insertions(+), 85 deletions(-) delete mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index deb84da2..00000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ main ] - pull_request: - -jobs: - - build: - strategy: - matrix: - arch: [ amd64, arm64 ] - fail-fast: false - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build - id: docker_build - uses: docker/build-push-action@v3 - with: - context: . - push: false - platforms: linux/${{ matrix.arch }} - tags: | - whist-team/whist-server:${{ matrix.arch }}-test - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index d658ad5d..e20f9a9c 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,29 +1,22 @@ name: Docker on: - release: - types: [ published ] + push: + branches: [ main, develop ] + tags: + - 'v*' workflow_dispatch: env: - IMAGE_NAME: whist-server + IMAGE_NAME: teamwhist/whist-server jobs: push: - strategy: - matrix: - arch: [ amd64, arm64 ] - fail-fast: false - runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Get Version - id: get_version - uses: battila7/get-version-action@v2 - - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -31,21 +24,31 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to DockerHub + if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.IMAGE_NAME }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - name: Build and push - id: docker_build uses: docker/build-push-action@v3 with: context: . - push: true - platforms: linux/${{ matrix.arch }} - tags: | - teamwhist/whist-server:${{ matrix.arch }}-latest - teamwhist/whist-server:${{ matrix.arch }}-${{ steps.get_version.outputs.version-without-v }} - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index 08dad4af..c12f3407 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -1,33 +1,29 @@ name: Github Publish on: - release: - types: [ published ] + push: + branches: [ main, develop ] + tags: + - 'v*' + pull_request: + branches: [ main ] workflow_dispatch: +permissions: + contents: read + packages: write + env: - IMAGE_NAME: whist-server + REGISTRY: ghcr.io + IMAGE_NAME: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ github.repository }} jobs: push: - strategy: - matrix: - arch: [ amd64, arm64 ] - fail-fast: false - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - steps: - uses: actions/checkout@v3 - - name: Get Version - id: get_version - uses: battila7/get-version-action@v2 - - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -35,22 +31,32 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' uses: docker/login-action@v2 with: - registry: ghcr.io + registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.IMAGE_NAME }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - name: Build and push - id: docker_build uses: docker/build-push-action@v3 with: context: . - push: true - platforms: linux/${{ matrix.arch }} - tags: | - whist-team/whist-server:${{ matrix.arch }}-latest - whist-team/whist-server:${{ matrix.arch }}-${{ steps.get_version.outputs.version-without-v }} - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 1d1954f338da8fec3412b40e50d781ddcab8994e Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 01:26:22 +0200 Subject: [PATCH 23/48] Fix error in workflow file --- .github/workflows/github-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index c12f3407..7f72d906 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -15,7 +15,7 @@ permissions: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ github.repository }} + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.repository }} jobs: push: From 368091edd67e4998ddfd47968231f1e06f437b00 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 01:36:00 +0200 Subject: [PATCH 24/48] Unify docker publish ci --- .github/workflows/docker-publish.yml | 20 +++++++-- .github/workflows/github-publish.yml | 62 ---------------------------- 2 files changed, 17 insertions(+), 65 deletions(-) delete mode 100644 .github/workflows/github-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index e20f9a9c..a20804bf 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -5,13 +5,17 @@ on: branches: [ main, develop ] tags: - 'v*' + pull_request: + branches: [ main ] workflow_dispatch: env: - IMAGE_NAME: teamwhist/whist-server + REGISTRY: ghcr.io + IMAGE_NAME_DOCKERHUB: teamwhist/whist-server + IMAGE_NAME_GHCR: ghcr.io/${{ github.repository_owner }}/${{ github.repository }} jobs: - push: + docker_deploy: runs-on: ubuntu-latest steps: @@ -30,11 +34,21 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v4 with: - images: ${{ env.IMAGE_NAME }} + images: | + ${{ env.IMAGE_NAME_DOCKERHUB }} + ${{ env.IMAGE_NAME_GHCR }} tags: | type=schedule type=ref,event=branch diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml deleted file mode 100644 index 7f72d906..00000000 --- a/.github/workflows/github-publish.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Github Publish - -on: - push: - branches: [ main, develop ] - tags: - - 'v*' - pull_request: - branches: [ main ] - workflow_dispatch: - -permissions: - contents: read - packages: write - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.repository }} - -jobs: - push: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to GitHub Container Registry - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.IMAGE_NAME }} - tags: | - type=schedule - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} From 743b2a862b6b14b7dd4ce509141982134d233da7 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 01:42:54 +0200 Subject: [PATCH 25/48] Bump version --- pyproject.toml | 2 +- whist_server/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 10225724..28590c3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "whist-server" # remember to also update the version in __init__.py! -version = "0.4.0" +version = "0.4.1" description = "Whist server implementation" authors = ["Whist-Team"] license = "MIT" diff --git a/whist_server/__init__.py b/whist_server/__init__.py index ee5fed86..b43d362b 100644 --- a/whist_server/__init__.py +++ b/whist_server/__init__.py @@ -16,7 +16,7 @@ from whist_server.web_socket.entry import router as ws_router # remember to also update the version in pyproject.toml! -__version__ = '0.4.0' +__version__ = '0.4.1' app = FastAPI() app.include_router(api.router) From b376f4b280d84c44e2529d207b0a8e381d451af6 Mon Sep 17 00:00:00 2001 From: Marcel <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 10:57:39 +0200 Subject: [PATCH 26/48] UPDATE: use db only in int tests --- .github/workflows/python-app.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 8a892478..2e2f53ef 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -26,6 +26,7 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + if: ${{ matrix.test-type }} == 'integtest' - name: Install poetry uses: snok/install-poetry@v1 From 71cb96fd3d48258834479fd4b5ca9ddc96c06a3c Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 12:23:31 +0200 Subject: [PATCH 27/48] UPDATE: use setup workflow Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- .github/workflows/setup.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/setup.yaml diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml new file mode 100644 index 00000000..996a0e5b --- /dev/null +++ b/.github/workflows/setup.yaml @@ -0,0 +1,34 @@ +name: Python Setup + +on: + workflow_call: + inputs: + python-version: + required: true + type: string + os: + required: true + type: string + +jobs: + setup: + runs-on: ${{ inputs.os }} + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ inputs.python-version }} + id: setup-python + uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.python-version }} + + - name: Install poetry + uses: snok/install-poetry@v1 + + - name: Load cached venv + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + - name: Install dependencies + run: poetry install --no-interaction \ No newline at end of file From ba72987c22d2a6f033c8ef82768480f4ebcb9da6 Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 12:33:38 +0200 Subject: [PATCH 28/48] FIX: move checkout Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- .github/workflows/setup.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 996a0e5b..bb662e52 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -14,7 +14,6 @@ jobs: setup: runs-on: ${{ inputs.os }} steps: - - uses: actions/checkout@v3 - name: Set up Python ${{ inputs.python-version }} id: setup-python From 5cd463adf8f94ce74b9ee0a37266903c4de72f40 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 12:28:11 +0200 Subject: [PATCH 29/48] Disable docker tag for major version 0 --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index a20804bf..4c688a04 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -55,7 +55,7 @@ jobs: type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} + type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} type=sha - name: Build and push From cc8dfc69c3b335830d4e532cfc87add734a6468d Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 13:30:54 +0200 Subject: [PATCH 30/48] Use composite action instead of reusable workflow --- .github/actions/setup-poetry/action.yml | 30 ++++++++++++++++++++++ .github/workflows/pylint.yml | 16 +----------- .github/workflows/python-publish.yml | 16 +----------- .github/workflows/security.yml | 6 ----- .github/workflows/setup.yaml | 33 ------------------------- 5 files changed, 32 insertions(+), 69 deletions(-) create mode 100644 .github/actions/setup-poetry/action.yml delete mode 100644 .github/workflows/setup.yaml diff --git a/.github/actions/setup-poetry/action.yml b/.github/actions/setup-poetry/action.yml new file mode 100644 index 00000000..0ea3c78c --- /dev/null +++ b/.github/actions/setup-poetry/action.yml @@ -0,0 +1,30 @@ +name: 'Setup Python & Poetry' +description: 'Setups Python & Poetry and then installs all dependencies' +inputs: + python-version: + description: 'Used python version' + required: true +runs: + using: composite + steps: + - name: Set up Python ${{ inputs.python-version }} + id: setup-python + uses: actions/setup-python@v4 + with: + python-version: ${{ inputs.python-version }} + + - name: Install poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + shell: bash + run: poetry install --no-interaction diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index bb795048..ee90b0d4 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -18,24 +18,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - id: setup-python - uses: actions/setup-python@v4 + - uses: ./.github/actions/setup-poetry with: python-version: ${{ matrix.python-version }} - - name: Install poetry - uses: snok/install-poetry@v1 - - - name: Load cached venv - uses: actions/cache@v3 - with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} - - - name: Install dependencies - run: poetry install --no-interaction - - name: Lint sources with flake8 run: poetry run flake8 whist_server --count --show-source --statistics diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 2e0897c2..3049a042 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -12,24 +12,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python - id: setup-python - uses: actions/setup-python@v4 + - uses: ./.github/actions/setup-poetry with: python-version: 3.9 - - name: Install poetry - uses: snok/install-poetry@v1 - - - name: Load cached venv - uses: actions/cache@v3 - with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} - - - name: Install dependencies - run: poetry install --no-interaction - - name: Build project run: poetry build diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index a643653d..bcce7535 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -11,18 +11,12 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ 3.9 ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Run bandit uses: tj-actions/bandit@v5 with: diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml deleted file mode 100644 index bb662e52..00000000 --- a/.github/workflows/setup.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: Python Setup - -on: - workflow_call: - inputs: - python-version: - required: true - type: string - os: - required: true - type: string - -jobs: - setup: - runs-on: ${{ inputs.os }} - steps: - - - name: Set up Python ${{ inputs.python-version }} - id: setup-python - uses: actions/setup-python@v4 - with: - python-version: ${{ inputs.python-version }} - - - name: Install poetry - uses: snok/install-poetry@v1 - - - name: Load cached venv - uses: actions/cache@v3 - with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} - - name: Install dependencies - run: poetry install --no-interaction \ No newline at end of file From eb915babe6bc9f1ad6f2417c99f208382e13b8b8 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 14:04:15 +0200 Subject: [PATCH 31/48] Remove unneeded matrices --- .github/workflows/pylint.yml | 11 +++-------- .github/workflows/python-app.yml | 2 +- .github/workflows/security.yml | 6 +----- .github/workflows/stale.yml | 15 ++++++++------- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index ee90b0d4..eed42cd8 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -1,4 +1,4 @@ -name: Pylint +name: Lint on: push: @@ -8,19 +8,14 @@ on: jobs: lint: - strategy: - matrix: - os: [ ubuntu-latest ] - python-version: [ 3.9 ] - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ./.github/actions/setup-poetry with: - python-version: ${{ matrix.python-version }} + python-version: 3.9 - name: Lint sources with flake8 run: poetry run flake8 whist_server --count --show-source --statistics diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2e2f53ef..0fccbe5d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,4 +1,4 @@ -name: Python application +name: Python CI on: push: diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index bcce7535..4f9ab3c6 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -8,11 +8,7 @@ on: jobs: security: - strategy: - matrix: - os: [ ubuntu-latest ] - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 35d8e11a..8ccb8057 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -6,11 +6,12 @@ on: jobs: stale: runs-on: ubuntu-latest + steps: - - name: Close Stale PRs - uses: actions/stale@v5 - with: - days-before-issue-close: -1 - days-before-stale: 30 - exempt-assignees: 'iTitus, Segelzwerg' - exempt-draft-pr: true + - name: Close Stale PRs + uses: actions/stale@v5 + with: + days-before-issue-close: -1 + days-before-stale: 30 + exempt-assignees: 'iTitus, Segelzwerg' + exempt-draft-pr: true From 2be621fe79933d9706cfa54cb7b92a36fe3c4fbe Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 14:06:20 +0200 Subject: [PATCH 32/48] change name of docker action --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 4c688a04..feb10cb8 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,4 +1,4 @@ -name: Docker +name: Docker Image Build & Publish on: push: From 37d2adb1cc60b7d7afd10eda9f2845c48f973c1e Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 14:07:04 +0200 Subject: [PATCH 33/48] rename workflow files --- .github/workflows/{docker-publish.yml => docker-build.yml} | 0 .github/workflows/{pylint.yml => lint.yml} | 0 .github/workflows/{python-app.yml => python-ci.yml} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{docker-publish.yml => docker-build.yml} (100%) rename .github/workflows/{pylint.yml => lint.yml} (100%) rename .github/workflows/{python-app.yml => python-ci.yml} (100%) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-build.yml similarity index 100% rename from .github/workflows/docker-publish.yml rename to .github/workflows/docker-build.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/lint.yml similarity index 100% rename from .github/workflows/pylint.yml rename to .github/workflows/lint.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-ci.yml similarity index 100% rename from .github/workflows/python-app.yml rename to .github/workflows/python-ci.yml From 339863c7cd2b8363a045c0815d046e46d09e169b Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 14:12:54 +0200 Subject: [PATCH 34/48] merge security and pylint lint --- .github/workflows/lint.yml | 13 +++++++++++++ .github/workflows/security.yml | 21 --------------------- 2 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 .github/workflows/security.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index eed42cd8..e8d8f6fd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,3 +22,16 @@ jobs: - name: Lint sources with pylint run: poetry run pylint whist_server + + security: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Run bandit + uses: tj-actions/bandit@v5 + with: + targets: | + whist_server + options: "-r" diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml deleted file mode 100644 index 4f9ab3c6..00000000 --- a/.github/workflows/security.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Security Check - -on: - push: - branches: [ main, develop ] - pull_request: - branches: [ main ] - -jobs: - security: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Run bandit - uses: tj-actions/bandit@v5 - with: - targets: | - whist_server - options: "-r" From b30bb3739c192b988180e9d690d359c7c597693c Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 14:15:52 +0200 Subject: [PATCH 35/48] rename docker job --- .github/workflows/docker-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index feb10cb8..aca40bec 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -15,7 +15,7 @@ env: IMAGE_NAME_GHCR: ghcr.io/${{ github.repository_owner }}/${{ github.repository }} jobs: - docker_deploy: + docker: runs-on: ubuntu-latest steps: From 8928b615b7ee3be4e3434bcb3d7d22586343dd5a Mon Sep 17 00:00:00 2001 From: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 20 Jul 2022 14:55:26 +0200 Subject: [PATCH 36/48] ADD: python 3.11 beta 4 to python ci Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com> --- .github/workflows/python-ci.yml | 49 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 0fccbe5d..b874c188 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -7,46 +7,51 @@ on: branches: [ main ] jobs: - test: + unittest: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ 3.9, '3.10', '3.11.0-beta.4' ] - mongodb-version: [ 4.4, 5.0 ] - test-type: [ 'integtest', '"not integtest"' ] - fail-fast: false - + python-version: [ '3.9', '3.10', '3.11.0-beta.4' ] runs-on: ${{ matrix.os }} - steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - id: setup-python - uses: actions/setup-python@v4 + - uses: ./.github/actions/setup-poetry with: python-version: ${{ matrix.python-version }} - if: ${{ matrix.test-type }} == 'integtest' - - name: Install poetry - uses: snok/install-poetry@v1 + - name: Unittest with pytest + run: poetry run python -m pytest -m "not integtest" --cov=whist_server --cov-report=xml + + - name: Upload to codecoverage + uses: codecov/codecov-action@v3 + with: + file: ./coverage.xml + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + + integrationtest: + strategy: + matrix: + os: [ ubuntu-latest ] + python-version: [ '3.9', '3.10', '3.11.0-beta.4' ] + mongodb-version: [ '4.4', '5.0' ] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 - - name: Load cached venv - uses: actions/cache@v3 + - uses: ./.github/actions/setup-poetry with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + python-version: ${{ matrix.python-version }} - name: Start MongoDB uses: supercharge/mongodb-github-action@1.7.0 with: mongodb-version: ${{ matrix.mongodb-version }} - - name: Install dependencies - run: poetry install --no-interaction - - - name: Test with pytest (${{ matrix.test-type }}) - run: poetry run python -m pytest -m ${{ matrix.test-type }} --cov=whist_server --cov-report=xml + - name: Integrationtest with pytest + run: poetry run python -m pytest -m integtest --cov=whist_server --cov-report=xml - name: Upload to codecoverage uses: codecov/codecov-action@v3 From b42547620930151b86dc10af914af61f64ae80e8 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 20 Jul 2022 16:15:39 +0200 Subject: [PATCH 37/48] Delete setup.py --- setup.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 setup.py diff --git a/setup.py b/setup.py deleted file mode 100644 index e69de29b..00000000 From 4883cb4e68821730839df96a243c5d32a2b1ee0a Mon Sep 17 00:00:00 2001 From: Marcel <25705862+Segelzwerg@users.noreply.github.com> Date: Wed, 27 Jul 2022 08:08:38 +0200 Subject: [PATCH 38/48] Update python-ci.yml --- .github/workflows/python-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 22f9af30..72b7444b 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-beta.4' ] + python-version: [ '3.9', '3.10', '3.11.0-beta.5' ] fail-fast: false runs-on: ${{ matrix.os }} steps: From 201b4c31eb5a6a87d9c445e166caf95c1fecabe1 Mon Sep 17 00:00:00 2001 From: iTitus Date: Wed, 27 Jul 2022 13:50:47 +0200 Subject: [PATCH 39/48] Update python-ci.yml --- .github/workflows/python-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 72b7444b..f89e6e02 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-beta.4' ] + python-version: [ '3.9', '3.10', '3.11.0-beta.5' ] mongodb-version: [ '4.4', '5.0' ] fail-fast: false runs-on: ${{ matrix.os }} From d95227248da78ff6042b754b840944375887ecc4 Mon Sep 17 00:00:00 2001 From: Marcel <25705862+Segelzwerg@users.noreply.github.com> Date: Mon, 15 Aug 2022 23:09:26 +0200 Subject: [PATCH 40/48] BUMP: to rc 1 --- .github/workflows/python-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index f89e6e02..7c054939 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-beta.5' ] + python-version: [ '3.9', '3.10', '3.11.0-rc.1' ] fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -29,7 +29,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-beta.5' ] + python-version: [ '3.9', '3.10', '3.11.0-rc.1' ] mongodb-version: [ '4.4', '5.0' ] fail-fast: false runs-on: ${{ matrix.os }} From 8612bd3a82c3cede9883a39a9bbbf8d8f79c47f7 Mon Sep 17 00:00:00 2001 From: Marcel <25705862+Segelzwerg@users.noreply.github.com> Date: Sat, 17 Sep 2022 10:05:37 +0200 Subject: [PATCH 41/48] Bump: next rc --- .github/workflows/python-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 06819541..89590fcc 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-rc.1' ] + python-version: [ '3.9', '3.10', '3.11.0-rc.2' ] fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -29,7 +29,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-rc.1' ] + python-version: [ '3.9', '3.10', '3.11.0-rc.2' ] mongodb-version: [ '4.4', '5.0', '6.0' ] fail-fast: false runs-on: ${{ matrix.os }} From bf2097a90cf4f58a91a86d4519f5d151d82dc299 Mon Sep 17 00:00:00 2001 From: Marcel <25705862+Segelzwerg@users.noreply.github.com> Date: Mon, 24 Oct 2022 18:13:28 +0200 Subject: [PATCH 42/48] UPDATE: use release version --- .github/workflows/python-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 89590fcc..7668ee76 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-rc.2' ] + python-version: [ '3.9', '3.10', '3.11' ] fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -29,7 +29,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ '3.9', '3.10', '3.11.0-rc.2' ] + python-version: [ '3.9', '3.10', '3.11' ] mongodb-version: [ '4.4', '5.0', '6.0' ] fail-fast: false runs-on: ${{ matrix.os }} From fea2337044d458e18b9aabdd340ac6a2b15b4359 Mon Sep 17 00:00:00 2001 From: Marcel <25705862+Segelzwerg@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:06:51 +0200 Subject: [PATCH 43/48] FIX: typo in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35902813..c4597ccc 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ 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: @@ -70,4 +70,4 @@ In order to run the application it must be started like this: 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`. \ No newline at end of file +:warning: A mongodb instance is required to run before launching the `Whist-Server`. From 051167f0c5a78b444c2d7d1edf005dae25ec8ff2 Mon Sep 17 00:00:00 2001 From: JellyBoonz <86168103+JellyBoonz@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:52:46 -0400 Subject: [PATCH 44/48] Update user.py updated function name --- whist_server/database/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whist_server/database/user.py b/whist_server/database/user.py index 09a96bfa..4075ee9b 100644 --- a/whist_server/database/user.py +++ b/whist_server/database/user.py @@ -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. From 51c8614e25c9474030c87322b06fa501351698b2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 09:16:22 +0000 Subject: [PATCH 45/48] Build(deps): bump whist-core from 0.4.1 to 0.5.0 Bumps [whist-core](https://github.com/Whist-Team/Whist-Core) from 0.4.1 to 0.5.0. - [Release notes](https://github.com/Whist-Team/Whist-Core/releases) - [Commits](https://github.com/Whist-Team/Whist-Core/compare/v0.4.1...v0.5.0) --- updated-dependencies: - dependency-name: whist-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- poetry.lock | 28 ++++++++++++++++------------ pyproject.toml | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/poetry.lock b/poetry.lock index 2b275572..bec8a4ba 100644 --- a/poetry.lock +++ b/poetry.lock @@ -235,7 +235,7 @@ test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==22.8.0)", "databases[sqlite] ( name = "flake8" version = "5.0.4" description = "the modular source code checker: pep8 pyflakes and co" -category = "dev" +category = "main" optional = false python-versions = ">=3.6.1" @@ -248,7 +248,7 @@ pyflakes = ">=2.5.0,<2.6.0" name = "flake8-docstrings" version = "1.6.0" description = "Extension for flake8 which uses pydocstyle to check docstrings" -category = "dev" +category = "main" optional = false python-versions = "*" @@ -385,7 +385,7 @@ python-versions = ">=3.7" name = "mccabe" version = "0.7.0" description = "McCabe checker, plugin for flake8" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -461,7 +461,7 @@ python-versions = "*" name = "pycodestyle" version = "2.9.1" description = "Python style guide checker" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -492,7 +492,7 @@ email = ["email-validator (>=1.0.3)"] name = "pydocstyle" version = "6.1.1" description = "Python docstring style checker" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -506,7 +506,7 @@ toml = ["toml"] name = "pyflakes" version = "2.5.0" description = "passive checker of Python programs" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -724,7 +724,7 @@ python-versions = ">=3.7" name = "snowballstemmer" version = "2.2.0" description = "This package provides 29 stemmers for 28 languages generated from Snowball algorithms." -category = "dev" +category = "main" optional = false python-versions = "*" @@ -852,14 +852,15 @@ python-versions = ">=3.7" [[package]] name = "whist-core" -version = "0.4.1" +version = "0.5.0" description = "Whist rules implementation" category = "main" optional = false python-versions = ">=3.9,<4.0" [package.dependencies] -pydantic = ">=1.9,<2.0" +flake8-docstrings = ">=1.6.0,<2.0.0" +pydantic = ">=1.10,<2.0" python-jose = {version = ">=3.3,<4.0", extras = ["cryptography"]} [[package]] @@ -873,7 +874,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "d7de3f8775c4a66fbe597ece48ebbfa85529c23c46346165f4433c21b3346c89" +content-hash = "3cbec2a761de84001f6ed1cafdc0f193390c367ebf5bff88bf5f638f44fbbb20" [metadata.files] anyio = [ @@ -1276,7 +1277,10 @@ orjson = [ {file = "orjson-3.8.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:b68a42a31f8429728183c21fb440c21de1b62e5378d0d73f280e2d894ef8942e"}, {file = "orjson-3.8.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:ff13410ddbdda5d4197a4a4c09969cb78c722a67550f0a63c02c07aadc624833"}, {file = "orjson-3.8.0-cp310-none-win_amd64.whl", hash = "sha256:2d81e6e56bbea44be0222fb53f7b255b4e7426290516771592738ca01dbd053b"}, + {file = "orjson-3.8.0-cp311-cp311-macosx_10_7_x86_64.whl", hash = "sha256:200eae21c33f1f8b02a11f5d88d76950cd6fd986d88f1afe497a8ae2627c49aa"}, + {file = "orjson-3.8.0-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:9529990f3eab54b976d327360aa1ff244a4b12cb5e4c5b3712fcdd96e8fe56d4"}, {file = "orjson-3.8.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:e2defd9527651ad39ec20ae03c812adf47ef7662bdd6bc07dabb10888d70dc62"}, + {file = "orjson-3.8.0-cp311-none-win_amd64.whl", hash = "sha256:b21c7af0ff6228ca7105f54f0800636eb49201133e15ddb80ac20c1ce973ef07"}, {file = "orjson-3.8.0-cp37-cp37m-macosx_10_7_x86_64.whl", hash = "sha256:9e6ac22cec72d5b39035b566e4b86c74b84866f12b5b0b6541506a080fb67d6d"}, {file = "orjson-3.8.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:e2f4a5542f50e3d336a18cb224fc757245ca66b1fd0b70b5dd4471b8ff5f2b0e"}, {file = "orjson-3.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e1418feeb8b698b9224b1f024555895169d481604d5d884498c1838d7412794c"}, @@ -1753,8 +1757,8 @@ websockets = [ {file = "websockets-10.3.tar.gz", hash = "sha256:fc06cc8073c8e87072138ba1e431300e2d408f054b27047d047b549455066ff4"}, ] whist-core = [ - {file = "whist-core-0.4.1.tar.gz", hash = "sha256:83c6f9dc9dae6340499545e7a65e1ad8cf17bf9b01f0c3225e26758979b38aef"}, - {file = "whist_core-0.4.1-py3-none-any.whl", hash = "sha256:f224de17c15d8aa787611d078ab10898b6e289aa6f076bd8f35651b8da43a348"}, + {file = "whist_core-0.5.0-py3-none-any.whl", hash = "sha256:ac1d2d20def68221aa2bee6e6607c04a057db00e78f9369cbd0eea2a9e2c3cb4"}, + {file = "whist_core-0.5.0.tar.gz", hash = "sha256:2f27493ffc89558f3518e6a0893b6368dc59898f486ec241069b7c220b08369e"}, ] wrapt = [ {file = "wrapt-1.14.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:1b376b3f4896e7930f1f772ac4b064ac12598d1c38d04907e696cc4d794b43d3"}, diff --git a/pyproject.toml b/pyproject.toml index bfe6dc89..399ef1fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ whist-server = "whist_server.cli:main" [tool.poetry.dependencies] python = "^3.9" -whist-core = "^0.4" +whist-core = ">=0.4,<0.6" fastapi = { version = "^0.85", extras = ["all"] } httpx = "^0.23" pydantic = "^1.10" From 6fec59060f812bd0894a43f91fc45851045e5242 Mon Sep 17 00:00:00 2001 From: JellyBoonz <86168103+JellyBoonz@users.noreply.github.com> Date: Wed, 26 Oct 2022 21:16:32 -0400 Subject: [PATCH 46/48] replaced occurences of to_user with to_player --- tests/whist_server/api/ranking/test_leaderboard.py | 12 ++++++------ tests/whist_server/base_token_case.py | 2 +- tests/whist_server/database/test_user.py | 2 +- tests/whist_server/services/test_authentication.py | 4 ++-- tests/whist_server/services/test_ranking_service.py | 8 ++++---- whist_server/database/user.py | 2 +- whist_server/services/authentication.py | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/whist_server/api/ranking/test_leaderboard.py b/tests/whist_server/api/ranking/test_leaderboard.py index a8f8a79a..489e019d 100644 --- a/tests/whist_server/api/ranking/test_leaderboard.py +++ b/tests/whist_server/api/ranking/test_leaderboard.py @@ -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 @@ -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) diff --git a/tests/whist_server/base_token_case.py b/tests/whist_server/base_token_case.py index 2cd9f44f..70eb0385 100644 --- a/tests/whist_server/base_token_case.py +++ b/tests/whist_server/base_token_case.py @@ -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(), diff --git a/tests/whist_server/database/test_user.py b/tests/whist_server/database/test_user.py index 48a9d38b..3a860634 100644 --- a/tests/whist_server/database/test_user.py +++ b/tests/whist_server/database/test_user.py @@ -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') diff --git a/tests/whist_server/services/test_authentication.py b/tests/whist_server/services/test_authentication.py index 4251aa1b..cbcebafc 100644 --- a/tests/whist_server/services/test_authentication.py +++ b/tests/whist_server/services/test_authentication.py @@ -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 @@ -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 diff --git a/tests/whist_server/services/test_ranking_service.py b/tests/whist_server/services/test_ranking_service.py index e71f62be..7af62c07 100644 --- a/tests/whist_server/services/test_ranking_service.py +++ b/tests/whist_server/services/test_ranking_service.py @@ -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) diff --git a/whist_server/database/user.py b/whist_server/database/user.py index 09a96bfa..4075ee9b 100644 --- a/whist_server/database/user.py +++ b/whist_server/database/user.py @@ -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. diff --git a/whist_server/services/authentication.py b/whist_server/services/authentication.py index 8070526f..72bec891 100644 --- a/whist_server/services/authentication.py +++ b/whist_server/services/authentication.py @@ -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: From bc11edfdb0517e86f8a97b29f63049b0c8b8ad9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Nov 2022 09:43:06 +0000 Subject: [PATCH 47/48] Build(deps): bump fastapi from 0.85.1 to 0.85.2 Bumps [fastapi](https://github.com/tiangolo/fastapi) from 0.85.1 to 0.85.2. - [Release notes](https://github.com/tiangolo/fastapi/releases) - [Commits](https://github.com/tiangolo/fastapi/compare/0.85.1...0.85.2) --- updated-dependencies: - dependency-name: fastapi dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- poetry.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index bec8a4ba..b8b55c9c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -206,7 +206,7 @@ test = ["pytest (>=6)"] [[package]] name = "fastapi" -version = "0.85.1" +version = "0.85.2" description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" category = "main" optional = false @@ -228,8 +228,8 @@ uvicorn = {version = ">=0.12.0,<0.19.0", extras = ["standard"], optional = true, [package.extras] all = ["email-validator (>=1.1.1,<2.0.0)", "itsdangerous (>=1.1.0,<3.0.0)", "jinja2 (>=2.11.2,<4.0.0)", "orjson (>=3.2.1,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "pyyaml (>=5.3.1,<7.0.0)", "requests (>=2.24.0,<3.0.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)", "uvicorn[standard] (>=0.12.0,<0.19.0)"] dev = ["autoflake (>=1.4.0,<2.0.0)", "flake8 (>=3.8.3,<6.0.0)", "pre-commit (>=2.17.0,<3.0.0)", "uvicorn[standard] (>=0.12.0,<0.19.0)"] -doc = ["mdx-include (>=1.4.1,<2.0.0)", "mkdocs (>=1.1.2,<2.0.0)", "mkdocs-markdownextradata-plugin (>=0.1.7,<0.3.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "pyyaml (>=5.3.1,<7.0.0)", "typer (>=0.4.1,<0.7.0)"] -test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==22.8.0)", "databases[sqlite] (>=0.3.2,<0.7.0)", "email-validator (>=1.1.1,<2.0.0)", "flake8 (>=3.8.3,<6.0.0)", "flask (>=1.1.2,<3.0.0)", "httpx (>=0.23.0,<0.24.0)", "isort (>=5.0.6,<6.0.0)", "mypy (==0.971)", "orjson (>=3.2.1,<4.0.0)", "passlib[bcrypt] (>=1.7.2,<2.0.0)", "peewee (>=3.13.3,<4.0.0)", "pytest (>=7.1.3,<8.0.0)", "pytest-cov (>=2.12.0,<4.0.0)", "python-jose[cryptography] (>=3.3.0,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "pyyaml (>=5.3.1,<7.0.0)", "requests (>=2.24.0,<3.0.0)", "sqlalchemy (>=1.3.18,<1.5.0)", "types-orjson (==3.6.2)", "types-ujson (==5.4.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)"] +doc = ["mdx-include (>=1.4.1,<2.0.0)", "mkdocs (>=1.1.2,<2.0.0)", "mkdocs-markdownextradata-plugin (>=0.1.7,<0.3.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "pyyaml (>=5.3.1,<7.0.0)", "typer[all] (>=0.6.1,<0.7.0)"] +test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==22.8.0)", "databases[sqlite] (>=0.3.2,<0.7.0)", "email-validator (>=1.1.1,<2.0.0)", "flake8 (>=3.8.3,<6.0.0)", "flask (>=1.1.2,<3.0.0)", "httpx (>=0.23.0,<0.24.0)", "isort (>=5.0.6,<6.0.0)", "mypy (==0.982)", "orjson (>=3.2.1,<4.0.0)", "passlib[bcrypt] (>=1.7.2,<2.0.0)", "peewee (>=3.13.3,<4.0.0)", "pytest (>=7.1.3,<8.0.0)", "pytest-cov (>=2.12.0,<5.0.0)", "python-jose[cryptography] (>=3.3.0,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "pyyaml (>=5.3.1,<7.0.0)", "requests (>=2.24.0,<3.0.0)", "sqlalchemy (>=1.3.18,<=1.4.41)", "types-orjson (==3.6.2)", "types-ujson (==5.5.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)"] [[package]] name = "flake8" @@ -1095,8 +1095,8 @@ exceptiongroup = [ {file = "exceptiongroup-1.0.0rc9.tar.gz", hash = "sha256:9086a4a21ef9b31c72181c77c040a074ba0889ee56a7b289ff0afb0d97655f96"}, ] fastapi = [ - {file = "fastapi-0.85.1-py3-none-any.whl", hash = "sha256:de3166b6b1163dc22da4dc4ebdc3192fcbac7700dd1870a1afa44de636a636b5"}, - {file = "fastapi-0.85.1.tar.gz", hash = "sha256:1facd097189682a4ff11cbd01334a992e51b56be663b2bd50c2c09523624f144"}, + {file = "fastapi-0.85.2-py3-none-any.whl", hash = "sha256:6292db0edd4a11f0d938d6033ccec5f706e9d476958bf33b119e8ddb4e524bde"}, + {file = "fastapi-0.85.2.tar.gz", hash = "sha256:3e10ea0992c700e0b17b6de8c2092d7b9cd763ce92c49ee8d4be10fee3b2f367"}, ] flake8 = [ {file = "flake8-5.0.4-py2.py3-none-any.whl", hash = "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248"}, From 7f4125a10e4a6ca6f8ff8444a8f035a1fd3c5539 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 09:08:04 +0000 Subject: [PATCH 48/48] Build(deps): bump fastapi from 0.85.2 to 0.86.0 Bumps [fastapi](https://github.com/tiangolo/fastapi) from 0.85.2 to 0.86.0. - [Release notes](https://github.com/tiangolo/fastapi/releases) - [Commits](https://github.com/tiangolo/fastapi/compare/0.85.2...0.86.0) --- updated-dependencies: - dependency-name: fastapi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- poetry.lock | 10 +++++----- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index b8b55c9c..34aad86f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -206,7 +206,7 @@ test = ["pytest (>=6)"] [[package]] name = "fastapi" -version = "0.85.2" +version = "0.86.0" description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" category = "main" optional = false @@ -229,7 +229,7 @@ uvicorn = {version = ">=0.12.0,<0.19.0", extras = ["standard"], optional = true, all = ["email-validator (>=1.1.1,<2.0.0)", "itsdangerous (>=1.1.0,<3.0.0)", "jinja2 (>=2.11.2,<4.0.0)", "orjson (>=3.2.1,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "pyyaml (>=5.3.1,<7.0.0)", "requests (>=2.24.0,<3.0.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)", "uvicorn[standard] (>=0.12.0,<0.19.0)"] dev = ["autoflake (>=1.4.0,<2.0.0)", "flake8 (>=3.8.3,<6.0.0)", "pre-commit (>=2.17.0,<3.0.0)", "uvicorn[standard] (>=0.12.0,<0.19.0)"] doc = ["mdx-include (>=1.4.1,<2.0.0)", "mkdocs (>=1.1.2,<2.0.0)", "mkdocs-markdownextradata-plugin (>=0.1.7,<0.3.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "pyyaml (>=5.3.1,<7.0.0)", "typer[all] (>=0.6.1,<0.7.0)"] -test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==22.8.0)", "databases[sqlite] (>=0.3.2,<0.7.0)", "email-validator (>=1.1.1,<2.0.0)", "flake8 (>=3.8.3,<6.0.0)", "flask (>=1.1.2,<3.0.0)", "httpx (>=0.23.0,<0.24.0)", "isort (>=5.0.6,<6.0.0)", "mypy (==0.982)", "orjson (>=3.2.1,<4.0.0)", "passlib[bcrypt] (>=1.7.2,<2.0.0)", "peewee (>=3.13.3,<4.0.0)", "pytest (>=7.1.3,<8.0.0)", "pytest-cov (>=2.12.0,<5.0.0)", "python-jose[cryptography] (>=3.3.0,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "pyyaml (>=5.3.1,<7.0.0)", "requests (>=2.24.0,<3.0.0)", "sqlalchemy (>=1.3.18,<=1.4.41)", "types-orjson (==3.6.2)", "types-ujson (==5.5.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)"] +test = ["anyio[trio] (>=3.2.1,<4.0.0)", "black (==22.8.0)", "coverage[toml] (>=6.5.0,<7.0)", "databases[sqlite] (>=0.3.2,<0.7.0)", "email-validator (>=1.1.1,<2.0.0)", "flake8 (>=3.8.3,<6.0.0)", "flask (>=1.1.2,<3.0.0)", "httpx (>=0.23.0,<0.24.0)", "isort (>=5.0.6,<6.0.0)", "mypy (==0.982)", "orjson (>=3.2.1,<4.0.0)", "passlib[bcrypt] (>=1.7.2,<2.0.0)", "peewee (>=3.13.3,<4.0.0)", "pytest (>=7.1.3,<8.0.0)", "python-jose[cryptography] (>=3.3.0,<4.0.0)", "python-multipart (>=0.0.5,<0.0.6)", "pyyaml (>=5.3.1,<7.0.0)", "requests (>=2.24.0,<3.0.0)", "sqlalchemy (>=1.3.18,<=1.4.41)", "types-orjson (==3.6.2)", "types-ujson (==5.5.0)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,<6.0.0)"] [[package]] name = "flake8" @@ -874,7 +874,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "3cbec2a761de84001f6ed1cafdc0f193390c367ebf5bff88bf5f638f44fbbb20" +content-hash = "5b319bcbea1a93a6391323c6b1efe6abc827227da9034ec7f3ae394fc3ad7bc7" [metadata.files] anyio = [ @@ -1095,8 +1095,8 @@ exceptiongroup = [ {file = "exceptiongroup-1.0.0rc9.tar.gz", hash = "sha256:9086a4a21ef9b31c72181c77c040a074ba0889ee56a7b289ff0afb0d97655f96"}, ] fastapi = [ - {file = "fastapi-0.85.2-py3-none-any.whl", hash = "sha256:6292db0edd4a11f0d938d6033ccec5f706e9d476958bf33b119e8ddb4e524bde"}, - {file = "fastapi-0.85.2.tar.gz", hash = "sha256:3e10ea0992c700e0b17b6de8c2092d7b9cd763ce92c49ee8d4be10fee3b2f367"}, + {file = "fastapi-0.86.0-py3-none-any.whl", hash = "sha256:1020d7ca205d8b95813881fb3282e9c3656e47993531af3aa4ae11065b61dd2c"}, + {file = "fastapi-0.86.0.tar.gz", hash = "sha256:cdcaff84ecf7ae939b9579f0c98b0a0989ee3dd855710a32bc985260d92612f6"}, ] flake8 = [ {file = "flake8-5.0.4-py2.py3-none-any.whl", hash = "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248"}, diff --git a/pyproject.toml b/pyproject.toml index 399ef1fe..115a9b77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ whist-server = "whist_server.cli:main" [tool.poetry.dependencies] python = "^3.9" whist-core = ">=0.4,<0.6" -fastapi = { version = "^0.85", extras = ["all"] } +fastapi = { version = ">=0.85,<0.87", extras = ["all"] } httpx = "^0.23" pydantic = "^1.10" pymongo = "^4.2"