-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathconftest.py
More file actions
107 lines (90 loc) · 2.92 KB
/
conftest.py
File metadata and controls
107 lines (90 loc) · 2.92 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""Shared pytest fixtures and configuration for all tests."""
import os
import tempfile
import shutil
from pathlib import Path
from typing import Generator, Dict, Any
import pytest
import yaml
@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Create a temporary directory for test files."""
temp_path = Path(tempfile.mkdtemp())
yield temp_path
# Cleanup after test
if temp_path.exists():
shutil.rmtree(temp_path)
@pytest.fixture
def mock_config() -> Dict[str, Any]:
"""Provide a mock configuration dictionary for testing."""
return {
"search_tweets_api": {
"endpoint": "https://api.twitter.com/1.1/tweets/search/30day/test.json",
"consumer_key": "test_consumer_key",
"consumer_secret": "test_consumer_secret",
"bearer_token": "test_bearer_token"
}
}
@pytest.fixture
def mock_yaml_config(temp_dir: Path, mock_config: Dict[str, Any]) -> Path:
"""Create a temporary YAML configuration file."""
config_path = temp_dir / "test_config.yaml"
with open(config_path, 'w', encoding='utf-8') as f:
yaml.dump(mock_config, f)
return config_path
@pytest.fixture
def mock_credentials() -> Dict[str, str]:
"""Provide mock API credentials for testing."""
return {
"consumer_key": "test_consumer_key",
"consumer_secret": "test_consumer_secret",
"access_token": "test_access_token",
"access_token_secret": "test_access_token_secret",
"bearer_token": "test_bearer_token"
}
@pytest.fixture
def mock_tweet_response() -> Dict[str, Any]:
"""Provide a mock tweet API response for testing."""
return {
"results": [
{
"id": "1234567890",
"text": "This is a test tweet",
"created_at": "2023-01-01T00:00:00Z",
"user": {
"id": "987654321",
"screen_name": "test_user"
}
}
],
"next": "next_token_value"
}
@pytest.fixture
def mock_search_params() -> Dict[str, Any]:
"""Provide mock search parameters for testing."""
return {
"query": "python",
"fromDate": "202301010000",
"toDate": "202301020000",
"maxResults": 100
}
@pytest.fixture(autouse=True)
def setup_test_environment(monkeypatch):
"""Set up test environment variables."""
# Clear any existing Twitter API environment variables
env_vars = [
"TWITTER_CONSUMER_KEY",
"TWITTER_CONSUMER_SECRET",
"TWITTER_ACCESS_TOKEN",
"TWITTER_ACCESS_TOKEN_SECRET",
"TWITTER_BEARER_TOKEN"
]
for var in env_vars:
monkeypatch.delenv(var, raising=False)
# Set test environment flag
monkeypatch.setenv("TESTING", "true")
@pytest.fixture
def capture_logs(caplog):
"""Fixture to capture log messages during tests."""
with caplog.at_level("DEBUG"):
yield caplog