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))
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='' )
def test_integrated_transplant_sec_approval_group_is_excluded_from_reviewers_list( app, db, client, phabdouble, auth0_mock, s3, transfactory, sec_approval_project): repo = phabdouble.repo() user = phabdouble.user(username="******") diff = phabdouble.diff() revision = phabdouble.revision(diff=diff, repo=repo) phabdouble.reviewer(revision, user) phabdouble.reviewer(revision, sec_approval_project) transfactory.mock_successful_response() response = client.post( "/transplants", json={ "landing_path": [{ "revision_id": "D{}".format(revision["id"]), "diff_id": diff["id"] }] }, headers=auth0_mock.mock_headers, ) assert response == 202 # Check the transplanted patch for our alternate commit message. patch = s3.Object(app.config["PATCH_BUCKET_NAME"], patches.name(revision["id"], diff["id"])) patch_text = patch.get()["Body"].read().decode() assert sec_approval_project["name"] not in patch_text
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_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
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='@' )
def test_integrated_sec_approval_transplant_uses_alternate_message( app, db, client, phabdouble, transfactory, s3, auth0_mock, secure_project, monkeypatch, authed_headers, ): sanitized_title = "my secure commit title" revision_title = "my insecure revision title" # Build a revision with an active sec-approval request. diff, secure_revision = _make_sec_approval_request( sanitized_title, revision_title, authed_headers, client, monkeypatch, phabdouble, secure_project, ) # Get our list of warnings so we can get the confirmation token, acknowledge them, # and land the request. response = client.post( "/transplants/dryrun", json={ "landing_path": [{ "revision_id": monogram(secure_revision), "diff_id": diff["id"] }] }, headers=auth0_mock.mock_headers, ) assert response == 200 confirmation_token = response.json["confirmation_token"] transfactory.mock_successful_response() # Request landing of the patch using our alternate commit message. response = client.post( "/transplants", json={ "landing_path": [{ "revision_id": monogram(secure_revision), "diff_id": diff["id"] }], "confirmation_token": confirmation_token, }, headers=auth0_mock.mock_headers, ) assert response == 202 # Check the transplanted patch for our alternate commit message. patch = s3.Object(app.config["PATCH_BUCKET_NAME"], patches.name(secure_revision["id"], diff["id"])) for line in patch.get()["Body"].read().decode().splitlines(): if not line.startswith("#"): title = line break else: pytest.fail("Could not find commit message title in patch body") assert title == sanitized_title