Coverage for mlos_bench/mlos_bench/tests/services/remote/mock/mock_auth_service.py: 79%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 00:44 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""A collection Service functions for mocking authentication.""" 

6 

7import logging 

8from typing import Any, Callable, Dict, List, Optional, Union 

9 

10from mlos_bench.services.base_service import Service 

11from mlos_bench.services.types.authenticator_type import SupportsAuth 

12 

13_LOG = logging.getLogger(__name__) 

14 

15 

16class MockAuthService(Service, SupportsAuth[str]): 

17 """A collection Service functions for mocking authentication ops.""" 

18 

19 def __init__( 

20 self, 

21 config: Optional[Dict[str, Any]] = None, 

22 global_config: Optional[Dict[str, Any]] = None, 

23 parent: Optional[Service] = None, 

24 methods: Union[Dict[str, Callable], List[Callable], None] = None, 

25 ): 

26 super().__init__( 

27 config, 

28 global_config, 

29 parent, 

30 self.merge_methods( 

31 methods, 

32 [ 

33 self.get_access_token, 

34 self.get_auth_headers, 

35 self.get_credential, 

36 ], 

37 ), 

38 ) 

39 

40 def get_access_token(self) -> str: 

41 return "TOKEN" 

42 

43 def get_auth_headers(self) -> dict: 

44 return {"Authorization": "Bearer " + self.get_access_token()} 

45 

46 def get_credential(self) -> str: 

47 return "MOCK CREDENTIAL"