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

15 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-01 00:52 +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 collections.abc import Callable 

9from typing import Any 

10 

11from mlos_bench.services.base_service import Service 

12from mlos_bench.services.types.authenticator_type import SupportsAuth 

13 

14_LOG = logging.getLogger(__name__) 

15 

16 

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

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

19 

20 def __init__( 

21 self, 

22 config: dict[str, Any] | None = None, 

23 global_config: dict[str, Any] | None = None, 

24 parent: Service | None = None, 

25 methods: dict[str, Callable] | list[Callable] | None = None, 

26 ): 

27 super().__init__( 

28 config, 

29 global_config, 

30 parent, 

31 self.merge_methods( 

32 methods, 

33 [ 

34 self.get_access_token, 

35 self.get_auth_headers, 

36 self.get_credential, 

37 ], 

38 ), 

39 ) 

40 

41 def get_access_token(self) -> str: 

42 return "TOKEN" 

43 

44 def get_auth_headers(self) -> dict: 

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

46 

47 def get_credential(self) -> str: 

48 return "MOCK CREDENTIAL"