-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathconftest.py
More file actions
197 lines (172 loc) · 5.65 KB
/
conftest.py
File metadata and controls
197 lines (172 loc) · 5.65 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import csv
from http import HTTPStatus
from io import StringIO
from typing import Any, Dict, List
from uuid import UUID
import httpx
import pytest
from pybotx import UserFromSearch, UserKinds
from tests.client.users_api.convert_to_datetime import convert_to_datetime
from tests.client.users_api.factories import CsvUserResponseValues
@pytest.fixture()
def user_from_search_with_data_json() -> Dict[str, Any]:
return {
"user_huid": "6fafda2c-6505-57a5-a088-25ea5d1d0364",
"ad_login": "ad_user_login",
"ad_domain": "cts.com",
"name": "Bob",
"company": "Bobs Co",
"company_position": "Director",
"department": "Owners",
"emails": ["ad_user@cts.com"],
"user_kind": "cts_user",
"active": True,
"created_at": "2023-03-26T14:36:08.740618Z",
"cts_id": "e0140f4c-4af2-5a2e-9ad1-5f37fceafbaf",
"description": "Director in Owners dep",
"ip_phone": "1271020",
"manager": "Alice",
"office": "SUN",
"other_ip_phone": "32593",
"other_phone": "1254218",
"public_name": "Bobby",
"rts_id": "f46440a4-d930-58d4-b3f5-8110ab846ee3",
"updated_at": "2023-03-26T14:36:08.740618Z",
}
@pytest.fixture
def user_from_search_with_data() -> UserFromSearch:
return UserFromSearch(
huid=UUID("6fafda2c-6505-57a5-a088-25ea5d1d0364"),
ad_login="ad_user_login",
ad_domain="cts.com",
username="Bob",
company="Bobs Co",
company_position="Director",
department="Owners",
emails=["ad_user@cts.com"],
other_id=None,
user_kind=UserKinds.CTS_USER,
active=True,
created_at=convert_to_datetime("2023-03-26T14:36:08.740618Z"),
cts_id=UUID("e0140f4c-4af2-5a2e-9ad1-5f37fceafbaf"),
description="Director in Owners dep",
ip_phone="1271020",
manager="Alice",
office="SUN",
other_ip_phone="32593",
other_phone="1254218",
public_name="Bobby",
rts_id=UUID("f46440a4-d930-58d4-b3f5-8110ab846ee3"),
updated_at=convert_to_datetime("2023-03-26T14:36:08.740618Z"),
)
@pytest.fixture
def user_from_search_without_data_json() -> Dict[str, Any]:
return {
"user_huid": "6fafda2c-6505-57a5-a088-25ea5d1d0364",
"ad_login": "ad_user_login",
"ad_domain": "cts.com",
"name": "Bob",
"company": "Bobs Co",
"company_position": "Director",
"department": "Owners",
"emails": ["ad_user@cts.com"],
"user_kind": "cts_user",
"active": None,
"created_at": None,
"cts_id": None,
"description": None,
"ip_phone": None,
"manager": None,
"office": None,
"other_ip_phone": None,
"other_phone": None,
"public_name": None,
"rts_id": None,
"updated_at": None,
}
@pytest.fixture
def user_from_search_without_data() -> UserFromSearch:
return UserFromSearch(
huid=UUID("6fafda2c-6505-57a5-a088-25ea5d1d0364"),
ad_login="ad_user_login",
ad_domain="cts.com",
username="Bob",
company="Bobs Co",
company_position="Director",
department="Owners",
emails=["ad_user@cts.com"],
other_id=None,
user_kind=UserKinds.CTS_USER,
active=None,
created_at=None,
cts_id=None,
description=None,
ip_phone=None,
manager=None,
office=None,
other_ip_phone=None,
other_phone=None,
public_name=None,
rts_id=None,
updated_at=None,
)
@pytest.fixture
def csv_users_from_api() -> list[dict[str, str]]:
"""Generate a list of user dictionaries for CSV testing.
This fixture creates a list of dictionaries representing user data as it would
appear in a CSV response from the BotX API.
:return: A list of dictionaries where each dictionary represents
a user with CSV column names as keys and corresponding values as strings.
"""
result_list = CsvUserResponseValues.create_batch(2)
# add extra value for check APISyncSourceTypes convertion
result_list.append(CsvUserResponseValues(Sync_source="unsupported")) # type: ignore
return result_list
@pytest.fixture
def users_csv_response(csv_users_from_api: List[Dict[str, str]]) -> httpx.Response:
"""
Create a mock HTTP response with CSV user data.
This fixture takes the user data from ``csv_users_from_api`` and converts it into
CSV format. It then returns an ``httpx.Response`` object containing the CSV content.
:param: A list of dictionaries containing user data for CSV conversion.
:return: An HTTP response object with status code 200 (OK) and CSV-formatted
user data as content.
"""
csv_columns = [
"HUID",
"AD Login",
"Domain",
"AD E-mail",
"Name",
"Sync source",
"Active",
"Kind",
"User DN",
"Company",
"Department",
"Position",
"Manager",
"Manager HUID",
"Manager DN",
"Personnel number",
"Description",
"IP phone",
"Other IP phone",
"Phone",
"Other phone",
"Avatar",
"Office",
"Avatar preview",
]
output = StringIO()
writer = csv.DictWriter(output, fieldnames=csv_columns)
writer.writeheader()
for user in csv_users_from_api:
ordered_row_values = {
column_name: user[column_name] for column_name in csv_columns
}
writer.writerow(ordered_row_values)
return httpx.Response(
status_code=HTTPStatus.OK,
content=output.getvalue().encode("utf-8"),
)