Skip to content

Commit 3e5e055

Browse files
added multiple or operator test
1 parent 5062f02 commit 3e5e055

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_vacancy_restriction() -> dict:
114114
'title': [ops.startswith, ops.eq, ops.endswith],
115115
'category': [ops.startswith, ops.eq, ops.in_],
116116
'salary_from': [ops.between, ops.eq, ops.gt, ops.lt, ops.in_, ops.gte],
117-
'salary_up_to': [ops.eq, ops.gt],
117+
'salary_up_to': [ops.eq, ops.gt, ops.lt],
118118
'description': [ops.like, ops.not_like, ops.contains, ops.eq, ops.in_],
119119
'created_at': [ops.between, ops.in_, ops.eq, ops.gt, ops.lt, ops.not_eq],
120120
'updated_at': [ops.between, ops.in_, ops.eq, ops.gt, ops.lt],

tests/test_filter.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,31 @@ async def test_complex_query(session, get_vacancy_filter, create_vacancies):
372372
}
373373

374374

375+
async def test_several_or_in_query(session, get_vacancy_filter, create_vacancies):
376+
created_between = ["2023-05-01", "2023-05-05"]
377+
created_pattern = "%Y-%m-%d"
378+
updated_in = ["2023-01-05 15:15:15", "2023-05-05 15:15:15"]
379+
updated_pattern = "%Y-%m-%d %H:%M:%S"
380+
salary = 120
381+
382+
query = get_vacancy_filter.get_query(
383+
f"created_at__between={created_between[0]},{created_between[1]}|"
384+
f"updated_at__in_={updated_in[0]},{updated_in[1]}|"
385+
f"salary_up_to__lt={salary}"
386+
)
387+
res = await session.execute(query)
388+
data = ListPydanticVacancy(vacancies=res.scalars().all()).model_dump()
389+
assert len(data["vacancies"]) == 5
390+
391+
for vacancy in data["vacancies"]:
392+
assert (
393+
datetime.strptime(created_between[0], created_pattern).date() < vacancy["created_at"] < datetime.strptime(created_between[1], created_pattern).date()
394+
or vacancy["salary_up_to"] < salary
395+
or vacancy["updated_at"] == datetime.strptime(updated_in[0], updated_pattern)
396+
or vacancy["updated_at"] == datetime.strptime(updated_in[1], updated_pattern)
397+
)
398+
399+
375400
async def test_complex_query_with_order_by(session, get_vacancy_filter, create_vacancies):
376401
query = get_vacancy_filter.get_query(
377402
"created_at__between=2023-05-01,2023-05-05&"

0 commit comments

Comments
 (0)