Skip to content

Commit

Permalink
added pagination to search, updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lvyshnevska committed Dec 8, 2024
1 parent 904d905 commit dcd7a64
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 82 deletions.
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

0 comments on commit dcd7a64

Please sign in to comment.