(self, request, tenant_id, entity_id)
return b''
Create a check
Create a check
Create a check
def create_check(self, request, tenant_id, entity_id):
        """
        Create a check
        """
        content = request.content.read()
        postdata = json.loads(content.decode("utf-8"))
        entities = self._entity_cache_for_tenant(tenant_id).entities

        newcheck = None
        try:
            newcheck = create_check(self._session_store.clock, postdata)
        except TypeError:
            missing_key = _find_missing_required_key(
                Check, postdata, ['created_at', 'updated_at'])
            status = 400
            request.setResponseCode(status)
            self._audit('checks', request, tenant_id, status, content)
            return json.dumps({'type': 'badRequest',
                               'code': status,
                               'message': 'Validation error for key \'{0}\''.format(missing_key),
                               'details': 'Missing required key ({0})'.format(missing_key),
                               'txnId': '.fake.mimic.transaction.id.c-1111111.ts-123444444.v-12344frf'})

        try:
            entity = _get_entity(entities, entity_id)
            entity.checks[newcheck.id] = newcheck
        except ObjectDoesNotExist as e:
            request.setResponseCode(e.code)
            self._audit('checks', request, tenant_id, e.code, content)
            return json.dumps(e.to_json())

        status = 201
        request.setResponseCode(status)
        request.setHeader(b'location', base_uri_from_request(request).rstrip('/').encode('utf-8') +
                          request.path + b'/' + newcheck.id.encode('utf-8'))
        request.setHeader(b'x-object-id', newcheck.id.encode('utf-8'))
        request.setHeader(b'content-type', b'text/plain')
        self._audit('checks', request, tenant_id, status, content)
        return b''
def create_check ( self , request , tenant_id , entity_id ) : content = request . content . read ( ) postdata = json . loads ( content . decode ( "utf-8" ) ) entities = self . _entity_cache_for_tenant ( tenant_id ) . entities newcheck = None try : newcheck = create_check ( self . _session_store . clock , postdata ) except TypeError : missing_key = _find_missing_required_key ( Check , postdata , [ 'created_at' , 'updated_at' ] ) status = 400 request . setResponseCode ( status ) self . _audit ( 'checks' , request , tenant_id , status , content ) return json . dumps ( { 'type' : 'badRequest' , 'code' : status , 'message' : 'Validation error for key \'{0}\'' . format ( missing_key ) , 'details' : 'Missing required key ({0})' . format ( missing_key ) , 'txnId' : '.fake.mimic.transaction.id.c-1111111.ts-123444444.v-12344frf' } ) try : entity = _get_entity ( entities , entity_id ) entity . checks [ newcheck . id ] = newcheck except ObjectDoesNotExist as e : request . setResponseCode ( e . code ) self . _audit ( 'checks' , request , tenant_id , e . code , content ) return json . dumps ( e . to_json ( ) ) status = 201 request . setResponseCode ( status ) request . setHeader ( b'location' , base_uri_from_request ( request ) . rstrip ( '/' ) . encode ( 'utf-8' ) + request . path + b'/' + newcheck . id . encode ( 'utf-8' ) ) request . setHeader ( b'x-object-id' , newcheck . id . encode ( 'utf-8' ) ) request . setHeader ( b'content-type' , b'text/plain' ) self . _audit ( 'checks' , request , tenant_id , status , content ) return b''