<s> from __future__ import unicode_literals <EOL> from django . contrib . auth . models import User <EOL> from django . utils import six <EOL> from djblets . webapi . errors import PERMISSION_DENIED <EOL> from reviewboard . reviews . models import ScreenshotComment <EOL> from reviewboard . webapi . resources import resources <EOL> from reviewboard . webapi . tests . base import BaseWebAPITestCase <EOL> from reviewboard . webapi . tests . mimetypes import ( <EOL> screenshot_comment_item_mimetype , <EOL> screenshot_comment_list_mimetype ) <EOL> from reviewboard . webapi . tests . mixins import ( <EOL> BasicTestsMetaclass , <EOL> ReviewRequestChildItemMixin , <EOL> ReviewRequestChildListMixin ) <EOL> from reviewboard . webapi . tests . mixins_comment import ( <EOL> CommentItemMixin , <EOL> CommentListMixin ) <EOL> from reviewboard . webapi . tests . urls import ( <EOL> get_review_screenshot_comment_item_url , <EOL> get_review_screenshot_comment_list_url ) <EOL> class BaseTestCase ( BaseWebAPITestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def _create_screenshot_review_with_issue ( self , publish = False , <EOL> comment_text = None ) : <EOL> """<STR_LIT>""" <EOL> if not comment_text : <EOL> comment_text = '<STR_LIT>' <EOL> review_request = self . create_review_request ( publish = True , <EOL> submitter = self . user ) <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = self . user , <EOL> publish = publish ) <EOL> comment = self . create_screenshot_comment ( review , screenshot , <EOL> comment_text , <EOL> issue_opened = True ) <EOL> return comment , review , review_request <EOL> @ six . add_metaclass ( BasicTestsMetaclass ) <EOL> class ResourceListTests ( CommentListMixin , ReviewRequestChildListMixin , <EOL> BaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> sample_api_url = '<STR_LIT>' <EOL> resource = resources . review_screenshot_comment <EOL> def setup_review_request_child_test ( self , review_request ) : <EOL> self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = self . user ) <EOL> return ( get_review_screenshot_comment_list_url ( review ) , <EOL> screenshot_comment_list_mimetype ) <EOL> def compare_item ( self , item_rsp , comment ) : <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:id>' ] , comment . pk ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:text>' ] , comment . text ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:x>' ] , comment . x ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:y>' ] , comment . y ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:w>' ] , comment . w ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:h>' ] , comment . h ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT>' ] , comment . extra_data ) <EOL> if comment . rich_text : <EOL> self . assertEqual ( item_rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . assertEqual ( item_rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def setup_basic_get_test ( self , user , with_local_site , local_site_name , <EOL> populate_items ) : <EOL> review_request = self . create_review_request ( <EOL> with_local_site = with_local_site , <EOL> submitter = user , <EOL> publish = True ) <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = user ) <EOL> if populate_items : <EOL> items = [ self . create_screenshot_comment ( review , screenshot ) ] <EOL> else : <EOL> items = [ ] <EOL> return ( get_review_screenshot_comment_list_url ( review , <EOL> local_site_name ) , <EOL> screenshot_comment_list_mimetype , <EOL> items ) <EOL> def setup_basic_post_test ( self , user , with_local_site , local_site_name , <EOL> post_valid_data ) : <EOL> review_request = self . create_review_request ( <EOL> with_local_site = with_local_site , <EOL> submitter = user , <EOL> publish = True ) <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = user ) <EOL> return ( get_review_screenshot_comment_list_url ( review , <EOL> local_site_name ) , <EOL> screenshot_comment_item_mimetype , <EOL> { <EOL> '<STR_LIT>' : screenshot . pk , <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> '<STR_LIT:x>' : <NUM_LIT:2> , <EOL> '<STR_LIT:y>' : <NUM_LIT:2> , <EOL> '<STR_LIT:w>' : <NUM_LIT:10> , <EOL> '<STR_LIT:h>' : <NUM_LIT:10> , <EOL> } , <EOL> [ review , screenshot ] ) <EOL> def check_post_result ( self , user , rsp , review , screenshot ) : <EOL> comment = ScreenshotComment . objects . get ( pk = rsp [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] ) <EOL> self . compare_item ( rsp [ '<STR_LIT>' ] , comment ) <EOL> def test_post_with_issue ( self ) : <EOL> """<STR_LIT>""" <EOL> comment_text = "<STR_LIT>" <EOL> comment , review , review_request = self . _create_screenshot_review_with_issue ( <EOL> publish = False , comment_text = comment_text ) <EOL> rsp = self . api_get ( <EOL> get_review_screenshot_comment_list_url ( review ) , <EOL> expected_mimetype = screenshot_comment_list_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , rsp ) <EOL> self . assertEqual ( len ( rsp [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:text>' ] , comment_text ) <EOL> self . assertTrue ( rsp [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> @ six . add_metaclass ( BasicTestsMetaclass ) <EOL> class ResourceItemTests ( CommentItemMixin , ReviewRequestChildItemMixin , <EOL> BaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> sample_api_url = '<STR_LIT>' <EOL> resource = resources . review_screenshot_comment <EOL> def compare_item ( self , item_rsp , comment ) : <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:id>' ] , comment . pk ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:text>' ] , comment . text ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:x>' ] , comment . x ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:y>' ] , comment . y ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:w>' ] , comment . w ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:h>' ] , comment . h ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT>' ] , comment . extra_data ) <EOL> if comment . rich_text : <EOL> self . assertEqual ( item_rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> else : <EOL> self . assertEqual ( item_rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def setup_review_request_child_test ( self , review_request ) : <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = self . user ) <EOL> comment = self . create_screenshot_comment ( review , screenshot ) <EOL> return ( get_review_screenshot_comment_item_url ( review , comment . pk ) , <EOL> screenshot_comment_item_mimetype ) <EOL> def setup_basic_delete_test ( self , user , with_local_site , local_site_name ) : <EOL> review_request = self . create_review_request ( <EOL> with_local_site = with_local_site , <EOL> submitter = user , <EOL> publish = True ) <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = user ) <EOL> comment = self . create_screenshot_comment ( review , screenshot ) <EOL> return ( get_review_screenshot_comment_item_url ( review , comment . pk , <EOL> local_site_name ) , <EOL> [ comment , review ] ) <EOL> def check_delete_result ( self , user , comment , review ) : <EOL> self . assertNotIn ( comment , review . screenshot_comments . all ( ) ) <EOL> def test_delete_with_does_not_exist_error ( self ) : <EOL> """<STR_LIT>""" <EOL> review_request = self . create_review_request ( publish = True ) <EOL> self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = self . user ) <EOL> self . api_delete ( get_review_screenshot_comment_item_url ( review , <NUM_LIT> ) , <EOL> expected_status = <NUM_LIT> ) <EOL> def setup_basic_get_test ( self , user , with_local_site , local_site_name ) : <EOL> review_request = self . create_review_request ( <EOL> with_local_site = with_local_site , <EOL> submitter = user , <EOL> publish = True ) <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = user ) <EOL> comment = self . create_screenshot_comment ( review , screenshot ) <EOL> return ( get_review_screenshot_comment_item_url ( review , comment . pk , <EOL> local_site_name ) , <EOL> screenshot_comment_item_mimetype , <EOL> comment ) <EOL> def setup_basic_put_test ( self , user , with_local_site , local_site_name , <EOL> put_valid_data ) : <EOL> review_request = self . create_review_request ( <EOL> with_local_site = with_local_site , <EOL> submitter = user , <EOL> publish = True ) <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = user ) <EOL> comment = self . create_screenshot_comment ( review , screenshot ) <EOL> return ( get_review_screenshot_comment_item_url ( review , comment . pk , <EOL> local_site_name ) , <EOL> screenshot_comment_item_mimetype , <EOL> { '<STR_LIT:text>' : '<STR_LIT>' } , <EOL> comment , <EOL> [ ] ) <EOL> def check_put_result ( self , user , item_rsp , comment , * args ) : <EOL> comment = ScreenshotComment . objects . get ( pk = comment . pk ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( item_rsp [ '<STR_LIT:text>' ] , '<STR_LIT>' ) <EOL> self . compare_item ( item_rsp , comment ) <EOL> def test_put_with_issue ( self ) : <EOL> """<STR_LIT>""" <EOL> comment , review , review_request = self . _create_screenshot_review_with_issue ( ) <EOL> rsp = self . api_put ( <EOL> get_review_screenshot_comment_item_url ( review , comment . pk ) , <EOL> { '<STR_LIT>' : False } , <EOL> expected_mimetype = screenshot_comment_item_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertFalse ( rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def test_put_issue_status_before_publish ( self ) : <EOL> """<STR_LIT>""" <EOL> comment , review , review_request = self . _create_screenshot_review_with_issue ( ) <EOL> rsp = self . api_put ( <EOL> get_review_screenshot_comment_item_url ( review , comment . pk ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> expected_mimetype = screenshot_comment_item_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_put_issue_status_after_publish ( self ) : <EOL> """<STR_LIT>""" <EOL> comment , review , review_request = self . _create_screenshot_review_with_issue ( publish = True ) <EOL> rsp = self . api_put ( <EOL> get_review_screenshot_comment_item_url ( review , comment . pk ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> expected_mimetype = screenshot_comment_item_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_put_issue_status_by_issue_creator ( self ) : <EOL> """<STR_LIT>""" <EOL> comment , review , review_request = self . _create_screenshot_review_with_issue ( publish = True ) <EOL> review_request . submitter = User . objects . get ( username = '<STR_LIT>' ) <EOL> review_request . save ( ) <EOL> rsp = self . api_put ( <EOL> get_review_screenshot_comment_item_url ( review , comment . pk ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> expected_mimetype = screenshot_comment_item_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_put_issue_status_by_uninvolved_user ( self ) : <EOL> """<STR_LIT>""" <EOL> comment , review , review_request = self . _create_screenshot_review_with_issue ( publish = True ) <EOL> new_owner = User . objects . get ( username = '<STR_LIT>' ) <EOL> review_request . submitter = new_owner <EOL> review_request . save ( ) <EOL> review . user = new_owner <EOL> review . save ( ) <EOL> rsp = self . api_put ( <EOL> get_review_screenshot_comment_item_url ( review , comment . pk ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> expected_status = <NUM_LIT> ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT:code>' ] , PERMISSION_DENIED . code ) <EOL> def test_put_deleted_screenshot_comment_issue_status ( self ) : <EOL> """<STR_LIT>""" <EOL> comment_text = "<STR_LIT>" <EOL> x , y , w , h = ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> review_request = self . create_review_request ( publish = True , <EOL> submitter = self . user ) <EOL> screenshot = self . create_screenshot ( review_request ) <EOL> review = self . create_review ( review_request , user = self . user ) <EOL> comment = self . create_screenshot_comment ( review , screenshot , <EOL> comment_text , x , y , w , h , <EOL> issue_opened = True ) <EOL> rsp = self . api_put ( <EOL> get_review_screenshot_comment_item_url ( review , comment . pk ) , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> expected_mimetype = screenshot_comment_item_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> review . public = True <EOL> review . save ( ) <EOL> rsp = self . api_put ( <EOL> rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> expected_mimetype = screenshot_comment_item_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . _delete_screenshot ( review_request , screenshot ) <EOL> review_request . publish ( review_request . submitter ) <EOL> rsp = self . api_put ( <EOL> rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> expected_mimetype = screenshot_comment_item_mimetype ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT>' ] , '<STR_LIT>' ) </s>
