Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1007 [BE] Add Pagination to Search #1008

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions BackEnd/search/tests/test_advanced_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def setUp(self) -> None:

def test_get_search_in_all_companies_official_order_by_name(self):
response = self.client.get(path="/api/search/advanced?search=official")
names_from_response = [prof["name"] for prof in response.data]
names_from_response = [
prof["name"] for prof in response.data["results"]
]
self.assertEqual(200, response.status_code)
self.assertEqual(
names_from_response,
Expand All @@ -74,52 +76,58 @@ def test_get_search_in_all_companies_official_order_by_name(self):
def test_get_search_name_service_info_lower_case(self):
response = self.client.get(path="/api/search/advanced?search=kyiv")
self.assertEqual(200, response.status_code)
self.assertEqual(2, len(response.data))
self.assertEqual(2, response.data["total_items"])

def test_get_search_name_service_info_authorized(self):
self.client.force_authenticate(self.user)
response = self.client.get(path="/api/search/advanced?search=kyiv")
self.assertEqual(200, response.status_code)
self.assertEqual(2, len(response.data))
self.assertEqual(2, response.data["total_items"])

def test_get_search_name_service_info_upper_case(self):
response = self.client.get(path="/api/search/advanced?search=KYIV")
self.assertEqual(200, response.status_code)
self.assertEqual(2, len(response.data))
self.assertEqual(2, response.data["total_items"])

def test_get_search_parcial_item(self):
response = self.client.get(path="/api/search/advanced?search=ch")
names_from_response = [prof["name"] for prof in response.data]
names_from_response = [
prof["name"] for prof in response.data["results"]
]
self.assertEqual(200, response.status_code)
self.assertEqual(3, len(response.data))
self.assertEqual(3, response.data["total_items"])
self.assertEqual(
names_from_response, ["Charkiv", "Chernigiv", "Dnipro"]
)

def test_get_search_not_exist(self):
response = self.client.get(path="/api/search/advanced?search=QQQ")
self.assertEqual(200, response.status_code)
self.assertEqual([], response.json())
self.assertEqual([], response.data["results"])

def test_get_search_name_product_info(self):
response = self.client.get(path="/api/search/advanced?search=dnipro")
self.assertEqual(200, response.status_code)
self.assertEqual(2, len(response.data))
self.assertEqual(2, response.data["total_items"])

def test_get_search_name_service_product_common_info(self):
response = self.client.get(path="/api/search/advanced?search=KYIV")
names_from_response = [prof["name"] for prof in response.data]
names_from_response = [
prof["name"] for prof in response.data["results"]
]
self.assertEqual(200, response.status_code)
self.assertEqual(2, len(response.data))
self.assertEqual(2, response.data["total_items"])
self.assertEqual(names_from_response, ["Kryvyi Rig", "Kyiv"])

def test_get_search_devide_item(self):
response = self.client.get(
path="/api/search/advanced?search=product info"
)
names_from_response = [prof["name"] for prof in response.data]
names_from_response = [
prof["name"] for prof in response.data["results"]
]
self.assertEqual(200, response.status_code)
self.assertEqual(1, len(response.data))
self.assertEqual(1, response.data["total_items"])
self.assertEqual(names_from_response, ["Kryvyi Rig"])

def test_advanced_search_serializer_fields(self):
Expand All @@ -144,4 +152,4 @@ def test_advanced_search_serializer_fields(self):
"person": self.company_kyiv.person_id,
}
]
self.assertEqual(expected_result, response.json())
self.assertEqual(expected_result, response.data["results"])
Loading
Loading