-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathconftest.py
More file actions
150 lines (125 loc) · 3.7 KB
/
conftest.py
File metadata and controls
150 lines (125 loc) · 3.7 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import shutil
import tempfile
from typing import Callable, Generator
import pytest
from diskcache import Cache
from pytest import TempPathFactory
import ai_marketplace_monitor
from ai_marketplace_monitor.ai import (
AIResponse, # type: ignore
OllamaBackend,
OllamaConfig,
)
from ai_marketplace_monitor.facebook import FacebookItemConfig, FacebookMarketplaceConfig
from ai_marketplace_monitor.listing import Listing
from ai_marketplace_monitor.user import User, UserConfig
@pytest.fixture
def version() -> Generator[str, None, None]:
"""Sample pytest fixture."""
yield ai_marketplace_monitor.__version__
@pytest.fixture
def listing() -> Listing:
return Listing(
marketplace="facebook",
name="test",
id="111",
title="dddd",
image="",
price="$10",
post_url="https://www.facebook.com/marketplace/item/1234567890",
location="houston, tx",
seller="some guy",
condition="New",
description="something good",
)
@pytest.fixture
def marketplace_config() -> FacebookMarketplaceConfig:
return FacebookMarketplaceConfig(
name="facebook",
username="XXXXXXXX",
password="XXXXXXXX",
login_wait_time=10,
seller_locations=["city"],
search_city=["houston"],
availability=["all"],
condition=["new", "used_good"],
date_listed=[7],
delivery_method=["local_pick_up"],
exclude_sellers=["seller"],
max_search_interval=1000,
search_interval=12,
notify=["user1"],
radius=[100],
search_region=["usa"],
)
@pytest.fixture
def item_config() -> FacebookItemConfig:
return FacebookItemConfig(
name="test",
description="long description",
enabled=True,
antikeywords=["exclude1", "exclude2"],
keywords=["include1", "include2"],
search_phrases=["search word one"],
marketplace="facebook",
search_city=["houston"],
# the following are common options
seller_locations=["city"],
condition=["new", "used_good"],
date_listed=[7],
ai=["openai"],
availability=["out", "all"],
delivery_method=["local_pick_up"],
exclude_sellers=["seller"],
max_price=300,
rating=[4],
max_search_interval=1000,
search_interval=12,
min_price=200,
notify=["user1"],
radius=[100],
search_region=["usa"],
)
@pytest.fixture
def ollama_config() -> OllamaConfig:
return OllamaConfig(
name="ollama",
api_key="ollama",
provider="ollama",
base_url="http://localhost:11434/v1",
model="llama3.1:8b",
max_retries=10,
)
@pytest.fixture(scope="session")
def config_file(tmp_path_factory: TempPathFactory) -> Callable:
def generate_config_file(content: str) -> str:
fn = tmp_path_factory.mktemp("config") / "test.toml"
with open(fn, "w") as f:
f.write(content)
return str(fn)
return generate_config_file
@pytest.fixture
def temp_cache() -> Generator[Cache, None, None]:
temp_dir = tempfile.mkdtemp()
cache = Cache(temp_dir)
yield cache
cache.close()
shutil.rmtree(temp_dir)
@pytest.fixture
def user_config() -> UserConfig:
return UserConfig(
name="test",
pushbullet_token="whatever",
max_retries=1,
retry_delay=1,
remind=True,
)
@pytest.fixture
def user(user_config: UserConfig) -> User:
return User(user_config)
@pytest.fixture
def ollama(ollama_config: OllamaConfig) -> User:
return OllamaBackend(ollama_config)
@pytest.fixture
def ai_response() -> AIResponse:
return AIResponse(score=4, comment="good")