Beispiel #1
0
    def deserialize(self):
        if not type(self.json_obj) is dict:
            json_dict = Serializable.convert_input_to_dict(self.json_obj)
        else:
            json_dict = self.json_obj
        result = NewCarRequest.pre_deserialize(json_dict)
        if result[0]:
            car_info = json_dict[Keys.CAR_INFO]
            vin_number = ''
            if Keys.VIN_NUMBER not in car_info:
                vin_number = json_dict[Keys.CAR_INFO][Keys.VIN_NUMBER]

            plate_number = json_dict[Keys.CAR_INFO][Keys.PLATE_NUMBER]
            auto_type = json_dict[Keys.CAR_INFO][Keys.AUTO_TYPE]
            color = json_dict[Keys.CAR_INFO][Keys.CAR_COLOR]
            auto_model = json_dict[Keys.CAR_INFO][Keys.AUTO_MODEL]
            current_kilometer = json_dict[Keys.CAR_INFO][
                Keys.CURRENT_KILOMETER]
            car = Car(vin_number=vin_number,
                      plate_number=plate_number,
                      auto_type_id=auto_type,
                      color_id=color,
                      current_kilometer=current_kilometer,
                      auto_model_id=auto_model)
            self.car_owner = json_dict[Keys.CAR_OWNER]

            self.car = car
            result_pattern = self.post_deserialize()
            if not result_pattern[0]:
                return result_pattern
            return True, self
        return result
Beispiel #2
0
def init_cars():
    cars = [{
        "vin_number": "iRFC93R21SN497640",
        "plate_number": "70ط749-33"
    }, {
        "vin_number": "iRFC93R21SN497641",
        "plate_number": "71ط749-33"
    }, {
        "vin_number": "iRFC93R21SN497643",
        "plate_number": "72ط749-33"
    }, {
        "vin_number": "iRFC93R21SN497644",
        "plate_number": "73ط749-33"
    }, {
        "vin_number": "iRFC93R21SN497645",
        "plate_number": "74ط749-33"
    }]

    car_for_car_owner = []
    for car in cars:
        ccar = Car(vin_number=car['vin_number'],
                   plate_number=car['plate_number'],
                   color_id=1,
                   current_kilometer=10000,
                   auto_type_id=1,
                   auto_model_id=1)
        car_for_car_owner.append(ccar)

    CarOwner.query.filter(
        CarOwner.name == "Amish").first().cars.extend(car_for_car_owner)

    db.session.commit()
Beispiel #3
0
 def request_notification(car_problems, business_owner_id, car_id, job_id,
                          time):
     business_owner = User.load_user_reg_id(business_owner_id)
     car = Car.load_car(car_id)
     message = IWSAnnouncement.message_creator(car.name, car_problems, time)
     service_types = IWSAnnouncement.service_type_creator(car_problems)
     data = {
         'info': {
             Keys.CAR_INFO: {
                 Keys.NAME: car.name
             },
             Keys.PROBLEM: {
                 Keys.GRADE:
                 car_problems[0].services_definition.service_grade,
                 Keys.TYPES: service_types,
                 Keys.JOB_ID: job_id,
             },
             Keys.USER_TYPE: Keys.NEW_JOB_REQUEST,
         },
         Keys.ACTIONS: Result.language.ACCEPT_DENY_ACTIONS,
         Keys.MESSAGE: message,
         Keys.TITLE: Result.language.NEW_REQUEST_NOTIFICATION_TITLE,
         Keys.BUSINESS_OWNER: {
             Keys.NAME: business_owner.name,
             Keys.REG_ID: business_owner.reg_id
         }
     }
     response = PushNotification.push(
         data[Keys.BUSINESS_OWNER][Keys.REG_ID], data)
     return response
Beispiel #4
0
 def _push_notification_done_payment(self):
     loaded_car_result = Car.find(id=self.job.car_id)
     loaded_business_owner_result = User.find(id=self.job.business_owner_id)
     if not loaded_car_result[0] or not loaded_business_owner_result[0]:
         logger.warn('push notification failed')
         return
     business_owner = loaded_business_owner_result[1][0]
     car = loaded_car_result[1][0]
     IWSAnnouncement.send_payment_result_notification(car, business_owner)
Beispiel #5
0
    def _is_car_existence(self):
        result = Car.find(id=self.car.id, deleted=False)
        if not result[0]:
            return result

        if len(result[1]) == 0:
            params = {"car_id": self.car.id}
            fail = CarNotExist(status=400,
                               message=MessagesKeys.CAR_NOT_EXIST,
                               params=params)
            return False, fail

        return True, result[1][0]
Beispiel #6
0
    def _is_registered_before(self):
        result = Car.find(plate_number=self.car_info.car.plate_number)
        if not result[0]:
            return result

        if len(result[1]) > 0:
            params = {Keys.PLATE_NUMBER: self.car_info.car.plate_number}
            fail = CarRegisteredBefore(
                status=404,
                message=MessagesKeys.CAR_REGISTERED_BEFORE,
                params=params)
            return False, fail

        return True,
Beispiel #7
0
 def cancel_job(job):
     business_owner = User.load_user_reg_id(job.business_owner_id)
     car = Car.load_car(job.car_id)
     info = {
         Keys.USER_TYPE: Keys.CANCEL_JOB,
         Keys.CAR_INFO: {
             Keys.NAME: car.name
         },
         Keys.BUSINESS_OWNER: {
             Keys.NAME: business_owner.name,
             Keys.REG_ID: business_owner.reg_id
         }
     }
     response = PushNotification.push(
         [info[Keys.BUSINESS_OWNER][Keys.REG_ID]], info)
     return response
Beispiel #8
0
    def test_give_payment_list(self):
        data = {"car_owner_id": 6, "car_id": 2}
        data1 = json.dumps(data)

        ccar = Car(vin_number="iRFC93R21SN497647",
                   plate_number="77ط749-33",
                   auto_type_id=1)
        User.query.filter(User.name == "MahD").first().cars.append(ccar)
        db.session.commit()

        with self.app as client:
            with client.session_transaction() as sess:
                sess['user_id'] = 6
            response = self.make_post_request(data1)
            dct = json.loads(response.data)
            self.assertEqual(dct[Keys.STATUS], 200)
            self.assertEqual(dct[Keys.MESSAGE], Result.language.SUCCESS_LIST)
 def deserialize(self):
     if not type(self.json_obj) is dict:
         json_dict = Serializable.convert_input_to_dict(self.json_obj)
     else:
         json_dict = self.json_obj
     result = UpdateCarRequest.pre_deserialize(json_dict)
     if result[0]:
         vin_number = json_dict['car_info']['vin_number']
         plate_number = json_dict['car_info']['plate_number']
         auto_type = json_dict['car_info']['auto_type']
         car_id = json_dict['car_id']
         car = Car(
             id=car_id,
             vin_number=vin_number,
             plate_number=plate_number,
             auto_type_id=auto_type,
             car_owner_id=SessionManager.retrieve_session_value_by_key(
                 Keys.USER_ID))
         self.car = car
         result_pattern = self.post_deserialize()
         if not result_pattern[0]:
             return result_pattern
         return True, self
     return result
Beispiel #10
0
 def _find_all(self):
     return Car.find_all(user_id=self.user_id, deleted=False)
Beispiel #11
0
 def _delete_car(self):
     return Car.delete_by_id(db, self.car_info.car_id)