Exemplo n.º 1
0
def test_landing_revision_calls_transplant_service(db, client, phabfactory,
                                                   monkeypatch, s3):
    # Mock the phabricator response data
    phabfactory.revision()

    # Build the patch we expect to see
    phabclient = PhabricatorClient('someapi')
    revision = phabclient.get_revision('D1')
    diff_id = phabclient.get_diff(phid=revision['activeDiffPHID'])['id']
    gitdiff = phabclient.get_rawdiff(diff_id)
    author = phabclient.get_revision_author(revision)
    hgpatch = build_patch_for_revision(gitdiff, author, revision)
    patch_url = 's3://landoapi.test.bucket/L1_D1_1.patch'

    # The repo we expect to see
    repo_uri = phabclient.get_revision_repo(revision)['uri']

    tsclient = MagicMock(spec=TransplantClient)
    tsclient().land.return_value = 1
    monkeypatch.setattr('landoapi.models.landing.TransplantClient', tsclient)
    client.post('/landings?api_key=api-key',
                data=json.dumps({
                    'revision_id': 'D1',
                    'diff_id': int(diff_id)
                }),
                content_type='application/json')
    tsclient().land.assert_called_once_with(
        '*****@*****.**', patch_url, repo_uri,
        '{}/landings/1/update'.format(os.getenv('PINGBACK_HOST_URL')))
    body = s3.Object('landoapi.test.bucket',
                     'L1_D1_1.patch').get()['Body'].read().decode("utf-8")
    assert body == hgpatch
Exemplo n.º 2
0
def test_get_rawdiff_by_id(phabfactory):
    patch = "diff --git a/hello.c b/hello.c..."
    # The raw patch's diffID is encoded in the Diff URI.
    phabfactory.diff(id='12345', patch=patch)
    phab = PhabricatorClient(api_key='api-key')
    returned_patch = phab.get_rawdiff('12345')
    assert returned_patch == patch