Coverage for src/tests/modules/identity/test_authenticate_user.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module for testing the use case authenticate user.""" 

2 

3import pytest 

4 

5from kwai_bc_identity.authenticate_user import ( 

6 AuthenticateUser, 

7 AuthenticateUserCommand, 

8) 

9from kwai_bc_identity.tokens.access_token_db_repository import ( 

10 AccessTokenDbRepository, 

11) 

12from kwai_bc_identity.tokens.log_user_login_db_service import LogUserLoginDbService 

13from kwai_bc_identity.tokens.refresh_token_db_repository import ( 

14 RefreshTokenDbRepository, 

15) 

16from kwai_bc_identity.users.user_account_db_repository import ( 

17 UserAccountDbRepository, 

18) 

19from kwai_core.db.database import Database 

20from kwai_core.domain.value_objects.password import Password 

21 

22 

23pytestmark = pytest.mark.db 

24 

25 

26async def test_authenticate_user( 

27 database: Database, make_user_account_in_db, make_user_account 

28): 

29 """Test the use case authenticate user.""" 

30 user_account = await make_user_account_in_db( 

31 make_user_account(password=Password.create_from_string("Nage-waza/1882")) 

32 ) 

33 command = AuthenticateUserCommand( 

34 username=str(user_account.user.email), password="Nage-waza/1882" 

35 ) 

36 

37 refresh_token = await AuthenticateUser( 

38 UserAccountDbRepository(database), 

39 AccessTokenDbRepository(database), 

40 RefreshTokenDbRepository(database), 

41 LogUserLoginDbService( 

42 database, 

43 user_agent="pytest", 

44 client_ip="127.0.0.1", 

45 email=str(user_account.user.email), 

46 ), 

47 ).execute(command) 

48 

49 assert refresh_token is not None, "There should be a refresh token"