Пример #1
0
    def _load_grades(self):
        grades = []
        result = True, grades
        for grade_id in self.service_grades:
            loaded_grade = ServiceGrade.load_service_grade(grade_id)
            if loaded_grade is None:
                result = False, InvalidServiceGrade(status=HttpStatus.NOT_FOUND,
                                                    message="invalid grade id: " + str(grade_id),
                                                    params=[])
                break
            grades.append(loaded_grade)

        return result
Пример #2
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 = NewServiceGradeRequest.pre_deserialize(json_dict)
        if not result[0]:
            return result

        service_grade = ServiceGrade(name=json_dict['service_grade_name'])
        self.service_grade = service_grade
        result_pattern = self.post_deserialize()
        if not result_pattern[0]:
            return result_pattern
        return True, self
Пример #3
0
    def _add_service_grade(self):
        error = None
        loaded_grades_result = self._load_grades()
        if not loaded_grades_result[0]:
            return loaded_grades_result

        loaded_grades = loaded_grades_result[1]
        db.session.begin(subtransactions=True)
        try:
            for grade in loaded_grades:
                register_result = ServiceGrade.register_service_type(grade, self.service_type, db)
                if not register_result[0]:
                    error = register_result[1]
                    raise Exception()
        except:
            db.session.rollback()
            return False, error

        return True, SuccessServiceTypeRegistration(status=HttpStatus.OK,
                                                    message="Types registered in grades",
                                                    params=[])
Пример #4
0
    def _list_service_grades():
        list_returned = ServiceGrade.list_service_grades()
        if not list_returned[0]:
            return list_returned

        return True, list_returned[1]
Пример #5
0
    def _list_service_types(self):
        list_returned = ServiceGrade.list_service_types(self.service_grade_id)
        if not list_returned[0]:
            return list_returned

        return True, list_returned[1]
Пример #6
0
 def test_get_service_type_by_service_grade(self):
     list_returned = ServiceGrade.list_service_types(1)
     # list_returned[1][0][0].service_types[0].name
     list_returned[1].dictionary_creator()
     self.assertEqual(list_returned[1], list_returned[1])
Пример #7
0
 def test_get_service_grade(self):
     list_returned = ServiceGrade.list_service_grades()
     list_returned1 = ServiceGrade.list_service_grades()
     self.assertEqual(list_returned[1], list_returned[1])