def setUp(self): """""" super().setUp() self.host = 'http://www.weather.com.cn' self.ep_path = '/data/cityinfo' self.client = HttpClient()
class Weather(TestCase): """Weather api test cases""" def setUp(self): """Setup of the test""" self.host = 'http://www.weather.com.cn' self.ep_path = '/data/cityinfo' self.client = HttpClient() @allure.story('Test of ShenZhen') def test_1(self): city_code = '101280601' exp_city = '深圳' self._test(city_code, exp_city) @allure.story('Test of BeiJing') def test_2(self): city_code = '101010100' exp_city = '北京' self._test(city_code, exp_city) @allure.story('Test of ShangHai') def test_3(self): city_code = '101020100' exp_city = '上海' self._test(city_code, exp_city) def _test(self, city_code, exp_city): url = f'{self.host}{self.ep_path}/{city_code}.html' response = self.client.Get(url=url) act_city = response.json()['weatherinfo']['city'] print(f'Expect city = {exp_city}, while actual city = {act_city}') self.assertEqual( exp_city, act_city, f'Expect city = {exp_city}, while actual city = {act_city}')
class Weather(TestCase): """Weather api test cases""" def setUp(self): # super(self).setUp() self.host = 'http://www.weather.com.cn' self.ep_path = '/data/cityinfo' self.client = HttpClient() # @allure.story('Test of shenzhen') def test_1(self): city_code = '101280601' exp_city = "18:00" self._test(city_code, exp_city) def test_2(self): city_code = '101010100' exp_city = "18:00" self._test(city_code, exp_city) def _test(self, city_code, exp_city): url = self.host + self.ep_path + '/' + city_code + '.html' print(url) response = self.client.get(url=url) print(response.content) act_city = response.json()['weatherinfo']['ptime'] print(act_city) #print('Expect city = %s, while actual city = %s' % (exp_city, act_city)) # self.assertEqual(exp_city, act_city, 'Expect city = {exp_city}, while actual city = {act_city}') self.assertEqual(exp_city, act_city)
class Weather(TestCase): """Weather api test cases""" def setUp(self): """Setup of the test""" self.host = 'http://www.weather.com.cn' self.ep_path = '/data/cityinfo' self.client = HttpClient() @allure.story('Test of HangZhou') @allure.severity(allure.severity_level.NORMAL) def test_weather_hangzhou(self): city_code = '101210101' exp_city = '杭州' self._test(city_code, exp_city) @allure.story('Test of FuYang') @allure.severity(allure.severity_level.MINOR) def test_weather_fuyang(self): city_code = '101220801' exp_city = '阜阳' self._test(city_code, exp_city) @allure.story('Test of NingBo') def test_weather_ningbo(self): city_code = '101210401' exp_city = '宁波' self._test(city_code, exp_city) @allure.story('Test of ShangHai') @allure.severity(allure.severity_level.BLOCKER) def test_weather_shanghai(self): city_code = '101020100' exp_city = '上海' self._test(city_code, exp_city) @allure.story('Test of GuiYang') @allure.severity(allure.severity_level.TRIVIAL) def test_weather_guiyang(self): city_code = '101260101' exp_city = '贵阳' self._test(city_code, exp_city) def _test(self, city_code, exp_city): url = f'{self.host}{self.ep_path}/{city_code}.html' response = self.client.Get(url=url) act_city = response.json()['weatherinfo']['city'] print(f'Expect city = {exp_city}, while actual city = {act_city}') # self.assertEqual(exp_city, act_city, f'Expect city = {exp_city}, while actual city = {act_city}') self.assertEqual(exp_city, act_city)
class TestWeather: """Weather api test cases""" def setup(self): """""" self.host = 'http://www.weather.com.cn' self.api = '/data/cityinfo' self.client = HttpClient() @pytest.mark.parametrize('city_code, exp_city', [("101280601", "深圳1"), ("101010100", "北京"), ("101020100", "上海")]) def test_weather(self, city_code, exp_city): url = f'{self.host}{self.api}/{city_code}.html' response = self.client.Get(url=url) act_city = response.json()['weatherinfo']['city'] print(f'Expect city = {exp_city}, while actual city = {act_city}') assert exp_city == act_city
def setUp(self): """Setup of the test""" self.host = 'http://www.weather.com.cn' self.ep_path = '/data/cityinfo' self.client = HttpClient()
def setup(self): """""" self.host = 'http://www.weather.com.cn' self.api = '/data/cityinfo' self.client = HttpClient()