예제 #1
0
 def rawdiff(self, diffID='12345'):
     """Return raw diff text for a Revision Diff."""
     rawdiff = deepcopy(CANNED_REVISION_1_RAW_DIFF)
     self.mock.get(phab_url('differential.getrawdiff'),
                   status_code=200,
                   json=rawdiff,
                   additional_matcher=form_matcher('diffID', diffID))
     return rawdiff
예제 #2
0
 def phid(self, response_data):
     """Add a phid.query matcher for the given Phabricator response object.
     """
     phid = phid_for_response(response_data)
     self.mock.get(phab_url('phid.query'),
                   status_code=200,
                   additional_matcher=form_matcher('phids[]', phid),
                   json=response_data)
예제 #3
0
    def rawdiff(self, diff_id='1', patch=None):
        """Return raw diff text for a Revision Diff."""
        rawdiff = deepcopy(CANNED_RAW_DIFF_1)
        if patch is not None:
            rawdiff['result'] = patch

        self.mock.get(phab_url('differential.getrawdiff'),
                      status_code=200,
                      json=rawdiff,
                      additional_matcher=form_matcher('diffID', str(diff_id)))
        return rawdiff
예제 #4
0
    def user(self, username=None, phid=None):
        """Return a Phabricator User."""
        response = deepcopy(CANNED_USER_1)
        user = first_result_in_response(response)
        if username:
            user['userName'] = username
            user['realName'] = "{} Name".format(username)
            user['uri'] = 'http://phabricator.test/p/{}'.format(username)
        if phid:
            user['phid'] = phid

        self.mock.get(phab_url('user.query'),
                      status_code=200,
                      additional_matcher=form_matcher('phids[]', user['phid']),
                      json=response)
        return response
예제 #5
0
    def diff(self, **kwargs):
        """Create a Phabricator Diff along with stub API endpoints.

        Use the kwargs to customize the diff being created. If they are not
        provided, a default template will be used instead.

        kwargs:
            id: The integer diff id to be used. The diff's phid will be
                based on this.
            patch: The patch file to be used when generating the diff's
                rawdiff. All diffs must have a corresponding rawdiff.

        Returns:
            The full JSON response dict for the generated Diff.
        """
        diff = deepcopy(CANNED_DIFF_1)
        if 'id' in kwargs:
            diff_id = kwargs['id']
        else:
            diff_id = first_result_in_response(diff)['id']
        diff = self._replace_key(diff, 'id', diff_id)

        # Create the mock PHID endpoint.
        diff_phid = 'PHID-DIFF-{diff_id}'.format(diff_id=diff_id)
        diff_phid_resp = self._replace_key(CANNED_DIFF_PHID_QUERY_RESULT_1,
                                           'phid', diff_phid)
        diff_phid_resp['uri'] = "{url}/differential/diff/{diff_id}/".format(
            url=os.getenv('PHABRICATOR_URL'), diff_id=diff_id)
        diff_phid_resp['name'] = "Diff {diff_id}".format(diff_id=diff_id)
        diff_phid_resp['full_name'] = diff_phid_resp['name']
        self.phid(diff_phid_resp)

        # Create the mock raw diff endpoint.
        if 'patch' in kwargs:
            self.rawdiff(diff_id=diff_id, patch=kwargs['patch'])
        else:
            self.rawdiff(diff_id=diff_id)

        # Create the mock diff endpoint.
        self.mock.get(phab_url('differential.querydiffs'),
                      status_code=200,
                      json=diff,
                      additional_matcher=form_matcher('ids[]', str(diff_id)))

        return diff
예제 #6
0
 def match_revision(request):
     # Revisions can be looked up by PHID or ID.
     found_phid = form_matcher('phids[]', revision['phid'])(request)
     found_id = form_matcher('ids[]', revision['id'])(request)
     return found_phid or found_id