def _createNonEmptyRevision(self, title):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""

        message = "{}\n\nTest Plan: this is the plan".format(title)

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        get_diff_response = phlcon_differential._get_diff(self.conduit, diff_id=diff_response.id)
        self.assertEqual(get_diff_response.id, diff_response.id)

        parse_response = phlcon_differential.parse_commit_message(self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(self.conduit, diff_response.id, parse_response.fields)

        return create_response.revisionid
Пример #2
0
    def _createNonEmptyRevision(self, title):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""

        message = "{}\n\nTest Plan: this is the plan".format(title)

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(
            self.conduit, diff_response.id, parse_response.fields)

        return create_response.revisionid
 def _createRevision(self, title):
     diff = """diff --git a/ b/"""
     message = title + "\n\ntest plan: no test plan"
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(self.conduit, message)
     create_response = phlcon_differential.create_revision(self.conduit, diff_response.id, parse_response.fields)
     return create_response.revisionid
 def testUpdateStrangeFields(self):
     revisionid = self._createRevision("testUpdateStrangeFields")
     message = "test\n\nmeh: blah\nstrange: blah\n123: blah\ntest plan: hmm"
     diff = """diff --git a/ b/"""
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(self.conduit, message)
     print str(parse_response.fields)
     phlcon_differential.update_revision(self.conduit, revisionid, diff_response.id, parse_response.fields, "update")
Пример #5
0
    def parse_commit_message(self, message):
        """Return a ParseCommitMessageResponse based on 'message'.

        :message: a string message to parse
        :returns: a phlcon_differential.ParseCommitMessageResponse

        """
        message = phlsys_textconvert.to_unicode(message)
        return phlcon_differential.parse_commit_message(self._conduit, message)
    def parse_commit_message(self, message):
        """Return a ParseCommitMessageResponse based on 'message'.

        :message: a string message to parse
        :returns: a phlcon_differential.ParseCommitMessageResponse

        """
        message = unicode(message, errors='replace')
        return phlcon_differential.parse_commit_message(self._conduit, message)
Пример #7
0
 def _createRevision(self, title):
     diff = """diff --git a/ b/"""
     message = title + "\n\ntest plan: no test plan"
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(
         self.conduit, message)
     create_response = phlcon_differential.create_revision(
         self.conduit, diff_response.id, parse_response.fields)
     return create_response.revisionid
Пример #8
0
    def parse_commit_message(self, message):
        """Return a ParseCommitMessageResponse based on 'message'.

        :message: a string message to parse
        :returns: a phlcon_differential.ParseCommitMessageResponse

        """
        message = phlsys_textconvert.to_unicode(message)
        return phlcon_differential.parse_commit_message(
            self._multi_conduit, message)
Пример #9
0
 def testUpdateStrangeFields(self):
     revisionid = self._createRevision("testUpdateStrangeFields")
     message = "test\n\nmeh: blah\nstrange: blah\n123: blah\ntest plan: hmm"
     diff = """diff --git a/ b/"""
     diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)
     parse_response = phlcon_differential.parse_commit_message(
         self.conduit, message)
     print(str(parse_response.fields))
     phlcon_differential.update_revision(
         self.conduit,
         revisionid,
         diff_response.id,
         parse_response.fields,
         "update")
def getFieldsFromCommitHash(conduit, clone, commit_hash, defaultTestPlan=None):
    """Return a ParseCommitMessageResponse based on the commit message.

    :conduit: supports call()
    :clone: supports call()
    :commit_hash: a single commit hash to get the message from
    :returns: a phlcon_differential.ParseCommitMessageResponse

    """
    revision = phlgit_log.make_revision_from_hash(clone, commit_hash)
    message = revision.subject + "\n"
    message += "\n"
    message += revision.message + "\n"
    parsed = phlcon_differential.parse_commit_message(conduit, message)

    testPlan = "testPlan"
    if defaultTestPlan is not None:
        if parsed.fields is not None:
            if not testPlan in parsed.fields or not parsed.fields[testPlan]:
                message += "Test Plan:\n" + defaultTestPlan
                parsed = phlcon_differential.parse_commit_message(
                    conduit, message)

    return parsed
    def testCreateDiffRevision(self):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -1,3 +1,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""
        message = """
add a line to README

Test Plan: I proof-read it and it looked ok
"""
        raw_diff_response = phlcon_differential.create_raw_diff(
            self.conduit, diff)
        get_diff_response = phlcon_differential._get_diff(
            self.conduit,
            diff_id=raw_diff_response.id)

        diff_response = phlcon_differential.create_diff(
            self.conduit,
            changes_dict=get_diff_response.changes,
            source_machine="test_machine",
            source_path="source_path",
            branch="branch",
            source_control_system="git",  # svn or git
            source_control_path="control_path",
            source_control_base_revision="0",
            lint_status="none",
            unit_status="none",
            bookmark=None,
            parent_revision_id=None,
            creation_method="arcanist daemon",
            author_phid=None,
            arcanist_project="project",
            repository_uuid=None)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        # rely on create_revision to raise if we get anything seriously wrong
        phlcon_differential.create_revision(
            self.conduit, diff_response["diffid"], parse_response.fields)
    def test_D_DistinguishParseErrors(self):
        not_a_username1 = "NOTAUSER1_test_D_DistinguishParseErrors"
        not_a_username2 = "NOTAUSER2_test_D_DistinguishParseErrors"

        title = ""
        summary = ""
        test_plan = ""
        unknown_reviewers = [not_a_username1, not_a_username2, phldef_conduit.NOTAUSER.user]
        reviewers = [phldef_conduit.ALICE.user]

        message = self._make_commit_message(title, summary, test_plan, reviewers + unknown_reviewers)

        parsed = phlcon_differential.parse_commit_message(self.conduit, message)

        parsed_errors = phlcon_differential.parse_commit_message_errors(parsed.errors)

        self.assertEqual(parsed.fields["title"], title)
        self.assertEqual(parsed.fields["summary"], summary)
        self.assertEqual(parsed.fields["testPlan"], test_plan)
        self.assertListEqual(parsed.fields["reviewerPHIDs"], [])

        def all_are_instance_of(item_list, kind):
            return all([isinstance(x, kind) for x in item_list])

        def only_one_is_instance_of(item_list, kind):
            # iterate to the first one and then make sure there are no others
            i = iter([isinstance(x, kind) for x in item_list])
            return any(i) and not any(i)

        self.assertTrue(all_are_instance_of(parsed_errors, phlcon_differential.ParseCommitMessageFail))

        self.assertTrue(only_one_is_instance_of(parsed_errors, phlcon_differential.ParseCommitMessageNoTestPlanFail))

        self.assertTrue(
            only_one_is_instance_of(parsed_errors, phlcon_differential.ParseCommitMessageUnknownReviewerFail)
        )

        self.assertTrue(only_one_is_instance_of(parsed_errors, phlcon_differential.ParseCommitMessageUnknownFail))

        UnkReviewer = phlcon_differential.ParseCommitMessageUnknownReviewerFail
        did_test = False
        for error in parsed_errors:
            if isinstance(error, UnkReviewer):
                self.assertSetEqual(set(error.user_list), set(unknown_reviewers))
                did_test = True

        self.assertTrue(did_test)
    def testCreateCloseRawDiffRevision(self):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""
        message = """
add a line to README

Test Plan: I proof-read it and it looked ok
"""

        diff2 = """
diff --git a/readme b/readme
index d4711bb..1c634f5 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,5 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
+another line
"""

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        get_diff_response = phlcon_differential._get_diff(
            self.conduit, diff_id=diff_response.id)
        self.assertEqual(get_diff_response.id, diff_response.id)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(
            self.conduit, diff_response.id, parse_response.fields)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.needs_review)

        diff2_response = phlcon_differential.create_raw_diff(
            self.conduit, diff2)

        update_response = phlcon_differential.update_revision(
            self.conduit,
            create_response.revisionid, diff2_response.id,
            parse_response.fields, "updated with new diff")
        self.assertEqual(
            update_response.revisionid, create_response.revisionid)
        self.assertEqual(update_response.uri, create_response.uri)

        comment_response = phlcon_differential.create_comment(
            self.reviewerConduit, create_response.revisionid, action="accept")
        self.assertEqual(
            comment_response.revisionid, create_response.revisionid)
        self.assertEqual(comment_response.uri, create_response.uri)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.accepted)

        phlcon_differential.close(self.conduit, create_response.revisionid)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.closed)
Пример #14
0
    def testCreateCloseRawDiffRevision(self):
        diff = """
diff --git a/readme b/readme
index d4711bb..ee5b241 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,4 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
"""
        message = """
add a line to README

Test Plan: I proof-read it and it looked ok
"""

        diff2 = """
diff --git a/readme b/readme
index d4711bb..1c634f5 100644
--- a/readme
+++ b/readme
@@ -7,3 +7,5 @@ and one more!!
 -- and one last(?) one
 alaric!
 local stuff!
+manual conduit submission
+another line
"""

        diff_response = phlcon_differential.create_raw_diff(self.conduit, diff)

        parse_response = phlcon_differential.parse_commit_message(
            self.conduit, message)
        self.assertEqual(len(parse_response.errors), 0)

        create_response = phlcon_differential.create_revision(
            self.conduit, diff_response.id, parse_response.fields)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.needs_review)

        diff2_response = phlcon_differential.create_raw_diff(
            self.conduit, diff2)

        update_response = phlcon_differential.update_revision(
            self.conduit,
            create_response.revisionid, diff2_response.id,
            parse_response.fields, "updated with new diff")
        self.assertEqual(
            update_response.revisionid, create_response.revisionid)
        self.assertEqual(update_response.uri, create_response.uri)

        comment_response = phlcon_differential.create_comment(
            self.reviewerConduit, create_response.revisionid, action="accept")
        self.assertEqual(
            comment_response.revisionid, create_response.revisionid)
        self.assertEqual(comment_response.uri, create_response.uri)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.accepted)

        phlcon_differential.close(self.conduit, create_response.revisionid)

        query_response_list = phlcon_differential.query(
            self.conduit, [create_response.revisionid])
        self.assertEqual(len(query_response_list), 1)
        self.assertEqual(query_response_list[0].uri, create_response.uri)
        self.assertEqual(query_response_list[0].id, create_response.revisionid)
        self.assertEqual(
            query_response_list[0].status,
            phlcon_differential.ReviewStates.closed)
Пример #15
0
    def test_D_DistinguishParseErrors(self):
        not_a_username1 = 'NOTAUSER1_test_D_DistinguishParseErrors'
        not_a_username2 = 'NOTAUSER2_test_D_DistinguishParseErrors'

        title = ""
        summary = ""
        test_plan = ""
        unknown_reviewers = [
            not_a_username1,
            not_a_username2,
            phldef_conduit.NOTAUSER.user]
        reviewers = [phldef_conduit.ALICE.user]

        message = self._make_commit_message(
            title, summary, test_plan, reviewers + unknown_reviewers)

        parsed = phlcon_differential.parse_commit_message(
            self.conduit, message)

        parsed_errors = phlcon_differential.parse_commit_message_errors(
            parsed.errors)

        self.assertEqual(parsed.fields["title"], title)
        self.assertEqual(parsed.fields["summary"], summary)
        self.assertEqual(parsed.fields["testPlan"], test_plan)
        self.assertListEqual(parsed.fields["reviewerPHIDs"], [])

        def all_are_instance_of(item_list, kind):
            return all([isinstance(x, kind) for x in item_list])

        def only_one_is_instance_of(item_list, kind):
            # iterate to the first one and then make sure there are no others
            i = iter([isinstance(x, kind) for x in item_list])
            return any(i) and not any(i)

        self.assertTrue(
            all_are_instance_of(
                parsed_errors,
                phlcon_differential.ParseCommitMessageFail))

        self.assertTrue(
            only_one_is_instance_of(
                parsed_errors,
                phlcon_differential.ParseCommitMessageNoTestPlanFail))

        self.assertTrue(
            only_one_is_instance_of(
                parsed_errors,
                phlcon_differential.ParseCommitMessageUnknownReviewerFail))

        self.assertTrue(
            only_one_is_instance_of(
                parsed_errors,
                phlcon_differential.ParseCommitMessageUnknownFail))

        UnkReviewer = phlcon_differential.ParseCommitMessageUnknownReviewerFail
        did_test = False
        for error in parsed_errors:
            if isinstance(error, UnkReviewer):
                self.assertSetEqual(
                    set(error.user_list), set(unknown_reviewers))
                did_test = True

        self.assertTrue(did_test)