예제 #1
0
def test_landing_revision_calls_transplant_service(
    db, client, phabdouble, monkeypatch, s3, auth0_mock, get_phab_client
):
    repo = phabdouble.repo(name='mozilla-central')
    diff = phabdouble.diff()
    revision = phabdouble.revision(diff=diff, repo=repo)
    phabdouble.reviewer(revision, phabdouble.user(username='******'))
    patch_url = patches.url(
        'landoapi.test.bucket', patches.name(revision['id'], diff['id'])
    )

    tsclient = MagicMock(spec=TransplantClient)
    tsclient().land.return_value = 1
    monkeypatch.setattr('landoapi.api.landings.TransplantClient', tsclient)
    client.post(
        '/landings',
        json={
            'revision_id': 'D{}'.format(revision['id']),
            'diff_id': diff['id'],
        },
        headers=auth0_mock.mock_headers,
    )
    tsclient().land.assert_called_once_with(
        revision_id=revision['id'],
        ldap_username='******',
        patch_urls=[patch_url],
        tree='mozilla-central',
        pingback='{}/landings/update'.format(os.getenv('PINGBACK_HOST_URL')),
        push_bookmark=''
    )
예제 #2
0
def test_integrated_push_bookmark_sent_when_supported_repo(
    db,
    client,
    phabdouble,
    monkeypatch,
    s3,
    auth0_mock,
    get_phab_client,
    mock_repo_config,
):
    # Mock the repo to have a push bookmark.
    mock_repo_config(
        {
            "test": {
                "mozilla-central": Repo(
                    "mozilla-central",
                    SCM_LEVEL_3,
                    "@",
                    "",
                    "",
                    False,
                    "http://hg.test",
                    False,
                )
            }
        }
    )

    # Mock the phabricator response data
    repo = phabdouble.repo(name="mozilla-central")
    d1 = phabdouble.diff()
    r1 = phabdouble.revision(diff=d1, repo=repo)
    phabdouble.reviewer(r1, phabdouble.user(username="******"))
    patch_url = patches.url("landoapi.test.bucket", patches.name(r1["id"], d1["id"]))

    tsclient = MagicMock(spec=TransplantClient)
    tsclient().land.return_value = 1
    monkeypatch.setattr("landoapi.api.transplants.TransplantClient", tsclient)
    client.post(
        "/transplants",
        json={
            "landing_path": [
                {"revision_id": "D{}".format(r1["id"]), "diff_id": d1["id"]}
            ]
        },
        headers=auth0_mock.mock_headers,
    )
    tsclient().land.assert_called_once_with(
        revision_id=r1["id"],
        ldap_username="******",
        patch_urls=[patch_url],
        tree="mozilla-central",
        pingback="{}/landings/update".format(os.getenv("PINGBACK_HOST_URL")),
        push_bookmark="@",
    )
def test_upload(s3, contents):
    url = patches.upload(1,
                         1,
                         contents,
                         "landoapi.test.bucket",
                         aws_access_key=None,
                         aws_secret_key=None)
    patch = s3.Object("landoapi.test.bucket", patches.name(1, 1))
    patch = patch.get()["Body"].read().decode("utf-8")

    assert patch == contents
    assert url == patches.url("landoapi.test.bucket", patches.name(1, 1))
예제 #4
0
def test_integrated_push_bookmark_sent_when_supported_repo(
    db, client, phabdouble, monkeypatch, s3, auth0_mock, get_phab_client,
    mock_repo_config
):
    # Mock the repo to have a push bookmark.
    mock_repo_config(
        {
            'test': {
                'mozilla-central': Repo(
                    'mozilla-central', SCM_LEVEL_3, '@', 'http://hg.test'
                )
            },
        }
    )  # yapf: disable

    # Mock the phabricator response data
    repo = phabdouble.repo(name='mozilla-central')
    d1 = phabdouble.diff()
    r1 = phabdouble.revision(diff=d1, repo=repo)
    phabdouble.reviewer(r1, phabdouble.user(username='******'))
    patch_url = patches.url(
        'landoapi.test.bucket', patches.name(r1['id'], d1['id'])
    )

    tsclient = MagicMock(spec=TransplantClient)
    tsclient().land.return_value = 1
    monkeypatch.setattr('landoapi.api.transplants.TransplantClient', tsclient)
    client.post(
        '/transplants',
        json={
            'landing_path': [
                {
                    'revision_id': 'D{}'.format(r1['id']),
                    'diff_id': d1['id'],
                },
            ],
        },
        headers=auth0_mock.mock_headers,
    )
    tsclient().land.assert_called_once_with(
        revision_id=r1['id'],
        ldap_username='******',
        patch_urls=[patch_url],
        tree='mozilla-central',
        pingback='{}/landings/update'.format(os.getenv('PINGBACK_HOST_URL')),
        push_bookmark='@'
    )
예제 #5
0
def test_upload_download(s3, contents):
    url = patches.upload(1,
                         1,
                         contents,
                         "landoapi.test.bucket",
                         aws_access_key=None,
                         aws_secret_key=None)
    patch = s3.Object("landoapi.test.bucket", patches.name(1, 1))
    patch = patch.get()["Body"].read().decode("utf-8")

    assert patch == contents
    assert url == patches.url("landoapi.test.bucket", patches.name(1, 1))

    # Now use download to fetch the buffer.
    buf = patches.download(1,
                           1,
                           "landoapi.test.bucket",
                           aws_access_key=None,
                           aws_secret_key=None)
    assert buf.getvalue().decode("utf-8") == contents