def test_valid_random_woeid(self, get_location_api_url, get_location_search_api_url, get_valid_date, get_random_city, get_valid_woeid): """ Test to verify if Weather Details are fetched for the passed random woeid & date, and if it matches. If: woeid is None (City is not found in Location Search API) API response status code is compared with HTTP Status code 404. Else: API response status code is compared with HTTP Status code 200 """ self.log.info(("*" * 40) + " test_valid_random_woeid " + ("*" * 40)) # Reading from conftest value for woeid & date query = get_random_city date = get_valid_date self.log.info("Random city selected for test: %s", query) # Getting the response from Location Search API ls_response = ops.get(url=get_location_search_api_url, params={'query': query} ) ls_response = ls_response.json() if not ls_response: woeid = None else: woeid = ls_response[0]["woeid"] # Getting the response after making GET API call response = ops.get(url=get_location_api_url, woeid=woeid, date=date ) self.log.info( "\nActual Response:\nResponse Code: %s", response.status_code) allure.dynamic.description( "Response time for the request is: " + str(response.elapsed.total_seconds())) if not woeid: assert response.status_code == requests.codes.NOT_FOUND else: assert response.status_code == requests.codes.ok
def test_valid_woeid_date(self, get_location_api_url, get_valid_date, get_valid_woeid): """ Test to verify if Weather Details are fetched for the passed woeid & date, and if it matches with test data present in json. """ self.log.info(("*" * 40) + " test_valid_woeid_date " + ("*" * 40)) # Reading from conftest value for woeid & date woeid = get_valid_woeid date =get_valid_date # Reading from the JSON validator file data_response = readJson(f"location_day/{woeid}") # Getting the response after making GET API call response = ops.get(url=get_location_api_url, woeid=woeid, date=date ) self.log.info( "\nActual Response:\nResponse Code: %s", response.status_code) allure.dynamic.description( "Response time for the request is: " + str(response.elapsed.total_seconds())) assert response.status_code == requests.codes.ok and \ response.json() == data_response[date]
def test_valid_query_subset_value(self, get_location_search_api_url, location_search_query_subset_param): """ Test to verify if location details received is as per expected result for metaweather api Location Search, on passing a subset of valid city name. """ self.log.info( ("*" * 40) + " test_valid_query_subset_value " + ("*" * 40)) # Reading from conftest value for query parameter i.e. city name subset query = location_search_query_subset_param # Reading from the JSON validator file data_response = readJson( "location_search/valid_subset_query_parameter") self.log.info("\nExpected Response:\n %s", data_response[query]) # Getting the response after making GET API call response = ops.get(url=get_location_search_api_url, params={'query': query} ) self.log.info( "\nActual Response:\nResponse Code: %s \nResponse Body: %s", response.status_code, response.json()) allure.dynamic.description( "Response time for the request is: " + str(response.elapsed.total_seconds())) assert response.status_code == requests.codes.ok and \ response.json() == data_response[query]
def test_invalid_lattlong_value(self, get_location_search_api_url, location_search_lattlong_invalid): """ Test to verify if appropriate error is logged when request on metaweather api Location Search, on passing invalid latitudes & longitudes. """ self.log.info( ("*" * 40) + " test_invalid_lattlong_value " + ("*" * 40)) # Reading from conftest value for lattlong parameter # i.e. latitude & longitude values lattlong = location_search_lattlong_invalid # Getting the response after making GET API call response = ops.get(url=get_location_search_api_url, params={'lattlong': lattlong} ) self.log.info( "\nActual Response:\nResponse Code: %s", response.status_code) allure.dynamic.description( "Response time for the request is: " + str(response.elapsed.total_seconds())) assert response.status_code == requests.codes.BAD_REQUEST
def test_valid_lattlong_value(self, get_location_search_api_url, location_search_lattlong_valid): """ Test to verify if location details received is as per expected result for metaweather api Location Search, on passing valid latitudes & longitudes. """ self.log.info(("*" * 40) + " test_valid_lattlong_value " + ("*" * 40)) # Reading from conftest value for lattlong parameter # i.e. latitude & longitude values lattlong = location_search_lattlong_valid # Reading from the JSON validator file data_response = readJson("location_search/valid_lattlong_parameters") self.log.info("\nExpected Response:\n %s", data_response[lattlong]) # Getting the response after making GET API call response = ops.get(url=get_location_search_api_url, params={'lattlong': lattlong} ) self.log.info( "\nActual Response:\nResponse Code: %s \nResponse Body: %s", response.status_code, response.json()) allure.dynamic.description( "Response time for the request is: " + str(response.elapsed.total_seconds())) assert response.status_code == requests.codes.ok and \ response.json() == data_response[lattlong]
def test_valid_random_lattlong_value(self, get_location_search_api_url, get_random_latt_long): """ Test to verify metaweather api for Location Search on passing a random value in lattlong parameter (random latitude longitude). """ self.log.info( ("*" * 40) + " test_valid_random_lattlong_value " + ("*" * 40)) # Reading from conftest value for lattlong parameter # i.e. latitude & longitude random values lattlong = get_random_latt_long self.log.info("Random Latitude & Longitude selected for test: %s", lattlong) # Getting the response after making GET API call response = ops.get(url=get_location_search_api_url, params={'lattlong': lattlong} ) self.log.info( "\nActual Response:\nResponse Code: %s", response.status_code) allure.dynamic.description( "Response time for the request is: " + str(response.elapsed.total_seconds())) assert response.status_code == requests.codes.ok
def test_valid_random_query_value(self, get_location_search_api_url, get_random_city): """ Test to verify metaweather api for Location Search on passing a random value in query parameter (city name). """ self.log.info( ("*" * 40) + " test_valid_random_query_value " + ("*" * 40)) # Reading from conftest value for query parameter i.e. city name subset query = get_random_city self.log.info("Random city selected for test: %s", query) # Getting the response after making GET API call response = ops.get(url=get_location_search_api_url, params={'query': query} ) self.log.info( "\nActual Response:\nResponse Code: %s \nResponse Body: %s", response.status_code, response.json()) allure.dynamic.description( "Response time for the request is: " + str(response.elapsed.total_seconds())) assert response.status_code == requests.codes.ok