<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> import unittest <EOL> import phldef_conduit <EOL> import phlsys_conduit <EOL> import phlcon_differential <EOL> _COMMIT_MESSAGE_FORMAT = """<STR_LIT>""" . strip ( ) <EOL> class Test ( unittest . TestCase ) : <EOL> def __init__ ( self , data ) : <EOL> super ( Test , self ) . __init__ ( data ) <EOL> self . conduit = None <EOL> self . reviewerConduit = None <EOL> self . phabConduit = None <EOL> self . test_data = None <EOL> def setUp ( self ) : <EOL> self . test_data = phldef_conduit <EOL> self . conduit = phlsys_conduit . Conduit ( <EOL> self . test_data . TEST_URI , <EOL> self . test_data . ALICE . user , <EOL> self . test_data . ALICE . certificate ) <EOL> self . reviewerConduit = phlsys_conduit . Conduit ( <EOL> self . test_data . TEST_URI , <EOL> self . test_data . BOB . user , <EOL> self . test_data . BOB . certificate ) <EOL> self . phabConduit = phlsys_conduit . Conduit ( <EOL> self . test_data . TEST_URI , <EOL> self . test_data . PHAB . user , <EOL> self . test_data . PHAB . certificate ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_A_Breathing ( self ) : <EOL> rev_id = self . _createNonEmptyRevision ( '<STR_LIT>' ) <EOL> conduit = self . phabConduit <EOL> phlcon_differential . create_inline_comment ( <EOL> conduit , rev_id , '<STR_LIT>' , <NUM_LIT:2> , '<STR_LIT>' ) <EOL> phlcon_differential . create_inline_comment ( <EOL> conduit , rev_id , '<STR_LIT>' , <NUM_LIT:3> , '<STR_LIT>' ) <EOL> phlcon_differential . create_comment ( <EOL> conduit , rev_id , '<STR_LIT>' , attach_inlines = True ) <EOL> def test_B_AcceptedPersistsWhenUpdated ( self ) : <EOL> conduit = self . phabConduit <EOL> author = phldef_conduit . ALICE . user <EOL> reviewer = phldef_conduit . BOB . user <EOL> with phlsys_conduit . act_as_user_context ( conduit , author ) : <EOL> revision = phlcon_differential . create_empty_revision ( conduit ) <EOL> with phlsys_conduit . act_as_user_context ( conduit , reviewer ) : <EOL> phlcon_differential . create_comment ( <EOL> conduit , <EOL> revision , <EOL> action = phlcon_differential . Action . accept ) <EOL> with phlsys_conduit . act_as_user_context ( conduit , author ) : <EOL> phlcon_differential . update_revision_empty ( conduit , revision ) <EOL> self . assertEqual ( <EOL> phlcon_differential . get_revision_status ( conduit , revision ) , <EOL> phlcon_differential . ReviewStates . accepted ) <EOL> def test_C_CantUpdateClosedReviews ( self ) : <EOL> conduit = self . phabConduit <EOL> author = phldef_conduit . ALICE . user <EOL> reviewer = phldef_conduit . BOB . user <EOL> with phlsys_conduit . act_as_user_context ( conduit , author ) : <EOL> revision = phlcon_differential . create_empty_revision ( conduit ) <EOL> with phlsys_conduit . act_as_user_context ( conduit , reviewer ) : <EOL> phlcon_differential . create_comment ( <EOL> conduit , <EOL> revision , <EOL> action = phlcon_differential . Action . accept ) <EOL> with phlsys_conduit . act_as_user_context ( conduit , author ) : <EOL> phlcon_differential . create_comment ( <EOL> conduit , <EOL> revision , <EOL> action = phlcon_differential . Action . close ) <EOL> self . assertRaises ( <EOL> phlcon_differential . UpdateClosedRevisionError , <EOL> phlcon_differential . update_revision_empty , <EOL> conduit , <EOL> revision ) <EOL> phlcon_differential . close ( conduit , revision ) <EOL> def _make_commit_message ( self , title , summary , test_plan , reviewer_list ) : <EOL> return _COMMIT_MESSAGE_FORMAT . format ( <EOL> title = title , <EOL> summary = summary , <EOL> test_plan = test_plan , <EOL> reviewers = "<STR_LIT:U+0020>" . join ( reviewer_list ) ) <EOL> def test_D_DistinguishParseErrors ( self ) : <EOL> not_a_username1 = '<STR_LIT>' <EOL> not_a_username2 = '<STR_LIT>' <EOL> title = "<STR_LIT>" <EOL> summary = "<STR_LIT>" <EOL> test_plan = "<STR_LIT>" <EOL> unknown_reviewers = [ <EOL> not_a_username1 , <EOL> not_a_username2 , <EOL> phldef_conduit . NOTAUSER . user ] <EOL> reviewers = [ phldef_conduit . ALICE . user ] <EOL> message = self . _make_commit_message ( <EOL> title , summary , test_plan , reviewers + unknown_reviewers ) <EOL> parsed = phlcon_differential . parse_commit_message ( <EOL> self . conduit , message ) <EOL> parsed_errors = phlcon_differential . parse_commit_message_errors ( <EOL> parsed . errors ) <EOL> self . assertEqual ( parsed . fields [ "<STR_LIT:title>" ] , title ) <EOL> self . assertEqual ( parsed . fields [ "<STR_LIT>" ] , summary ) <EOL> self . assertEqual ( parsed . fields [ "<STR_LIT>" ] , test_plan ) <EOL> self . assertListEqual ( parsed . fields [ "<STR_LIT>" ] , [ ] ) <EOL> def all_are_instance_of ( item_list , kind ) : <EOL> return all ( [ isinstance ( x , kind ) for x in item_list ] ) <EOL> def only_one_is_instance_of ( item_list , kind ) : <EOL> i = iter ( [ isinstance ( x , kind ) for x in item_list ] ) <EOL> return any ( i ) and not any ( i ) <EOL> self . assertTrue ( <EOL> all_are_instance_of ( <EOL> parsed_errors , <EOL> phlcon_differential . ParseCommitMessageFail ) ) <EOL> self . assertTrue ( <EOL> only_one_is_instance_of ( <EOL> parsed_errors , <EOL> phlcon_differential . ParseCommitMessageNoTestPlanFail ) ) <EOL> self . assertTrue ( <EOL> only_one_is_instance_of ( <EOL> parsed_errors , <EOL> phlcon_differential . ParseCommitMessageUnknownReviewerFail ) ) <EOL> self . assertTrue ( <EOL> only_one_is_instance_of ( <EOL> parsed_errors , <EOL> phlcon_differential . ParseCommitMessageUnknownFail ) ) <EOL> UnkReviewer = phlcon_differential . ParseCommitMessageUnknownReviewerFail <EOL> did_test = False <EOL> for error in parsed_errors : <EOL> if isinstance ( error , UnkReviewer ) : <EOL> self . assertSetEqual ( <EOL> set ( error . user_list ) , set ( unknown_reviewers ) ) <EOL> did_test = True <EOL> self . assertTrue ( did_test ) <EOL> def test_E_HandleReviewersAsTitle ( self ) : <EOL> message = """<STR_LIT>""" <EOL> self . assertRaises ( <EOL> phlcon_differential . UnknownParseCommitMessageResponseError , <EOL> phlcon_differential . parse_commit_message , <EOL> self . conduit , <EOL> message ) <EOL> def testNullQuery ( self ) : <EOL> phlcon_differential . query ( self . conduit ) <EOL> def testParseCommitMessage ( self ) : <EOL> title = "<STR_LIT>" <EOL> summary = "<STR_LIT>" <EOL> test_plan = "<STR_LIT>" <EOL> reviewers = "<STR_LIT>" <EOL> message = "<STR_LIT>" <EOL> message += title + "<STR_LIT:\n>" <EOL> message += "<STR_LIT:\n>" <EOL> message += summary + "<STR_LIT:\n>" <EOL> message += "<STR_LIT>" + test_plan + "<STR_LIT:\n>" <EOL> message += "<STR_LIT>" + reviewers + "<STR_LIT:\n>" <EOL> diff = phlcon_differential <EOL> diff . parse_response = diff . parse_commit_message ( <EOL> self . conduit , message ) <EOL> self . assertEqual ( diff . parse_response . fields [ "<STR_LIT:title>" ] , title ) <EOL> self . assertEqual ( diff . parse_response . fields [ "<STR_LIT>" ] , summary ) <EOL> self . assertEqual ( diff . parse_response . fields [ "<STR_LIT>" ] , test_plan ) <EOL> def testCreateCloseRawDiffRevision ( self ) : <EOL> diff = """<STR_LIT>""" <EOL> message = """<STR_LIT>""" <EOL> diff2 = """<STR_LIT>""" <EOL> diff_response = phlcon_differential . create_raw_diff ( self . conduit , diff ) <EOL> parse_response = phlcon_differential . parse_commit_message ( <EOL> self . conduit , message ) <EOL> self . assertEqual ( len ( parse_response . errors ) , <NUM_LIT:0> ) <EOL> create_response = phlcon_differential . create_revision ( <EOL> self . conduit , diff_response . id , parse_response . fields ) <EOL> query_response_list = phlcon_differential . query ( <EOL> self . conduit , [ create_response . revisionid ] ) <EOL> self . assertEqual ( len ( query_response_list ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( query_response_list [ <NUM_LIT:0> ] . uri , create_response . uri ) <EOL> self . assertEqual ( query_response_list [ <NUM_LIT:0> ] . id , create_response . revisionid ) <EOL> self . assertEqual ( <EOL> query_response_list [ <NUM_LIT:0> ] . status , <EOL> phlcon_differential . ReviewStates . needs_review ) <EOL> diff2_response = phlcon_differential . create_raw_diff ( <EOL> self . conduit , diff2 ) <EOL> update_response = phlcon_differential . update_revision ( <EOL> self . conduit , <EOL> create_response . revisionid , diff2_response . id , <EOL> parse_response . fields , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> update_response . revisionid , create_response . revisionid ) <EOL> self . assertEqual ( update_response . uri , create_response . uri ) <EOL> comment_response = phlcon_differential . create_comment ( <EOL> self . reviewerConduit , create_response . revisionid , action = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> comment_response . revisionid , create_response . revisionid ) <EOL> self . assertEqual ( comment_response . uri , create_response . uri ) <EOL> query_response_list = phlcon_differential . query ( <EOL> self . conduit , [ create_response . revisionid ] ) <EOL> self . assertEqual ( len ( query_response_list ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( query_response_list [ <NUM_LIT:0> ] . uri , create_response . uri ) <EOL> self . assertEqual ( query_response_list [ <NUM_LIT:0> ] . id , create_response . revisionid ) <EOL> self . assertEqual ( <EOL> query_response_list [ <NUM_LIT:0> ] . status , <EOL> phlcon_differential . ReviewStates . accepted ) <EOL> phlcon_differential . close ( self . conduit , create_response . revisionid ) <EOL> query_response_list = phlcon_differential . query ( <EOL> self . conduit , [ create_response . revisionid ] ) <EOL> self . assertEqual ( len ( query_response_list ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( query_response_list [ <NUM_LIT:0> ] . uri , create_response . uri ) <EOL> self . assertEqual ( query_response_list [ <NUM_LIT:0> ] . id , create_response . revisionid ) <EOL> self . assertEqual ( <EOL> query_response_list [ <NUM_LIT:0> ] . status , <EOL> phlcon_differential . ReviewStates . closed ) <EOL> def _createRevision ( self , title ) : <EOL> diff = """<STR_LIT>""" <EOL> message = title + "<STR_LIT>" <EOL> diff_response = phlcon_differential . create_raw_diff ( self . conduit , diff ) <EOL> parse_response = phlcon_differential . parse_commit_message ( <EOL> self . conduit , message ) <EOL> create_response = phlcon_differential . create_revision ( <EOL> self . conduit , diff_response . id , parse_response . fields ) <EOL> return create_response . revisionid <EOL> def _createNonEmptyRevision ( self , title ) : <EOL> diff = """<STR_LIT>""" <EOL> message = "<STR_LIT>" . format ( title ) <EOL> diff_response = phlcon_differential . create_raw_diff ( self . conduit , diff ) <EOL> parse_response = phlcon_differential . parse_commit_message ( <EOL> self . conduit , message ) <EOL> self . assertEqual ( len ( parse_response . errors ) , <NUM_LIT:0> ) <EOL> create_response = phlcon_differential . create_revision ( <EOL> self . conduit , diff_response . id , parse_response . fields ) <EOL> return create_response . revisionid <EOL> def _authorCommentAction ( self , revisionid , action ) : <EOL> phlcon_differential . create_comment ( <EOL> self . conduit , revisionid , action = action ) <EOL> def _reviewCommentAction ( self , revisionid , action ) : <EOL> phlcon_differential . create_comment ( <EOL> self . reviewerConduit , revisionid , action = action ) <EOL> def _getState ( self , revisionid ) : <EOL> return phlcon_differential . query ( self . conduit , [ revisionid ] ) [ <NUM_LIT:0> ] . status <EOL> def _authorActExp ( self , revisionid , action , state ) : <EOL> self . _authorCommentAction ( revisionid , action ) <EOL> self . assertEqual ( self . _getState ( revisionid ) , state ) <EOL> def _reviewActExp ( self , revisionid , action , state ) : <EOL> self . _reviewCommentAction ( revisionid , action ) <EOL> self . assertEqual ( self . _getState ( revisionid ) , state ) <EOL> def testReviewStates ( self ) : <EOL> revisionid = self . _createRevision ( "<STR_LIT>" ) <EOL> d = phlcon_differential <EOL> authorActExp = self . _authorActExp <EOL> reviewActExp = self . _reviewActExp <EOL> states = phlcon_differential . ReviewStates <EOL> authorActExp ( revisionid , d . Action . rethink , states . needs_revision ) <EOL> authorActExp ( revisionid , d . Action . request , states . needs_review ) <EOL> authorActExp ( revisionid , d . Action . abandon , states . abandoned ) <EOL> authorActExp ( revisionid , d . Action . reclaim , states . needs_review ) <EOL> reviewActExp ( revisionid , d . Action . reject , states . needs_revision ) <EOL> reviewActExp ( revisionid , d . Action . accept , states . accepted ) <EOL> reviewActExp ( revisionid , d . Action . reject , states . needs_revision ) <EOL> reviewActExp ( revisionid , d . Action . accept , states . accepted ) <EOL> authorActExp ( revisionid , d . Action . close , states . closed ) <EOL> def testUpdateNoFields ( self ) : <EOL> revisionid = self . _createRevision ( "<STR_LIT>" ) <EOL> diff = """<STR_LIT>""" <EOL> diff_response = phlcon_differential . create_raw_diff ( self . conduit , diff ) <EOL> phlcon_differential . update_revision ( <EOL> self . conduit , revisionid , diff_response . id , [ ] , "<STR_LIT>" ) <EOL> def testUpdateStrangeFields ( self ) : <EOL> revisionid = self . _createRevision ( "<STR_LIT>" ) <EOL> message = "<STR_LIT>" <EOL> diff = """<STR_LIT>""" <EOL> diff_response = phlcon_differential . create_raw_diff ( self . conduit , diff ) <EOL> parse_response = phlcon_differential . parse_commit_message ( <EOL> self . conduit , message ) <EOL> print ( str ( parse_response . fields ) ) <EOL> phlcon_differential . update_revision ( <EOL> self . conduit , <EOL> revisionid , <EOL> diff_response . id , <EOL> parse_response . fields , <EOL> "<STR_LIT>" ) <EOL> def testCanGetCommitMessage ( self ) : <EOL> revisionid = self . _createRevision ( "<STR_LIT>" ) <EOL> phlcon_differential . get_commit_message ( self . conduit , revisionid ) <EOL> def testCreateUpdateEmptyRevision ( self ) : <EOL> conduit = phlsys_conduit . Conduit ( <EOL> self . test_data . TEST_URI , <EOL> self . test_data . PHAB . user , <EOL> self . test_data . PHAB . certificate ) <EOL> author = phldef_conduit . ALICE . user <EOL> with phlsys_conduit . act_as_user_context ( conduit , author ) : <EOL> revision_id = phlcon_differential . create_empty_revision ( conduit ) <EOL> revision_list = phlcon_differential . query ( conduit , [ revision_id ] ) <EOL> self . assertEqual ( len ( revision_list ) , <NUM_LIT:1> ) <EOL> with phlsys_conduit . act_as_user_context ( conduit , author ) : <EOL> phlcon_differential . update_revision_empty ( conduit , revision_id ) </s>
