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

13 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-06 00:35 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5""" 

6A collection Service functions for mocking authentication. 

7""" 

8 

9import logging 

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

11 

12from mlos_bench.services.base_service import Service 

13from mlos_bench.services.types.authenticator_type import SupportsAuth 

14 

15_LOG = logging.getLogger(__name__) 

16 

17 

18class MockAuthService(Service, SupportsAuth): 

19 """ 

20 A collection Service functions for mocking authentication ops. 

21 """ 

22 

23 def __init__(self, config: Optional[Dict[str, Any]] = None, 

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

25 parent: Optional[Service] = None, 

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

27 super().__init__( 

28 config, global_config, parent, 

29 self.merge_methods(methods, [ 

30 self.get_access_token, 

31 self.get_auth_headers, 

32 ]) 

33 ) 

34 

35 def get_access_token(self) -> str: 

36 return "TOKEN" 

37 

38 def get_auth_headers(self) -> dict: 

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