-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
64 lines (46 loc) · 1.77 KB
/
Copy pathconftest.py
File metadata and controls
64 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright (c) Microsoft Corporation. All rights reserved.
"""Pytest configuration and shared fixtures."""
import pytest
from azure.connectors.sdk import TokenProvider
class MockTokenProvider(TokenProvider):
"""Mock token provider for testing."""
def __init__(self, token: str = "mock_token"):
"""Initialize with a mock token."""
self._token = token
self.close_called = False
async def get_access_token_async(self, scopes: list[str]) -> str:
"""Return the mock token."""
return self._token
async def close(self):
"""Mark that close was called."""
self.close_called = True
class MockResponse:
"""Mock aiohttp.ClientResponse for testing."""
def __init__(self, status: int, text: str = "", headers: dict = None, content: bytes = None):
"""Initialize mock response."""
self.status = status
self.text = text
self.headers = headers or {}
# Set content: if explicitly provided use that, otherwise encode text
if content is not None:
self.content = content
elif text:
self.content = text.encode('utf-8')
else:
self.content = b""
@pytest.fixture
def mock_token_provider():
"""Fixture providing a mock token provider."""
return MockTokenProvider()
@pytest.fixture
def mock_response_success():
"""Fixture providing a successful mock response."""
return MockResponse(status=200, text='{"result": "success"}')
@pytest.fixture
def mock_response_error():
"""Fixture providing an error mock response."""
return MockResponse(status=400, text='{"error": "Bad Request"}')
@pytest.fixture
def mock_response_empty():
"""Fixture providing an empty mock response."""
return MockResponse(status=204, text="")