def post(self, authcontext):
        """
        Adds a kitten33 item.
        """
        try:
            model = kitten33ModelPost(**request.get_json())
            result = kitten33Service(authcontext['context'])\
                .save(model)

            response = kitten33ModelPostResponse()
            for key in response.properties:
                response[key] = result[key]

            return (response, 201,
                    {'Location': request.path + '/' + str(response['id'])})
        except ValueError as e:
            LOG.error(e)
            return ErrorModel(**{'error_code': str(e.errors.value),
                                 'error_message': e.args[0]}), 400
        except ExtraValueException as e:
            LOG.error(e)
            return ErrorModel(**{'error_code': '400',
                                 'error_message': "{} is not valid input".
                              format(e.args[0])}), 400
        except Exception as ex:
            LOG.error(ex)
            return ErrorModel(**{'error_code': '500',
                                 'error_message': ex.args[0]}), 500
 def get(self, authcontext):
     """
     gets all kitten33 items
     """
     LOG.debug("Serving  Get all request")
     list = kitten33Service(authcontext['context']).get_all()
     # normalize the name for 'id'
     return list, 200
 def delete(self, authcontext, entity_id):
     """
     Delete kitten33 item
     """
     try:
         kitten33Service(authcontext['context']).delete(entity_id)
         return EMPTY, 204
     except kitten33ServiceError as e:
         LOG.error(e)
         return ErrorModel(**{'error_code': str(e.errors.value),
                              'error_message': e.args[0]}), e.errors
     except ValueError as e:
         LOG.error(e)
         return ErrorModel(**{'error_code': '400',
                              'error_message': e.args[0]}), 400
     except Exception as ex:
         LOG.error(ex)
         return ErrorModel(**{'error_code': '500',
                              'error_message': ex.args[0]}), 500
 def put(self, authcontext, entity_id):
     """
     updates an kitten33 item
     """
     try:
         model = kitten33ModelPut(**request.get_json())
         context = authcontext['context']
         kitten33Service(context).update(model, entity_id)
         return EMPTY, 204
     except kitten33ServiceError as e:
         LOG.error(e)
         return ErrorModel(**{'error_code': str(e.errors.value),
                              'error_message': e.args[0]}), e.errors
     except ValueError as e:
         LOG.error(e)
         return ErrorModel(**{'error_code': '400',
                              'error_message': e.args[0]}), 400
     except Exception as ex:
         LOG.error(ex)
         return ErrorModel(**{'error_code': '500',
                              'error_message': ex.args[0]}), 500
Exemple #5
0
 def setUp(self):
     context = AuthContext("23432523452345", "tenantname",
                           "987656789765670", "orgname", "1009009009988",
                           "username", False)
     self.kitten33Service = kitten33Service(context)
     self.kitten33_api_model = self.createTestModelData()
     self.kitten33_data = self.setupDatabaseRecords(self.kitten33_api_model)
     self.kitten33_someoneelses = \
         self.setupDatabaseRecords(self.kitten33_api_model)
     self.kitten33_someoneelses.tenantId = "123432523452345"
     with patch('mongomock.write_concern.WriteConcern.__init__',
                return_value=None):
         self.kitten33_someoneelses.save()
     self.kitten33_api_model_put_description \
         = self.createTestModelDataDescription()
     self.test_data_collection = [self.kitten33_data]
 def get(self, authcontext, entity_id):
     """gets an kitten33 item that omar has changed
     """
     try:
         LOG.debug("Get details by id %s ", entity_id)
         data = kitten33Service(authcontext['context'])\
             .find_by_id(entity_id)
         clean_nonserializable_attributes(data)
     except kitten33ServiceError as e:
         LOG.error(e)
         return ErrorModel(**{'error_code': str(e.errors.value),
                              'error_message': e.args[0]}), e.errors
     except ValueError as e:
         LOG.error(e)
         return ErrorModel(**{'error_code': '400',
                              'error_message': e.args[0]}), 400
     return kitten33Model(**data), 200