<s> from __future__ import unicode_literals <EOL> from django . utils import six <EOL> from djblets . testing . decorators import add_fixtures <EOL> from djblets . webapi . errors import DOES_NOT_EXIST , PERMISSION_DENIED <EOL> from reviewboard . webapi . resources import resources <EOL> from reviewboard . webapi . tests . base import BaseWebAPITestCase <EOL> from reviewboard . webapi . tests . mimetypes import ( <EOL> watched_review_request_item_mimetype , <EOL> watched_review_request_list_mimetype ) <EOL> from reviewboard . webapi . tests . mixins import BasicTestsMetaclass <EOL> from reviewboard . webapi . tests . urls import ( <EOL> get_review_request_item_url , <EOL> get_watched_review_request_item_url , <EOL> get_watched_review_request_list_url ) <EOL> @ six . add_metaclass ( BasicTestsMetaclass ) <EOL> class ResourceListTests ( BaseWebAPITestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> test_http_methods = ( '<STR_LIT:GET>' , '<STR_LIT:POST>' ) <EOL> sample_api_url = '<STR_LIT>' <EOL> resource = resources . watched_review_request <EOL> def compare_item ( self , item_rsp , obj ) : <EOL> watched_rsp = item_rsp [ '<STR_LIT>' ] <EOL> self . assertEqual ( watched_rsp [ '<STR_LIT:id>' ] , obj . display_id ) <EOL> self . assertEqual ( watched_rsp [ '<STR_LIT>' ] , obj . summary ) <EOL> def setup_basic_get_test ( self , user , with_local_site , local_site_name , <EOL> populate_items ) : <EOL> if populate_items : <EOL> review_request = self . create_review_request ( <EOL> with_local_site = with_local_site , <EOL> publish = True ) <EOL> profile = user . get_profile ( ) <EOL> profile . starred_review_requests . add ( review_request ) <EOL> items = [ review_request ] <EOL> else : <EOL> items = [ ] <EOL> return ( get_watched_review_request_list_url ( user . username , <EOL> local_site_name ) , <EOL> watched_review_request_list_mimetype , <EOL> items ) <EOL> @ add_fixtures ( [ '<STR_LIT>' ] ) <EOL> def test_get_with_site_does_not_exist ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _login_user ( local_site = True ) <EOL> rsp = self . api_get ( <EOL> get_watched_review_request_list_url ( self . user . username , <EOL> self . local_site_name ) , <EOL> expected_status = <NUM_LIT> ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT:code>' ] , DOES_NOT_EXIST . code ) <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> publish = True ) <EOL> if post_valid_data : <EOL> post_data = { <EOL> '<STR_LIT>' : review_request . display_id , <EOL> } <EOL> else : <EOL> post_data = { } <EOL> return ( get_watched_review_request_list_url ( user . username , <EOL> local_site_name ) , <EOL> watched_review_request_item_mimetype , <EOL> post_data , <EOL> [ review_request ] ) <EOL> def check_post_result ( self , user , rsp , review_request ) : <EOL> profile = user . get_profile ( ) <EOL> self . assertTrue ( review_request in <EOL> profile . starred_review_requests . all ( ) ) <EOL> def test_post_with_does_not_exist_error ( self ) : <EOL> """<STR_LIT>""" <EOL> rsp = self . api_post ( <EOL> get_watched_review_request_list_url ( self . user . username ) , <EOL> { '<STR_LIT>' : <NUM_LIT> } , <EOL> expected_status = <NUM_LIT> ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT:code>' ] , DOES_NOT_EXIST . code ) <EOL> @ add_fixtures ( [ '<STR_LIT>' ] ) <EOL> def test_post_with_site_does_not_exist_error ( self ) : <EOL> """<STR_LIT>""" <EOL> user = self . _login_user ( local_site = True ) <EOL> rsp = self . api_post ( <EOL> get_watched_review_request_list_url ( user . username , <EOL> self . local_site_name ) , <EOL> { '<STR_LIT>' : <NUM_LIT:10> } , <EOL> expected_status = <NUM_LIT> ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT:code>' ] , DOES_NOT_EXIST . code ) <EOL> @ six . add_metaclass ( BasicTestsMetaclass ) <EOL> class ResourceItemTests ( BaseWebAPITestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> test_http_methods = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sample_api_url = '<STR_LIT>' <EOL> resource = resources . watched_review_request <EOL> def setup_http_not_allowed_item_test ( self , user ) : <EOL> return get_watched_review_request_item_url ( user . username , <NUM_LIT:1> ) <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> publish = True ) <EOL> profile = user . get_profile ( ) <EOL> profile . starred_review_requests . add ( review_request ) <EOL> return ( get_watched_review_request_item_url ( user . username , <EOL> review_request . display_id , <EOL> local_site_name ) , <EOL> [ profile , review_request ] ) <EOL> def check_delete_result ( self , user , profile , review_request ) : <EOL> self . assertFalse ( review_request in <EOL> profile . starred_review_requests . all ( ) ) <EOL> def test_delete_with_does_not_exist_error ( self ) : <EOL> """<STR_LIT>""" <EOL> rsp = self . api_delete ( <EOL> get_watched_review_request_item_url ( self . user . username , <NUM_LIT> ) , <EOL> expected_status = <NUM_LIT> ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( rsp [ '<STR_LIT>' ] [ '<STR_LIT:code>' ] , DOES_NOT_EXIST . code ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> review_request = self . create_review_request ( publish = True ) <EOL> profile = self . user . get_profile ( ) <EOL> profile . starred_review_requests . add ( review_request ) <EOL> expected_url = ( self . base_url + <EOL> get_review_request_item_url ( review_request . display_id ) ) <EOL> self . api_get ( <EOL> get_watched_review_request_item_url ( self . user . username , <EOL> review_request . display_id ) , <EOL> expected_status = <NUM_LIT> , <EOL> expected_headers = { <EOL> '<STR_LIT>' : expected_url , <EOL> } ) <EOL> @ add_fixtures ( [ '<STR_LIT>' ] ) <EOL> def test_get_with_site ( self ) : <EOL> """<STR_LIT>""" <EOL> user = self . _login_user ( local_site = True ) <EOL> review_request = self . create_review_request ( with_local_site = True , <EOL> publish = True ) <EOL> profile = user . get_profile ( ) <EOL> profile . starred_review_requests . add ( review_request ) <EOL> expected_url = ( self . base_url + <EOL> get_review_request_item_url ( review_request . display_id , <EOL> self . local_site_name ) ) <EOL> self . api_get ( <EOL> get_watched_review_request_item_url ( user . username , <EOL> review_request . display_id , <EOL> self . local_site_name ) , <EOL> expected_status = <NUM_LIT> , <EOL> expected_headers = { <EOL> '<STR_LIT>' : expected_url , <EOL> } ) <EOL> @ add_fixtures ( [ '<STR_LIT>' ] ) <EOL> def test_get_with_site_no_access ( self ) : <EOL> """<STR_LIT>""" <EOL> review_request = self . create_review_request ( with_local_site = True , <EOL> publish = True ) <EOL> profile = self . user . get_profile ( ) <EOL> profile . starred_review_requests . add ( review_request ) <EOL> rsp = self . api_get ( <EOL> get_watched_review_request_item_url ( self . user . username , <EOL> review_request . display_id , <EOL> self . local_site_name ) , <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 ) </s>
