예제 #1
0
    def _update_location(self):

        try:
            BusinessOwner.update_lng_lat(self.business_owner.id, self.business_owner.lng, self.business_owner.lat, db)
            success = SuccessUpdate(status=200, message=MessagesKeys.SUCCESS_UPDATE)
            result = True, success
        except InvalidRequestError as error:
            result = db_error_message(logger)
            db.session.rollback()

        except:
            result = db_error_message(logger)
            db.session.rollback()
        return result
예제 #2
0
    def test_insert_job_b_o_calendar_time_not_exist_1(self):

        data = {
            Keys.BUSINESS_OWNER_ID: 1,
            Keys.START_TIME: '2019-04-22 11:00:00',
            Keys.FINISH_TIME: '2019-04-22 14:30:00'
        }

        json_obj = json.dumps(data)
        aaa = BusinessOwner.find(id=data[Keys.BUSINESS_OWNER_ID])
        if aaa[0]:
            self.business_owner = aaa[1][0]
            calendar = Calendar(start_time='2019-04-22 12:00:00', finish_time='2019-04-22 14:00:00',
                                business_owner_id=data[Keys.BUSINESS_OWNER_ID])
            result = calendar.add(db, calendar)

            self.business_owner.calendars.extend([calendar])
        with self.app as client:
            with client.session_transaction() as sess:
                sess['user_id'] = 1
            response = self.make_post_request(json_obj)
            dct = json.loads(response.data)
            self.assertEqual(dct[Keys.STATUS], 404)
            # self.assertEqual(dct[Keys.PARAMS], None)
            self.assertEqual(Result.language.BUSINESS_OWNER_IS_BUSY, dct[Keys.MESSAGE])
예제 #3
0
    def test_insert_job_b_o_calendar_exist_busy(self):
        data = {
            Keys.BUSINESS_OWNER_ID: 1,
            Keys.START_TIME: '2019-04-22 12:56:00',
            Keys.FINISH_TIME: '2019-04-22 14:56:00'
            # 03/21/2018 @ 9-11:00am (UTC)
            # "job": "تعویض روغن",
        }
        json_obj = json.dumps(data)
        # data = {id: data["business_owner_id"]}

        business_owner = BusinessOwner.find(id=data[Keys.BUSINESS_OWNER_ID])
        if business_owner[0]:
            self.business_owner = business_owner[1][0]
            calendar = Calendar(start_time=data[Keys.START_TIME], finish_time=data[Keys.FINISH_TIME],
                                business_owner_id=data[Keys.BUSINESS_OWNER_ID])
            result = calendar.add(db, calendar)
            self.business_owner.calendars.extend([calendar])

        with self.app as client:
            with client.session_transaction() as sess:
                sess['user_id'] = 1
            response = self.make_post_request(json_obj)
            dct = json.loads(response.data)
            self.assertEqual(dct[Keys.STATUS], 404)
            self.assertEqual(dct[Keys.MESSAGE], Result.language.BUSINESS_OWNER_IS_BUSY)
            self.assertEqual(dct[Keys.PARAMS], None)
예제 #4
0
    def _is_existence(self):
        ok, result = BusinessOwner.find(id=self.business_owner.id)
        if not ok:
            return False, result

        if len(result) == 0:
            return False, UserNotFound(status=404, message=MessagesKeys.ID_IS_NOT_IN_DB, params=None)

        return True, result[0]
예제 #5
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 = ListJobsByStatusRequest.pre_deserialize(json_dict)
     if not result[0]:
         return result
     self.business_owner = BusinessOwner(id=SessionManager.retrieve_session_value_by_key(Keys.USER_ID))
     self.status = json_dict[Keys.STATUS]
     result_pattern = self.post_deserialize()
     if not result_pattern[0]:
         return result_pattern
     return True, self
 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 = BusinessOwnerUpdateLocationRequest.pre_deserialize(json_dict)
     if not result[0]:
         return result
     self.business_owner = BusinessOwner(
         id=json_dict[Keys.BUSINESS_OWNER_ID],
         lat=json_dict[Keys.LATITUDE],
         lng=json_dict[Keys.LONGITUDE])
     result_pattern = self.post_deserialize()
     if not result_pattern[0]:
         return result_pattern
     return True, self