Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for buildprbody.py
  • Loading branch information
parthea committed Apr 25, 2021
commit c2309eb47f769ae6d5ded22778b2c6a310a0dbe1
67 changes: 67 additions & 0 deletions scripts/buildprbody_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""ChangeSummary tests."""

__author__ = "[email protected] (Anthonios Partheniou)"

import pathlib
import shutil
import unittest

# import pandas as pd

from buildprbody import BuildPrBody
from changesummary import ChangeType

SCRIPTS_DIR = pathlib.Path(__file__).parent.resolve()
CHANGE_SUMMARY_DIR = SCRIPTS_DIR / "test_resources" / "buildprbody_resources"

EXPECTED_PR_BODY_OUTPUT = """\
## Deleted keys were detected in the following stable discovery artifacts:
bigquery v2 https://github.com/googleapis/google-api-python-client/commit/123
cloudtasks v2 https://github.com/googleapis/google-api-python-client/commit/456

## Discovery Artifact Change Summary:
feat(bigquery): update the api https://github.com/googleapis/google-api-python-client/commit/123
feat(cloudtasks): update the api https://github.com/googleapis/google-api-python-client/commit/456
feat(drive): update the api https://github.com/googleapis/google-api-python-client/commit/789
"""


class TestBuildPrBody(unittest.TestCase):
def setUp(self):
self.buildprbody = BuildPrBody(change_summary_directory=CHANGE_SUMMARY_DIR)

def test_get_commit_uri_returns_correct_string(self):
base_uri = "https://github.com/googleapis/google-api-python-client/commit/"

expected_uri = "".join([base_uri, "123"])
result = self.buildprbody.get_commit_uri(name="bigquery")
self.assertEqual(result, expected_uri)

expected_uri = "".join([base_uri, "456"])
result = self.buildprbody.get_commit_uri(name="cloudtasks")
self.assertEqual(result, expected_uri)

expected_uri = "".join([base_uri, "789"])
result = self.buildprbody.get_commit_uri(name="drive")
self.assertEqual(result, expected_uri)

def test_generate_pr_body(self):
self.buildprbody.generate_pr_body()

with open(CHANGE_SUMMARY_DIR / "allapis.summary") as f:
pr_body = "".join(f.readlines())
self.assertEqual(pr_body, EXPECTED_PR_BODY_OUTPUT)
175 changes: 175 additions & 0 deletions scripts/test_resources/buildprbody_resources/allapis.dataframe

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/test_resources/buildprbody_resources/bigquery.sha
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
38 changes: 38 additions & 0 deletions scripts/test_resources/buildprbody_resources/bigquery.verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
feat(bigquery): update the api

#### bigquery:v2


The following keys were deleted:
- schemas.DimensionalityReductionMetrics (Total Keys: 4)
- schemas.EvaluationMetrics.properties.dimensionalityReductionMetrics (Total Keys: 1)
- schemas.IterationResult.properties.principalComponentInfos (Total Keys: 2)
- schemas.PrincipalComponentInfo (Total Keys: 10)

The following keys were added:
- resources.jobs.methods.delete (Total Keys: 16)
- schemas.ArimaModelInfo.properties.hasHolidayEffect (Total Keys: 1)
- schemas.ArimaModelInfo.properties.hasSpikesAndDips (Total Keys: 1)
- schemas.ArimaModelInfo.properties.hasStepChanges (Total Keys: 1)
- schemas.ArimaModelInfo.properties.timeSeriesIds (Total Keys: 2)
- schemas.ArimaSingleModelForecastingMetrics.properties.hasHolidayEffect (Total Keys: 1)
- schemas.ArimaSingleModelForecastingMetrics.properties.hasSpikesAndDips (Total Keys: 1)
- schemas.ArimaSingleModelForecastingMetrics.properties.hasStepChanges (Total Keys: 1)
- schemas.ArimaSingleModelForecastingMetrics.properties.timeSeriesIds (Total Keys: 2)
- schemas.TrainingOptions.properties.adjustStepChanges (Total Keys: 1)
- schemas.TrainingOptions.properties.cleanSpikesAndDips (Total Keys: 1)
- schemas.TrainingOptions.properties.decomposeTimeSeries (Total Keys: 1)
- schemas.TrainingOptions.properties.timeSeriesIdColumns (Total Keys: 2)

The following keys were changed:
- resources.datasets.methods.get (Total Keys: 1)
- resources.datasets.methods.list (Total Keys: 1)
- resources.jobs.methods.get (Total Keys: 1)
- resources.jobs.methods.getQueryResults (Total Keys: 1)
- resources.jobs.methods.list (Total Keys: 1)
- resources.jobs.methods.query (Total Keys: 1)
- resources.projects.methods.getServiceAccount (Total Keys: 1)
- resources.projects.methods.list (Total Keys: 1)
- resources.tabledata.methods.list (Total Keys: 1)
- resources.tables.methods.get (Total Keys: 1)
- resources.tables.methods.list (Total Keys: 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
456
78 changes: 78 additions & 0 deletions scripts/test_resources/buildprbody_resources/cloudtasks.verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
feat(cloudtasks): update the api

#### cloudtasks:v2


The following keys were deleted:
- basePath (Total Keys: 1)
- batchPath (Total Keys: 1)
- canonicalName (Total Keys: 1)
- discoveryVersion (Total Keys: 1)
- fullyEncodeReservedExpansion (Total Keys: 1)
- icons (Total Keys: 2)
- id (Total Keys: 1)
- kind (Total Keys: 1)
- name (Total Keys: 1)
- ownerDomain (Total Keys: 1)
- ownerName (Total Keys: 1)
- parameters.$.xgafv (Total Keys: 2)
- parameters.access_token (Total Keys: 2)
- parameters.alt (Total Keys: 3)
- parameters.callback (Total Keys: 2)
- parameters.fields (Total Keys: 2)
- parameters.key (Total Keys: 2)
- parameters.oauth_token (Total Keys: 2)
- parameters.prettyPrint (Total Keys: 3)
- parameters.quotaUser (Total Keys: 2)
- parameters.uploadType (Total Keys: 2)
- parameters.upload_protocol (Total Keys: 2)
- protocol (Total Keys: 1)
- resources.projects.resources.locations.methods.get (Total Keys: 11)
- resources.projects.resources.locations.methods.list (Total Keys: 18)
- resources.projects.resources.locations.resources.queues.methods.create (Total Keys: 12)
- resources.projects.resources.locations.resources.queues.methods.delete (Total Keys: 11)
- resources.projects.resources.locations.resources.queues.methods.get (Total Keys: 23)
- resources.projects.resources.locations.resources.queues.methods.list (Total Keys: 18)
- resources.projects.resources.locations.resources.queues.methods.patch (Total Keys: 15)
- resources.projects.resources.locations.resources.queues.methods.pause (Total Keys: 12)
- resources.projects.resources.locations.resources.queues.methods.purge (Total Keys: 12)
- resources.projects.resources.locations.resources.queues.methods.resume (Total Keys: 12)
- resources.projects.resources.locations.resources.queues.methods.setIamPolicy (Total Keys: 12)
- resources.projects.resources.locations.resources.queues.methods.testIamPermissions (Total Keys: 12)
- resources.projects.resources.locations.resources.queues.resources.tasks.methods.create (Total Keys: 12)
- resources.projects.resources.locations.resources.queues.resources.tasks.methods.delete (Total Keys: 11)
- resources.projects.resources.locations.resources.queues.resources.tasks.methods.get (Total Keys: 13)
- resources.projects.resources.locations.resources.queues.resources.tasks.methods.list (Total Keys: 18)
- resources.projects.resources.locations.resources.queues.resources.tasks.methods.run (Total Keys: 12)
- schemas.AppEngineHttpRequest (Total Keys: 9)
- schemas.AppEngineRouting (Total Keys: 6)
- schemas.Attempt (Total Keys: 9)
- schemas.Binding (Total Keys: 6)
- schemas.CreateTaskRequest (Total Keys: 4)
- schemas.Empty (Total Keys: 2)
- schemas.Expr (Total Keys: 4)
- schemas.GetIamPolicyRequest (Total Keys: 3)
- schemas.GetPolicyOptions (Total Keys: 4)
- schemas.HttpRequest (Total Keys: 9)
- schemas.ListLocationsResponse (Total Keys: 5)
- schemas.ListQueuesResponse (Total Keys: 5)
- schemas.ListTasksResponse (Total Keys: 5)
- schemas.Location (Total Keys: 9)
- schemas.OAuthToken (Total Keys: 4)
- schemas.OidcToken (Total Keys: 4)
- schemas.PauseQueueRequest (Total Keys: 2)
- schemas.Policy (Total Keys: 6)
- schemas.PurgeQueueRequest (Total Keys: 2)
- schemas.Queue (Total Keys: 10)
- schemas.RateLimits (Total Keys: 8)
- schemas.ResumeQueueRequest (Total Keys: 2)
- schemas.RetryConfig (Total Keys: 12)
- schemas.RunTaskRequest (Total Keys: 3)
- schemas.SetIamPolicyRequest (Total Keys: 3)
- schemas.StackdriverLoggingConfig (Total Keys: 4)
- schemas.Status (Total Keys: 8)
- schemas.Task (Total Keys: 18)
- schemas.TestIamPermissionsRequest (Total Keys: 4)
- schemas.TestIamPermissionsResponse (Total Keys: 4)
- servicePath (Total Keys: 1)
- version (Total Keys: 2)
1 change: 1 addition & 0 deletions scripts/test_resources/buildprbody_resources/drive.sha
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
789
80 changes: 80 additions & 0 deletions scripts/test_resources/buildprbody_resources/drive.verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
feat(drive): update the api

#### drive:v3


The following keys were added:
- basePath (Total Keys: 1)
- batchPath (Total Keys: 1)
- discoveryVersion (Total Keys: 1)
- icons (Total Keys: 2)
- id (Total Keys: 1)
- kind (Total Keys: 1)
- name (Total Keys: 1)
- ownerDomain (Total Keys: 1)
- ownerName (Total Keys: 1)
- parameters.alt (Total Keys: 3)
- parameters.fields (Total Keys: 2)
- parameters.key (Total Keys: 2)
- parameters.oauth_token (Total Keys: 2)
- parameters.prettyPrint (Total Keys: 3)
- parameters.quotaUser (Total Keys: 2)
- parameters.userIp (Total Keys: 2)
- protocol (Total Keys: 1)
- resources.about.methods.get (Total Keys: 5)
- resources.changes.methods.getStartPageToken (Total Keys: 15)
- resources.changes.methods.list (Total Keys: 46)
- resources.changes.methods.watch (Total Keys: 48)
- resources.channels.methods.stop (Total Keys: 6)
- resources.comments.methods.create (Total Keys: 10)
- resources.comments.methods.delete (Total Keys: 11)
- resources.comments.methods.get (Total Keys: 15)
- resources.comments.methods.list (Total Keys: 22)
- resources.comments.methods.update (Total Keys: 13)
- resources.drives.methods.create (Total Keys: 10)
- resources.drives.methods.delete (Total Keys: 8)
- resources.drives.methods.get (Total Keys: 12)
- resources.drives.methods.hide (Total Keys: 9)
- resources.drives.methods.list (Total Keys: 18)
- resources.drives.methods.unhide (Total Keys: 9)
- resources.drives.methods.update (Total Keys: 13)
- resources.files.methods.copy (Total Keys: 26)
- resources.files.methods.create (Total Keys: 33)
- resources.files.methods.delete (Total Keys: 17)
- resources.files.methods.emptyTrash (Total Keys: 7)
- resources.files.methods.export (Total Keys: 12)
- resources.files.methods.generateIds (Total Keys: 14)
- resources.files.methods.get (Total Keys: 23)
- resources.files.methods.list (Total Keys: 42)
- resources.files.methods.update (Total Keys: 37)
- resources.files.methods.watch (Total Keys: 25)
- resources.permissions.methods.create (Total Keys: 32)
- resources.permissions.methods.delete (Total Keys: 20)
- resources.permissions.methods.get (Total Keys: 21)
- resources.permissions.methods.list (Total Keys: 27)
- resources.permissions.methods.update (Total Keys: 28)
- resources.replies.methods.create (Total Keys: 13)
- resources.replies.methods.delete (Total Keys: 14)
- resources.replies.methods.get (Total Keys: 18)
- resources.replies.methods.list (Total Keys: 23)
- resources.replies.methods.update (Total Keys: 16)
- resources.teamdrives.methods.create (Total Keys: 10)
- resources.teamdrives.methods.delete (Total Keys: 8)
- resources.teamdrives.methods.get (Total Keys: 12)
- resources.teamdrives.methods.list (Total Keys: 18)
- resources.teamdrives.methods.update (Total Keys: 13)
- schemas.About (Total Keys: 40)
- schemas.Change (Total Keys: 23)
- schemas.Channel (Total Keys: 15)
- schemas.Comment (Total Keys: 28)
- schemas.ContentRestriction (Total Keys: 8)
- schemas.Drive (Total Keys: 50)
- schemas.File (Total Keys: 168)
- schemas.GeneratedIds (Total Keys: 7)
- schemas.Permission (Total Keys: 37)
- schemas.Reply (Total Keys: 22)
- schemas.StartPageToken (Total Keys: 5)
- schemas.TeamDrive (Total Keys: 50)
- schemas.User (Total Keys: 9)
- servicePath (Total Keys: 1)
- version (Total Keys: 1)