def test_search_text_valid_iso2(self): """ Testing the service for valid results with search text as any valid ISO2CODE """ # Fetch test data and read the ISO2CODE from the first record of the result assert self.fetch_data_and_validate() assert len(self.test_data_list) > 0 item = self.test_data_list[0] iso2code = item['alpha2_code'] # Create URL to test with ISO2CODE # Fetch status code and content from get method url2 = self.url + iso2code status_code, content = self.service.get(url2) assert status_code == HTTPStatus.OK # Check if the JSON format of content is valid # Read the message returned in the content validate(instance=content, schema=Schemas.schema_all) resp = content['RestResponse']['messages'] assert len(resp) == 1 resp_msg = resp[0] # Read the number of records returned total_no_of_records = CommonUtilities.fetch_total_records(resp_msg) assert total_no_of_records != -1 # Verify if the length of results list is same as the no mentioned in messages # Verify if the result list contains the iso2code as text in name,iso2code or iso3code assert len(content['RestResponse']['result']) == int(total_no_of_records) assert self.search_text(content['RestResponse']['result'], iso2code)
def test_get_all_valid(self): """ Testing the webservice for a valid request Expectation: Webservice should return HTTP Status 200 OK and a valid json with all records in the content """ status_code, content = self.service.get(self.url) assert status_code == HTTPStatus.OK # Check if the JSON format is valid validate(instance=content, schema=Schemas.schema_all) # Read the message returned in the content resp = content['RestResponse']['messages'] assert len(resp) == 1 resp_msg = resp[0] # Read the number of records returned total_no_of_records = CommonUtilities.fetch_total_records(resp_msg) assert total_no_of_records != -1 assert len( content['RestResponse']['result']) == int(total_no_of_records)
def test_search_text_empty_string(self): """ Testing to query records with empty search text Expectation: Service should return all records """ status_code, content = self.service.get(self.url) assert status_code == HTTPStatus.OK # Check if the JSON format of content is valid as it will return the full list # Read the message returned in the content validate(instance=content, schema=Schemas.schema_all) resp = content['RestResponse']['messages'] assert len(resp) == 1 resp_msg = resp[0] # Read the number of records returned total_no_of_records = CommonUtilities.fetch_total_records(resp_msg) assert total_no_of_records != -1 # Verify the total no of records matches in message and result list assert len(content['RestResponse']['result']) == int(total_no_of_records)
def fetch_data_and_validate(self): """ Method to fetch, validate and store all records for future test cases Return: (bool): return True if method is successful in fetching the test data, false otherwise """ # Fetch data for all records that will be used as test data in further methods # Check if the JSON format of test_content is valid status_code, test_content = self.service.get(self.url_testdata) validate(instance=test_content, schema=Schemas.schema_all) self.test_data_list = test_content['RestResponse']['result'] # Read the message returned in the content resp = test_content['RestResponse']['messages'] if len(resp) == 1: resp_msg = resp[0] else: return False # Read the number of records returned self.total_no_of_records = CommonUtilities.fetch_total_records(resp_msg) if self.total_no_of_records != -1: return True else: return False
def test_fetch_total_records_invalid(self): num_records = CommonUtilities.fetch_total_records("Total records") assert num_records is None
def test_fetch_total_records_valid(self): num_records = CommonUtilities.fetch_total_records("Total [4] records") assert int(num_records) == 4