<s> from __future__ import absolute_import <EOL> from rest_framework import serializers <EOL> from rest_framework . response import Response <EOL> from sentry . api . base import DocSection <EOL> from sentry . api . bases . project import ProjectEndpoint <EOL> from sentry . api . serializers import serialize <EOL> from sentry . models import Release , ReleaseFile <EOL> from sentry . utils . apidocs import scenario , attach_scenarios <EOL> @ scenario ( '<STR_LIT>' ) <EOL> def retrieve_file_scenario ( runner ) : <EOL> rf = runner . utils . create_release_file ( <EOL> project = runner . default_project , <EOL> release = runner . default_release , <EOL> path = '<STR_LIT>' , <EOL> contents = '<STR_LIT>' <EOL> ) <EOL> runner . request ( <EOL> method = '<STR_LIT:GET>' , <EOL> path = '<STR_LIT>' % ( <EOL> runner . org . slug , runner . default_project . slug , <EOL> runner . default_release . version , rf . id ) <EOL> ) <EOL> @ scenario ( '<STR_LIT>' ) <EOL> def update_file_scenario ( runner ) : <EOL> rf = runner . utils . create_release_file ( <EOL> project = runner . default_project , <EOL> release = runner . default_release , <EOL> path = '<STR_LIT>' , <EOL> contents = '<STR_LIT>' <EOL> ) <EOL> runner . request ( <EOL> method = '<STR_LIT>' , <EOL> path = '<STR_LIT>' % ( <EOL> runner . org . slug , runner . default_project . slug , <EOL> runner . default_release . version , rf . id ) , <EOL> data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' <EOL> } <EOL> ) <EOL> @ scenario ( '<STR_LIT>' ) <EOL> def delete_file_scenario ( runner ) : <EOL> rf = runner . utils . create_release_file ( <EOL> project = runner . default_project , <EOL> release = runner . default_release , <EOL> path = '<STR_LIT>' , <EOL> contents = '<STR_LIT>' <EOL> ) <EOL> runner . request ( <EOL> method = '<STR_LIT>' , <EOL> path = '<STR_LIT>' % ( <EOL> runner . org . slug , runner . default_project . slug , <EOL> runner . default_release . version , rf . id ) <EOL> ) <EOL> class ReleaseFileSerializer ( serializers . Serializer ) : <EOL> name = serializers . CharField ( max_length = <NUM_LIT:200> , required = True ) <EOL> class ReleaseFileDetailsEndpoint ( ProjectEndpoint ) : <EOL> doc_section = DocSection . RELEASES <EOL> @ attach_scenarios ( [ retrieve_file_scenario ] ) <EOL> def get ( self , request , project , version , file_id ) : <EOL> """<STR_LIT>""" <EOL> release = Release . objects . get ( <EOL> project = project , <EOL> version = version , <EOL> ) <EOL> releasefile = ReleaseFile . objects . get ( <EOL> release = release , <EOL> id = file_id , <EOL> ) <EOL> return Response ( serialize ( releasefile , request . user ) ) <EOL> @ attach_scenarios ( [ update_file_scenario ] ) <EOL> def put ( self , request , project , version , file_id ) : <EOL> """<STR_LIT>""" <EOL> release = Release . objects . get ( <EOL> project = project , <EOL> version = version , <EOL> ) <EOL> releasefile = ReleaseFile . objects . get ( <EOL> release = release , <EOL> id = file_id , <EOL> ) <EOL> serializer = ReleaseFileSerializer ( data = request . DATA ) <EOL> if not serializer . is_valid ( ) : <EOL> return Response ( serializer . errors , status = <NUM_LIT> ) <EOL> result = serializer . object <EOL> releasefile . update ( <EOL> name = result [ '<STR_LIT:name>' ] , <EOL> ) <EOL> return Response ( serialize ( releasefile , request . user ) ) <EOL> @ attach_scenarios ( [ delete_file_scenario ] ) <EOL> def delete ( self , request , project , version , file_id ) : <EOL> """<STR_LIT>""" <EOL> release = Release . objects . get ( <EOL> project = project , <EOL> version = version , <EOL> ) <EOL> releasefile = ReleaseFile . objects . get ( <EOL> release = release , <EOL> id = file_id , <EOL> ) <EOL> file = releasefile . file <EOL> releasefile . delete ( ) <EOL> file . delete ( ) <EOL> return Response ( status = <NUM_LIT> ) </s>
