Пример #1
0
 def test_for_params_control(self):
     years = ['2010', '2015']
     colors = ['black', 'blue']
     brands = ['bmw', 'audi']
     trans_types = ['manual', 'automatic']
     for year, trans, brand, color in zip(years, trans_types, brands,
                                          colors):
         tester = app.test_client(self)
         response = tester.get(
             f'{self.main_path}?brand={brand}&year={year}&trans={trans}&extcolor={color}'
         )
         json_data = json.loads(response.data)['cars']
         self.assertTrue(json_data, msg='The list is empty')
         for data in json_data:
             self.assertEqual(
                 str(data['trans_type']).lower(),
                 str(trans).lower())
             self.assertEqual(str(data['year']).lower(), str(year).lower())
             self.assertEqual(
                 str(data['brand']).lower(),
                 str(brand).lower())
             self.assertEqual(
                 str(data['exterior_color']).lower(),
                 str(color).lower())
         self.assertEqual(response.status_code,
                          requests.codes.ok,
                          msg=f'status code {response.status_code}')
Пример #2
0
 def test_return_count(self):
     tester = app.test_client(self)
     response = tester.get(f'{self.main_path}')
     if response.status_code == requests.codes.ok:
         data = json.loads(response.data)['cars']
         self.assertEqual(len(data), 50, msg='cars count is missing')
     self.assertEqual(response.status_code,
                      requests.codes.ok,
                      msg=f'status code {response.status_code}')
Пример #3
0
 def test_year_control(self):
     years = ['2020', '1990', '2017']
     for year in years:
         tester = app.test_client(self)
         response = tester.get(f'{self.main_path}?year={year}')
         json_data = json.loads(response.data)['cars']
         self.assertTrue(json_data, msg='The list is empty')
         for data in json_data:
             self.assertEqual(str(data['year']).lower(), str(year).lower())
         self.assertEqual(response.status_code,
                          requests.codes.ok,
                          msg=f'status code {response.status_code}')
Пример #4
0
 def test_brand_control(self):
     brands = ['bmw', 'audi', 'ford']
     for brand in brands:
         tester = app.test_client(self)
         response = tester.get(f'{self.main_path}?brand={brand}')
         json_data = json.loads(response.data)['cars']
         self.assertTrue(json_data, msg='The list is empty')
         for data in json_data:
             self.assertEqual(
                 str(data['brand']).lower(),
                 str(brand).lower())
         self.assertEqual(response.status_code,
                          requests.codes.ok,
                          msg=f'status code {response.status_code}')
Пример #5
0
 def test_color_control(self):
     colors = ['black', 'Black', 'white', 'RED']
     for color in colors:
         tester = app.test_client(self)
         response = tester.get(f'{self.main_path}?extcolor={color}')
         json_data = json.loads(response.data)['cars']
         self.assertTrue(json_data, msg='The list is empty')
         for data in json_data:
             self.assertEqual(
                 str(data['exterior_color']).lower(),
                 str(color).lower())
         self.assertEqual(response.status_code,
                          requests.codes.ok,
                          msg=f'status code {response.status_code}')
Пример #6
0
 def test_trans_control(self):
     trans_types = ['manual', 'automatic']
     for trans in trans_types:
         tester = app.test_client(self)
         response = tester.get(f'{self.main_path}?trans={trans}')
         json_data = json.loads(response.data)['cars']
         self.assertTrue(json_data, msg='The list is empty')
         for data in json_data:
             self.assertEqual(
                 str(data['trans_type']).lower(),
                 str(trans).lower())
         self.assertEqual(response.status_code,
                          requests.codes.ok,
                          msg=f'status code {response.status_code}')
Пример #7
0
 def test_two_params_control(self):
     colors = ['black', 'Black', 'white', 'RED']
     brands = ['bmw', 'audi', 'FORD']
     for color, brand in zip(colors, brands):
         tester = app.test_client(self)
         response = tester.get(
             f'{self.main_path}?extcolor={color}&brand={brand}')
         json_data = json.loads(response.data)['cars']
         self.assertTrue(json_data, msg='The list is empty')
         for data in json_data:
             self.assertEqual(
                 str(data['exterior_color']).lower(),
                 str(color).lower())
             self.assertEqual(
                 str(data['brand']).lower(),
                 str(brand).lower())
         self.assertEqual(response.status_code,
                          requests.codes.ok,
                          msg=f'status code {response.status_code}')
Пример #8
0
 def test_car_list_multi(self):
     tester = app.test_client(self)
     response = tester.get(
         f'{self.main_path}?trans=automatic&brand=BMW&color=black&year=2020'
     )
     self.assertEqual(response.status_code, requests.codes.ok)
Пример #9
0
 def test_car_list_trans(self):
     tester = app.test_client(self)
     response = tester.get(f'{self.main_path}?trans=automatic')
     self.assertEqual(response.status_code, requests.codes.ok)
Пример #10
0
 def test_car_list_color(self):
     tester = app.test_client(self)
     response = tester.get(f'{self.main_path}?color=black')
     self.assertEqual(response.status_code, requests.codes.ok)
Пример #11
0
 def test_car_list_brand(self):
     tester = app.test_client(self)
     response = tester.get(f'{self.main_path}?brand=BMW')
     self.assertEqual(response.status_code, requests.codes.ok)
Пример #12
0
 def test_car_list_content(self):
     tester = app.test_client(self)
     response = tester.get(self.main_path)
     self.assertEqual(response.content_type, 'application/json')