def delete_goods(self, user_id, goods_id): goods = self.get_goods(goods_id) if goods.user_id == user_id: requests = self.get_requests(goods_id=goods.id) for request in requests: if request.status.value == 1: request.status = Status(3) self._delete(goods)
def test_create_request(self): company_id = self.create_company() administrator = self.api.get_user(nickname=TEST_USER_NICKNAME) car_id = self.create_car(administrator.nickname, company_id) goods_id = self.create_goods(administrator.id) user_id = self.create_user(nickname="user") request_car_id = self.create_request(user_id, car_id=car_id) request_goods_id = self.create_request(user_id, goods_id=goods_id) requests = self.api.get_requests(user_id) self.assertEqual(len(requests), 2) request_car = self.api.get_request(request_car_id) request_goods = self.api.get_request(request_goods_id) self.assertTrue(request_car) self.assertTrue(request_goods) self.assertEqual(request_car.status, Status(1)) self.assertEqual(request_goods.status, Status(1))
def test_delete_goods(self): administrator = self.api.get_user(user_id=self.create_user()) goods_id = self.create_goods(administrator.id) user_id = self.create_user(nickname="user") self.create_request(user_id, goods_id=goods_id) self.api.delete_goods(administrator.id, goods_id) goods = self.api.get_goods(goods_id) self.assertIsNone(goods) requests = self.api.get_request(goods_id=goods_id) self.assertEqual(requests.status, Status(3))
def test_delete_car(self): company_id = self.create_company() administrator = self.api.get_user(nickname=TEST_USER_NICKNAME) car_id = self.create_car(administrator.nickname, company_id) user_id = self.create_user(nickname="user") self.create_request(user_id, car_id=car_id) self.api.delete_car(administrator.nickname, company_id, car_id) cars = self.api.get_cars(company_id=company_id) self.assertEqual(len(cars), 0) requests = self.api.get_request(car_id=car_id) self.assertEqual(requests.status, Status(3))
def reject_request(self, company_id, administrator_nickname, car_id, request_id, log=True): request = self.get_request(request_id=request_id) request.status = Status(3) request.date = datetime.datetime.now() + datetime.timedelta(hours=3) if log: text_log = REJECT_REQUEST self.create_log(company_id, administrator_nickname, text_log, "машины", car_id) self._session.commit()
def delete_car(self, administrator_nickname, company_id, car_id): administrator = self.get_user(nickname=administrator_nickname) company = self.get_company(company_id) car = self.get_car(car_id) if administrator.role.value > 1 and administrator.nickname == company.nickname: requests = self.get_requests(car_id=car.id) for request in requests: if request.status.value == 1: request.status = Status(3) self._delete(car) text_log = REMOVE_CAR self.create_log(administrator.company_id, administrator.nickname, text_log)