12
12
from django .urls import reverse
13
13
from search .helpers .photo import UnplashCityPhotoHelper
14
14
from urllib .request import urlopen
15
- from unittest .mock import patch
15
+ from unittest .mock import MagicMock , patch
16
16
from info .models import FavCityEntry
17
17
from search .helpers .photo import UnplashCityPhotoHelper
18
18
from urllib .request import urlopen
19
19
from info .models import ItineraryItem
20
- from django .utils import timezone # Added import for timezone
20
+ from django .utils import timezone
21
+
22
+ from search .utils .search import AmadeusCitySearch , GeoDB # Added import for timezone
21
23
22
24
image_formats = ("image/png" , "image/jpeg" , "image/gif" )
23
25
@@ -654,3 +656,52 @@ def test_profile_page_and_fav_city(self):
654
656
self .assertContains (response , 'Paris' )
655
657
656
658
# # should add more tests relating to the profile page
659
+ class TestGeoDB (TestCase ):
660
+ def setUp (self ):
661
+ # Provide required arguments for the URL class
662
+ self .url = URL (protocol = "https" , host = "test-geodb.com" , port = None )
663
+ self .geo_db = GeoDB (url = self .url )
664
+
665
+ def tearDown (self ):
666
+ self .geo_db = None
667
+
668
+ def test_get_city_suggestions_success (self ):
669
+ with patch ("requests.request" ) as mock_request :
670
+ mock_response = MagicMock ()
671
+ mock_response .json .return_value = {"data" : [{"city" : "Test City" , "country" : "Test Country" }]}
672
+ mock_request .return_value = mock_response
673
+
674
+ city_suggestions = self .geo_db .get_city_suggestions (city = "Test" )
675
+ self .assertIn ("data" , city_suggestions )
676
+ self .assertEqual (city_suggestions ["data" ][0 ]["city" ], "Test City" )
677
+
678
+ def test_get_city_suggestions_failure (self ):
679
+ with patch ("requests.request" ) as mock_request :
680
+ mock_response = MagicMock ()
681
+ mock_response .json .return_value = {"error" : "Invalid Request" }
682
+ mock_request .return_value = mock_response
683
+
684
+ city_suggestions = self .geo_db .get_city_suggestions (city = "Invalid" )
685
+ self .assertIn ("error" , city_suggestions )
686
+ self .assertEqual (city_suggestions ["error" ], "Invalid Request" )
687
+
688
+
689
+ class TestAmadeusCitySearch (TestCase ):
690
+ def setUp (self ):
691
+ # Provide required arguments for the URL class
692
+ self .url = URL (protocol = "https" , host = "test-amadeus.com" , port = None )
693
+ self .city_search = AmadeusCitySearch (url = self .url )
694
+
695
+ def tearDown (self ):
696
+ self .city_search = None
697
+
698
+ def test_get_city_suggestions_success (self ):
699
+ with patch ("requests.request" ) as mock_request :
700
+ mock_response = MagicMock ()
701
+ mock_response .json .return_value = {"data" : [{"name" : "New York" }]}
702
+ mock_request .return_value = mock_response
703
+
704
+ self .city_search ._access_token = "test_access_token"
705
+ city_suggestions = self .city_search .get_city_suggestions (city = "New York" )
706
+ self .assertIn ("data" , city_suggestions )
707
+ self .assertEqual (city_suggestions ["data" ][0 ]["name" ], "New York" )
0 commit comments