Exemplo n.º 1
0
 def put(self, authcontext, entity_id):
     """
     updates an omartestpy2 item
     """
     try:
         model = omartestpy2ModelPut(**request.get_json())
         context = authcontext['context']
         omartestpy2Service(context).update(model, entity_id)
         return EMPTY, 204
     except omartestpy2ServiceError 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
Exemplo n.º 2
0
 def delete(self, authcontext, entity_id):
     """
     Delete omartestpy2 item
     """
     try:
         omartestpy2Service(authcontext['context']).delete(entity_id)
         return EMPTY, 204
     except omartestpy2ServiceError 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
Exemplo n.º 3
0
    def post(self, authcontext):
        """
        Adds a omartestpy2 item.
        """
        try:
            model = omartestpy2ModelPost(**request.get_json())
            result = omartestpy2Service(authcontext['context'])\
                .save(model)

            response = omartestpy2ModelPostResponse()
            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
Exemplo n.º 4
0
 def get(self, authcontext):
     """
     gets all omartestpy2 items
     """
     LOG.debug("Serving  Get all request")
     list = omartestpy2Service(authcontext['context']).get_all()
     # normalize the name for 'id'
     return list, 200
 def setUp(self):
     context = AuthContext("23432523452345", "tenantname",
                           "987656789765670", "orgname", "1009009009988",
                           "username", False)
     self.omartestpy2Service = omartestpy2Service(context)
     self.omartestpy2_api_model = self.createTestModelData()
     self.omartestpy2_data = self.setupDatabaseRecords(self.omartestpy2_api_model)
     self.omartestpy2_someoneelses = \
         self.setupDatabaseRecords(self.omartestpy2_api_model)
     self.omartestpy2_someoneelses.tenantId = "123432523452345"
     with patch('mongomock.write_concern.WriteConcern.__init__',
                return_value=None):
         self.omartestpy2_someoneelses.save()
     self.omartestpy2_api_model_put_description \
         = self.createTestModelDataDescription()
     self.test_data_collection = [self.omartestpy2_data]
Exemplo n.º 6
0
 def get(self, authcontext, entity_id):
     """gets an omartestpy2 item that omar has changed
     """
     try:
         LOG.debug("Get details by id %s ", entity_id)
         data = omartestpy2Service(authcontext['context'])\
             .find_by_id(entity_id)
         clean_nonserializable_attributes(data)
     except omartestpy2ServiceError 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 omartestpy2Model(**data), 200