-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
167 lines (128 loc) · 3.58 KB
/
conftest.py
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from datetime import datetime
from time import sleep
import pytest
from flask.app import Flask
from app import create_app
from meetup_search.commands.migrate_models import migrate_models
from meetup_search.meetup_api_client.meetup_api_client import MeetupApiClient
from meetup_search.models.group import Group
from meetup_search.models.meetup_zip import MeetupZip
from meetup_search.models.token import Token
@pytest.fixture
def api_client() -> MeetupApiClient:
"""
meetup api client
Returns:
MeetupApiClient -- Meetup Api client
"""
return MeetupApiClient()
@pytest.fixture
def app() -> Flask:
"""
flask app fixture for texting
Returns:
Flask -- flask app with testing config
"""
return create_app(config_path="/app/config/test.py")
@pytest.fixture
def meetup_groups() -> dict:
"""
test groups with id & real meetup group urlname
Returns:
dict -- dict with mutiple meetup groups
"""
return {
"sandbox": {"meetup_id": 1556336, "urlname": "Meetup-API-Testing"},
"not-exist": {"meetup_id": 123456, "urlname": "None"},
"gone": {"meetup_id": 654321, "urlname": "connectedawareness-berlin"},
}
def create_group(
urlname: str, meetup_id: int = 0, name: str = "", lat: float = 0, lon: float = 0
) -> Group:
"""
create group object
Arguments:
urlname {str} -- urlname for group object
Keyword Arguments:
meetup_id {int} -- meetup_id for group object (default: {0})
name {str} -- name for group object (default: {""})
Returns:
Group -- new unsaved group object
"""
return Group(
meetup_id=meetup_id,
urlname=urlname,
created=datetime.now(),
description="",
name=name,
link="",
location={"lat": lat, "lon": lon},
members=0,
status="",
timezone="",
visibility="",
)
@pytest.fixture
def group_1() -> Group:
"""
create group object
Returns:
Group -- unsaved group object
"""
return create_group(urlname="1")
@pytest.fixture
def group_2() -> Group:
"""
create group object with a differnet urlname than group_1
Returns:
Group -- unsaved group object
"""
return create_group(urlname="2")
@pytest.fixture
def auth_token() -> Token:
"""
create new token
Returns:
Token -- saved token
"""
new_token: Token = Token(
access_token="access",
refresh_token="refresh"
)
return new_token
def pytest_runtest_setup():
"""
Run for each test
delete elasticsearch index & init the index afterwards
"""
delte_index()
init_models()
def pytest_runtest_teardown():
"""
Run after each test
delete elasticsearch index
"""
delte_index()
def delte_index():
"""
delte elasticsearch index
"""
print("delete Elasticsearch index: {}".format(Group.Index.name))
create_app(config_path="/app/config/test.py").config["ES"].indices.delete(
index=Group.Index.name, ignore=[400, 404]
)
print("delete Elasticsearch index: {}".format(MeetupZip.Index.name))
create_app(config_path="/app/config/test.py").config["ES"].indices.delete(
index=MeetupZip.Index.name, ignore=[400, 404]
)
print("delete Elasticsearch index: {}".format(Token.Index.name))
create_app(config_path="/app/config/test.py").config["ES"].indices.delete(
index=Token.Index.name, ignore=[400, 404]
)
sleep(2)
def init_models():
"""
init elasticsearch index
"""
migrate_models()
sleep(1)