def add_new_car(self):
     self.date = datetime.now().strftime("%H:%M:%S")
     new_car = '{"name":"TestName", "model":"TestModel", "type":"TestType", "status":1}'
     self.car = json.loads(new_car)
     CarApiService.add_new_car(car=new_car)
     yield
     CarApiService.delete_car(model=self.car['model'])
示例#2
0
    def test_smoke_suite(self):
        new_car = f'{"name":"Lamborghini", "model":"Huracan{randint(0, 1000)}", "type":"sportcar", "status":1}'

        # add new car
        add_response_message = CarApiService.add_new_car(car=new_car)
        add_message = 'New car added'
        assert add_response_message == add_message, f'Problem with adding car:' \
                                                    f'\n{add_response_message}, must be\n{add_message}'

        # get just added car
        new_car = json.loads(new_car)
        model_parameter = {'model': new_car['model']}
        new_car_information = CarApiService.get_car(params=model_parameter)
        assert new_car_information == new_car, f'Incorrect car information for model:' \
                                               f'\n{new_car_information}, must be\n{new_car}'

        # update car
        new_model = f'Test{new_car["model"]}'
        new_model_parameter = {'model': new_model}
        update_car_response = CarApiService.update_car(
            model=new_car["model"], params=new_model_parameter)
        assert update_car_response['model'] == new_model, f'Incorrect car information for model after update:' \
                                                          f'\n{update_car_response}, must be\n{new_model}'

        # remove just added/updated car
        delete_response_message = CarApiService.delete_car(model=new_model)
        delete_message = f'Car model {new_model} removed'
        assert delete_response_message == delete_message, f'Problem with delete car:' \
                                                          f'\n{delete_response_message}, must be\n{delete_message}'

        # get removed car
        no_car_response = CarApiService.get_car(params=new_model_parameter)
        no_car_message = f'Car model {new_model} is absent in the list'
        assert no_car_response == no_car_message, f'Removed car presence in the list:' \
                                                  f'\n{no_car_response}, must be\n{no_car_message}'
示例#3
0
    def rent_all_car(self):
        car_list = CarApiService.get_car_list()
        car_status_available = {'status': 0}
        car_status_not_available = {'status': 1}

        for car in car_list:
            CarApiService.update_car(model=car.get('model'),
                                     params=car_status_available)
        yield
        for car in car_list:
            CarApiService.update_car(model=car.get('model'),
                                     params=car_status_not_available)
    def test_update_car_type(self, add_new_car):
        new_car_type = f'{self.car["type"]}{str(self.date)}'
        parameter_type = {'type': new_car_type}
        update_car_response = CarApiService.update_car(model=self.car["model"],
                                                       params=parameter_type)
        actual_car_type = update_car_response['type']

        assert actual_car_type == new_car_type, f'Incorrect car name after it was updated: actual\n{actual_car_type} but must be\n{new_car_type}'
    def test_update_car_model(self, add_new_car):
        new_car_model = f'{self.car["model"]}{str(self.date)}'
        parameter_model = {'model': new_car_model}
        update_car_response = CarApiService.update_car(model=self.car["model"],
                                                       params=parameter_model)
        actual_car_model = update_car_response['model']

        assert actual_car_model == new_car_model, f'Incorrect car name after it was updated: actual\n{actual_car_model} but must be\n{new_car_model}'
示例#6
0
    def test_add_new_car(self):
        model = f'Accord v{randint(0, 1000)}'
        # new_car = '{"name":"Honda", "model":"' + model + '", "type":"Sedan", "status":1}'
        new_car = Car('Honda', model, CarType.SEDAN,
                      CarStatus.AVAILABLE).get_car_info()
        add_response_message = CarApiService.add_new_car(car=new_car)

        assert add_response_message == ResponseMessages.NEW_CAR_ADDED, f'Problem with adding car:' \
                                                                       f'\n{add_response_message}, must be\n{ResponseMessages.NEW_CAR_ADDED}'
示例#7
0
 def test_get_car(self):
     car = CarApiService.get_car()
     assert re.match(
         r'\w+', car['name']) is not None, 'Incorrect parameter name in car'
     assert re.match(
         r'\w+',
         car['model']) is not None, 'Incorrect parameter model in car'
     assert re.match(
         r'\w+', car['type']) is not None, 'Incorrect parameter type in car'
     assert re.match(r'\d+', str(
         car['status'])) is not None, 'Incorrect parameter status in car'
示例#8
0
 def test_get_car_when_no_available(self, rent_all_car):
     actual_message = CarApiService.get_car()
     assert actual_message == ResponseMessages.NO_FREE_CAR_AVAILABLE, f'Incorrect message when all car are absent:' \
                                                                      f'\n{actual_message} but must be\n{ResponseMessages.NO_FREE_CAR_AVAILABLE}'
示例#9
0
    def test_get_car_by_any_parameters(self, parameter, message):
        expected_car_information = CarApiService.get_car(params=parameter)

        assert expected_car_information == message, f'Incorrect car information for model:' \
                                                    f'\n{expected_car_information}, must be\n{message}'
示例#10
0
    def test_get_car_by_model(self, model_name, message):
        expected_car_information = CarApiService.get_car(params=model_name)

        assert expected_car_information == message, f'Incorrect car information for model:' \
                                                    f'\n{expected_car_information}, must be\n{message}'
    def test_update_car_negative(self, params, add_new_car):
        update_car_response = CarApiService.update_car(model=self.car["model"],
                                                       params=params)

        assert update_car_response == self.car, 'Problem with negative cases'
    def test_update_type_for_none_exist_car(self):
        parameter_type = {'type': 'test'}
        update_car_response = CarApiService.update_car(model='test',
                                                       params=parameter_type)

        assert update_car_response == ResponseMessages.CAR_ABSENT_IN_THE_LIST, 'Problem with update none exist cat in the list'
示例#13
0
    def test_negative_cases(self, new_car, message):
        # new_car = '{"name":"Accord", "model":"Honda", "type":"Sedan", "status":1}'
        add_response_message = CarApiService.add_new_car(car=new_car)

        assert message == add_response_message, 'Incorrect error while server was adding new car'
示例#14
0
    def test_add_presented_car(self):
        new_car = '{"name":"Honda", "model":"Accord", "type":"Sedan", "status":1}'
        add_response_message = CarApiService.add_new_car(car=new_car)

        assert 'Car presence in the list:' in add_response_message, f'Problem with adding presented car:' \
                                                                    f'\n{add_response_message}'
 def test_delete_no_exist_car(self):
     delete_response_message = CarApiService.delete_car(model='RX350-')
     assert delete_response_message == ResponseMessages.CAR_ABSENT_IN_THE_LIST, f'Problem with delete car:' \
         f'\n{delete_response_message}, must be\n{ResponseMessages.CAR_ABSENT_IN_THE_LIST}'