def test_pop_service_error(temp, expected_result): rock_service = ClassicService() city = City(name="Test City", temperature=temp, searched_date="29/06/2020") with raises(Exception) as e: rock_service.get_genre_playlist(city) assert e.errisinstance(HTTPException)
def test_chain_of_responsibility(temp, expected_result): genre_service = ClassicService(RockService(PopService())) city = City(name="Test City", temperature=temp, searched_date="29/06/2020") track_list = genre_service.get_genre_playlist(city) for track in track_list: assert track.genre == expected_result
def test_rock_service(temp): rock_service = RockService() city = City(name="Test City", temperature=temp, searched_date="29/06/2020") track_list = rock_service.get_genre_playlist(city) for track in track_list: assert isinstance(track, Track)
def __get_city_info(self, city: str) -> City: response = self._http_client.get('/weather', params={"q": city, "appid": self.API_WEATHER_KEY, "units": "metric"}) return City( name=response['name'], temperature=response['main']['temp'], searched_date=datetime.now().strftime("%d/%m/%Y %H:%M:%S") )
def get_all_searched_cities(self): cities = self._repository.get_all() if not cities: raise HTTPException( status_code=404, detail="Cities not found", ) return [ City( name=city.name, temperature=city.temperature, searched_date=city.date.strftime("%d/%m/%Y %H:%M:%S"), track_list=[Track(name=track.name, artist=track.artist) for track in city.track_list] ) for city in cities ]