Anthonios Partheniou | 6a88422 | 2021-05-10 22:14:57 -0400 | [diff] [blame] | 1 | # Copyright 2021 Google LLC |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | """BuildPrBody tests.""" |
| 16 | |
| 17 | __author__ = "partheniou@google.com (Anthonios Partheniou)" |
| 18 | |
| 19 | import pathlib |
| 20 | import shutil |
| 21 | import unittest |
| 22 | |
| 23 | from buildprbody import BuildPrBody |
| 24 | from changesummary import ChangeType |
| 25 | |
| 26 | SCRIPTS_DIR = pathlib.Path(__file__).parent.resolve() |
| 27 | CHANGE_SUMMARY_DIR = SCRIPTS_DIR / "test_resources" / "buildprbody_resources" |
| 28 | |
| 29 | EXPECTED_PR_BODY_OUTPUT = """\ |
| 30 | ## Deleted keys were detected in the following stable discovery artifacts: |
| 31 | bigquery v2 https://github.com/googleapis/google-api-python-client/commit/123 |
| 32 | cloudtasks v2 https://github.com/googleapis/google-api-python-client/commit/456 |
| 33 | |
| 34 | ## Discovery Artifact Change Summary: |
| 35 | feat(bigquery): update the api https://github.com/googleapis/google-api-python-client/commit/123 |
| 36 | feat(cloudtasks): update the api https://github.com/googleapis/google-api-python-client/commit/456 |
| 37 | feat(drive): update the api https://github.com/googleapis/google-api-python-client/commit/789 |
| 38 | """ |
| 39 | |
| 40 | |
| 41 | class TestBuildPrBody(unittest.TestCase): |
| 42 | def setUp(self): |
| 43 | self.buildprbody = BuildPrBody(change_summary_directory=CHANGE_SUMMARY_DIR) |
| 44 | |
| 45 | def test_get_commit_uri_returns_correct_string(self): |
| 46 | base_uri = "https://github.com/googleapis/google-api-python-client/commit/" |
| 47 | |
| 48 | expected_uri = "".join([base_uri, "123"]) |
| 49 | result = self.buildprbody.get_commit_uri(name="bigquery") |
| 50 | self.assertEqual(result, expected_uri) |
| 51 | |
| 52 | expected_uri = "".join([base_uri, "456"]) |
| 53 | result = self.buildprbody.get_commit_uri(name="cloudtasks") |
| 54 | self.assertEqual(result, expected_uri) |
| 55 | |
| 56 | expected_uri = "".join([base_uri, "789"]) |
| 57 | result = self.buildprbody.get_commit_uri(name="drive") |
| 58 | self.assertEqual(result, expected_uri) |
| 59 | |
| 60 | def test_generate_pr_body(self): |
| 61 | self.buildprbody.generate_pr_body() |
| 62 | |
| 63 | with open(CHANGE_SUMMARY_DIR / "allapis.summary") as f: |
| 64 | pr_body = "".join(f.readlines()) |
| 65 | self.assertEqual(pr_body, EXPECTED_PR_BODY_OUTPUT) |