From d0d68a3e8f5c5c23cd5263bb498192c7c1c3f4aa Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Wed, 6 Dec 2023 20:05:12 -0500 Subject: [PATCH 1/5] test: add test with RequestsMock for create_pull_request in test_gitlab.py Signed-off-by: Jennifer Power --- poetry.lock | 65 +++++++++++---------------------- pyproject.toml | 2 + tests/trestlebot/test_gitlab.py | 47 +++++++++++++++++++++++- 3 files changed, 70 insertions(+), 44 deletions(-) diff --git a/poetry.lock b/poetry.lock index bb98eaa1..2b8f8d8b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "anyio" @@ -567,7 +567,7 @@ jinja2 = ">=2.10.1,<4.0" packaging = "*" pydantic = [ {version = ">=1.10.0,<2.0.0 || >2.0.0,<2.0.1 || >2.0.1,<2.4.0 || >2.4.0,<3.0", extras = ["email"], markers = "python_version >= \"3.12\" and python_version < \"4.0\""}, - {version = ">=1.10.0,<2.4.0 || >2.4.0,<3.0", extras = ["email"], markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, + {version = ">=1.10.0,<2.4.0 || >2.4.0,<3.0", extras = ["email"], markers = "python_version >= \"3.11\" and python_version < \"4.0\""}, {version = ">=1.5.1,<2.4.0 || >2.4.0,<3.0", extras = ["email"], markers = "python_version < \"3.10\""}, {version = ">=1.9.0,<2.4.0 || >2.4.0,<3.0", extras = ["email"], markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, ] @@ -986,16 +986,6 @@ files = [ {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, @@ -1598,7 +1588,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -1606,15 +1595,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -1631,7 +1613,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -1639,7 +1620,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -1680,6 +1660,25 @@ files = [ [package.dependencies] requests = ">=2.0.1,<3.0.0" +[[package]] +name = "responses" +version = "0.24.1" +description = "A utility library for mocking out the `requests` Python library." +optional = false +python-versions = ">=3.8" +files = [ + {file = "responses-0.24.1-py3-none-any.whl", hash = "sha256:a2b43f4c08bfb9c9bd242568328c65a34b318741d3fab884ac843c5ceeb543f9"}, + {file = "responses-0.24.1.tar.gz", hash = "sha256:b127c6ca3f8df0eb9cc82fd93109a3007a86acb24871834c47b77765152ecf8c"}, +] + +[package.dependencies] +pyyaml = "*" +requests = ">=2.30.0,<3.0" +urllib3 = ">=1.25.10,<3.0" + +[package.extras] +tests = ["coverage (>=6.0.0)", "flake8", "mypy", "pytest (>=7.0.0)", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "tomli", "tomli-w", "types-PyYAML", "types-requests"] + [[package]] name = "ruamel-yaml" version = "0.18.5" @@ -1708,50 +1707,30 @@ files = [ {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:b42169467c42b692c19cf539c38d4602069d8c1505e97b86387fcf7afb766e1d"}, {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-macosx_13_0_arm64.whl", hash = "sha256:07238db9cbdf8fc1e9de2489a4f68474e70dffcb32232db7c08fa61ca0c7c462"}, {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:fff3573c2db359f091e1589c3d7c5fc2f86f5bdb6f24252c2d8e539d4e45f412"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-manylinux_2_24_aarch64.whl", hash = "sha256:aa2267c6a303eb483de8d02db2871afb5c5fc15618d894300b88958f729ad74f"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:840f0c7f194986a63d2c2465ca63af8ccbbc90ab1c6001b1978f05119b5e7334"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:024cfe1fc7c7f4e1aff4a81e718109e13409767e4f871443cbff3dba3578203d"}, {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-win32.whl", hash = "sha256:c69212f63169ec1cfc9bb44723bf2917cbbd8f6191a00ef3410f5a7fe300722d"}, {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-win_amd64.whl", hash = "sha256:cabddb8d8ead485e255fe80429f833172b4cadf99274db39abc080e068cbcc31"}, {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:bef08cd86169d9eafb3ccb0a39edb11d8e25f3dae2b28f5c52fd997521133069"}, {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-macosx_13_0_arm64.whl", hash = "sha256:b16420e621d26fdfa949a8b4b47ade8810c56002f5389970db4ddda51dbff248"}, {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:25c515e350e5b739842fc3228d662413ef28f295791af5e5110b543cf0b57d9b"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-manylinux_2_24_aarch64.whl", hash = "sha256:1707814f0d9791df063f8c19bb51b0d1278b8e9a2353abbb676c2f685dee6afe"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:46d378daaac94f454b3a0e3d8d78cafd78a026b1d71443f4966c696b48a6d899"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:09b055c05697b38ecacb7ac50bdab2240bfca1a0c4872b0fd309bb07dc9aa3a9"}, {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-win32.whl", hash = "sha256:53a300ed9cea38cf5a2a9b069058137c2ca1ce658a874b79baceb8f892f915a7"}, {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-win_amd64.whl", hash = "sha256:c2a72e9109ea74e511e29032f3b670835f8a59bbdc9ce692c5b4ed91ccf1eedb"}, {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:ebc06178e8821efc9692ea7544aa5644217358490145629914d8020042c24aa1"}, {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-macosx_13_0_arm64.whl", hash = "sha256:edaef1c1200c4b4cb914583150dcaa3bc30e592e907c01117c08b13a07255ec2"}, {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d176b57452ab5b7028ac47e7b3cf644bcfdc8cacfecf7e71759f7f51a59e5c92"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-manylinux_2_24_aarch64.whl", hash = "sha256:1dc67314e7e1086c9fdf2680b7b6c2be1c0d8e3a8279f2e993ca2a7545fecf62"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:3213ece08ea033eb159ac52ae052a4899b56ecc124bb80020d9bbceeb50258e9"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:aab7fd643f71d7946f2ee58cc88c9b7bfc97debd71dcc93e03e2d174628e7e2d"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-win32.whl", hash = "sha256:5c365d91c88390c8d0a8545df0b5857172824b1c604e867161e6b3d59a827eaa"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-win_amd64.whl", hash = "sha256:1758ce7d8e1a29d23de54a16ae867abd370f01b5a69e1a3ba75223eaa3ca1a1b"}, {file = "ruamel.yaml.clib-0.2.8-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:a5aa27bad2bb83670b71683aae140a1f52b0857a2deff56ad3f6c13a017a26ed"}, {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:c58ecd827313af6864893e7af0a3bb85fd529f862b6adbefe14643947cfe2942"}, {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-macosx_12_0_arm64.whl", hash = "sha256:f481f16baec5290e45aebdc2a5168ebc6d35189ae6fea7a58787613a25f6e875"}, - {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-manylinux_2_24_aarch64.whl", hash = "sha256:77159f5d5b5c14f7c34073862a6b7d34944075d9f93e681638f6d753606c6ce6"}, {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:7f67a1ee819dc4562d444bbafb135832b0b909f81cc90f7aa00260968c9ca1b3"}, - {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:4ecbf9c3e19f9562c7fdd462e8d18dd902a47ca046a2e64dba80699f0b6c09b7"}, - {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:87ea5ff66d8064301a154b3933ae406b0863402a799b16e4a1d24d9fbbcbe0d3"}, {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-win32.whl", hash = "sha256:75e1ed13e1f9de23c5607fe6bd1aeaae21e523b32d83bb33918245361e9cc51b"}, {file = "ruamel.yaml.clib-0.2.8-cp37-cp37m-win_amd64.whl", hash = "sha256:3f215c5daf6a9d7bbed4a0a4f760f3113b10e82ff4c5c44bec20a68c8014f675"}, {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1b617618914cb00bf5c34d4357c37aa15183fa229b24767259657746c9077615"}, {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-macosx_12_0_arm64.whl", hash = "sha256:a6a9ffd280b71ad062eae53ac1659ad86a17f59a0fdc7699fd9be40525153337"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-manylinux_2_24_aarch64.whl", hash = "sha256:305889baa4043a09e5b76f8e2a51d4ffba44259f6b4c72dec8ca56207d9c6fe1"}, {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:700e4ebb569e59e16a976857c8798aee258dceac7c7d6b50cab63e080058df91"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:e2b4c44b60eadec492926a7270abb100ef9f72798e18743939bdbf037aab8c28"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:e79e5db08739731b0ce4850bed599235d601701d5694c36570a99a0c5ca41a9d"}, {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-win32.whl", hash = "sha256:955eae71ac26c1ab35924203fda6220f84dce57d6d7884f189743e2abe3a9fbe"}, {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-win_amd64.whl", hash = "sha256:56f4252222c067b4ce51ae12cbac231bce32aee1d33fbfc9d17e5b8d6966c312"}, {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:03d1162b6d1df1caa3a4bd27aa51ce17c9afc2046c31b0ad60a0a96ec22f8001"}, {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-macosx_12_0_arm64.whl", hash = "sha256:bba64af9fa9cebe325a62fa398760f5c7206b215201b0ec825005f1b18b9bccf"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-manylinux_2_24_aarch64.whl", hash = "sha256:a1a45e0bb052edf6a1d3a93baef85319733a888363938e1fc9924cb00c8df24c"}, {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:da09ad1c359a728e112d60116f626cc9f29730ff3e0e7db72b9a2dbc2e4beed5"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:184565012b60405d93838167f425713180b949e9d8dd0bbc7b49f074407c5a8b"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a75879bacf2c987c003368cf14bed0ffe99e8e85acfa6c0bfffc21a090f16880"}, {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-win32.whl", hash = "sha256:84b554931e932c46f94ab306913ad7e11bba988104c5cff26d90d03f68258cd5"}, {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-win_amd64.whl", hash = "sha256:25ac8c08322002b06fa1d49d1646181f0b2c72f5cbc15a85e80b4c30a544bb15"}, {file = "ruamel.yaml.clib-0.2.8.tar.gz", hash = "sha256:beb2e0404003de9a4cab9753a8805a8fe9320ee6673136ed7f04255fe60bb512"}, @@ -1915,4 +1894,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "5dea8c720e29268277b003a8efdb4f7a227a2fc4cdaaccd9732794d7739515bd" +content-hash = "d9aa370c22ef62864ab300a194a78dbe385b004742435c6e52769d240f2d07bf" diff --git a/pyproject.toml b/pyproject.toml index 24c51a24..dde31cad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,8 @@ pre-commit = "^3.4.0" pytest = "^7.3.2" pytest-cov = "^4.1.0" pytest-skip-slow = "^0.0.5" +responses = "^0.24.1" + [tool.coverage.run] branch = true diff --git a/tests/trestlebot/test_gitlab.py b/tests/trestlebot/test_gitlab.py index 36ce69aa..2fe4878c 100644 --- a/tests/trestlebot/test_gitlab.py +++ b/tests/trestlebot/test_gitlab.py @@ -16,12 +16,14 @@ """Test for GitLab provider logic""" -from typing import Callable, Tuple +import re +from typing import Callable, Generator, Tuple from unittest.mock import patch import pytest from git.repo import Repo from gitlab.exceptions import GitlabAuthenticationError, GitlabCreateError +from responses import GET, POST, RequestsMock from tests.testutils import clean from trestlebot.gitlab import GitLab @@ -111,6 +113,49 @@ def test_parse_repository_with_incorrect_name() -> None: gl.parse_repository("https://notgitlab.com/owner/repo.git") +mr_content = { + "id": 123, + "title": "Example Merge Request", + "description": "This is an example merge request description.", + "state": "opened", + "created_at": "2023-12-06T08:30:00Z", + "updated_at": "2023-12-06T09:15:00Z", + "source_branch": "feature-branch", + "target_branch": "main", + "author": {"id": 789, "name": "Jane Doe", "username": "janedoe"}, + "merge_status": "can_be_merged", +} + + +@pytest.fixture +def resp_merge_requests() -> Generator[RequestsMock, None, None]: + with RequestsMock() as rsps: + rsps.add( + method=POST, + url=re.compile(r"http://localhost/api/v4/projects/1/merge_requests"), + json=mr_content, + content_type="application/json", + status=200, + ) + rsps.add( + method=GET, + url=re.compile(r"http://localhost/api/v4/projects/owner%2Frepo"), + json={"name": "name", "id": 1}, + content_type="application/json", + status=200, + ) + yield rsps + + +def test_create_pull_request(resp_merge_requests: RequestsMock) -> None: + """Test creating a pull request""" + gl = GitLab("fake", "http://localhost") + pr_number = gl.create_pull_request( + "owner", "repo", "main", "test", "My PR", "Has Changes" + ) + assert pr_number == 123 + + def create_side_effect(name: str) -> None: raise GitlabCreateError("example") From 88d60aa4b0f22f0da3c9edcf1f934ca944bbc5f9 Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Wed, 6 Dec 2023 20:06:29 -0500 Subject: [PATCH 2/5] docs: update E2E test docs Signed-off-by: Jennifer Power --- tests/e2e/README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 017abfd4..f2ab09ce 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -55,8 +55,4 @@ To run the end-to-end tests, follow these steps: export TRESTLEBOT_IMAGE=quay.io/continuouscompliance/trestle-bot:latest ``` -- When created tests that push to a branch, ensure the name is "test". This is because the mock API server is configured to only allow pushes to a branch named "test". - -## Future Improvements -- Create endpoints that mock GitHub and GitLab API calls for pull request creation. -- Add more end-to-end tests to cover more use cases. \ No newline at end of file +- When created tests that push to a branch, ensure the name is "test". This is because the mock API server is configured to only allow pushes to a branch named "test". \ No newline at end of file From 93d704444d4469e4dc05054faddf496d122aa8e9 Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Thu, 7 Dec 2023 15:11:52 -0500 Subject: [PATCH 3/5] test: adds JSON test data for example GitHub API responses Signed-off-by: Jennifer Power --- .../json/github_example_pull_response.json | 371 ++++++++++++++++++ .../json/github_example_repo_response.json | 114 ++++++ 2 files changed, 485 insertions(+) create mode 100644 tests/data/json/github_example_pull_response.json create mode 100644 tests/data/json/github_example_repo_response.json diff --git a/tests/data/json/github_example_pull_response.json b/tests/data/json/github_example_pull_response.json new file mode 100644 index 00000000..c8e7363d --- /dev/null +++ b/tests/data/json/github_example_pull_response.json @@ -0,0 +1,371 @@ +{ + "url": "https://api.github.com/repos/owner/repo/pulls/123", + "id": 1, + "node_id": "MDExOlB1bGxSZXF1ZXN0MQ==", + "html_url": "https://github.com/owner/repo/pull/123", + "diff_url": "https://github.com/owner/repo/pull/123.diff", + "patch_url": "https://github.com/owner/repo/pull/123.patch", + "issue_url": "https://api.github.com/repos/owner/repo/issues/123", + "commits_url": "https://api.github.com/repos/owner/repo/pulls/123/commits", + "review_comments_url": "https://api.github.com/repos/owner/repo/pulls/123/comments", + "review_comment_url": "https://api.github.com/repos/owner/repo/pulls/comments{/number}", + "comments_url": "https://api.github.com/repos/owner/repo/issues/123/comments", + "statuses_url": "https://api.github.com/repos/owner/repo/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", + "number": 123, + "state": "open", + "locked": true, + "title": "Amazing new feature", + "user": { + "login": "owner", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/owner_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/owner", + "html_url": "https://github.com/owner", + "followers_url": "https://api.github.com/users/owner/followers", + "following_url": "https://api.github.com/users/owner/following{/other_user}", + "gists_url": "https://api.github.com/users/owner/gists{/gist_id}", + "starred_url": "https://api.github.com/users/owner/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/owner/subscriptions", + "organizations_url": "https://api.github.com/users/owner/orgs", + "repos_url": "https://api.github.com/users/owner/repos", + "events_url": "https://api.github.com/users/owner/events{/privacy}", + "received_events_url": "https://api.github.com/users/owner/received_events", + "type": "User", + "site_admin": false + }, + "body": "Please pull these awesome changes in!", + "body_html": "Please pull these awesome changes in!", + "body_text": "Please pull these awesome changes in!", + "labels": [], + "milestone": {}, + "active_lock_reason": "too heated", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:01:12Z", + "closed_at": "2011-01-26T19:01:12Z", + "merged_at": "2011-01-26T19:01:12Z", + "merge_commit_sha": "e5bd3914e2e596debea16f433f57875b5b90bcd6", + "assignee": { + "login": "owner", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/owner_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/owner", + "html_url": "https://github.com/owner", + "followers_url": "https://api.github.com/users/owner/followers", + "following_url": "https://api.github.com/users/owner/following{/other_user}", + "gists_url": "https://api.github.com/users/owner/gists{/gist_id}", + "starred_url": "https://api.github.com/users/owner/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/owner/subscriptions", + "organizations_url": "https://api.github.com/users/owner/orgs", + "repos_url": "https://api.github.com/users/owner/repos", + "events_url": "https://api.github.com/users/owner/events{/privacy}", + "received_events_url": "https://api.github.com/users/owner/received_events", + "type": "User", + "site_admin": false + }, + "assignees": [], + "requested_reviewers": [], + "requested_teams": [], + "head": { + "label": "owner:new-topic", + "ref": "new-topic", + "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e", + "user": { + "login": "owner", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/owner_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/owner", + "html_url": "https://github.com/owner", + "followers_url": "https://api.github.com/users/owner/followers", + "following_url": "https://api.github.com/users/owner/following{/other_user}", + "gists_url": "https://api.github.com/users/owner/gists{/gist_id}", + "starred_url": "https://api.github.com/users/owner/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/owner/subscriptions", + "organizations_url": "https://api.github.com/users/owner/orgs", + "repos_url": "https://api.github.com/users/owner/repos", + "events_url": "https://api.github.com/users/owner/events{/privacy}", + "received_events_url": "https://api.github.com/users/owner/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 654286523, + "node_id": "R_kgDOJv-euw", + "name": "repo", + "full_name": "owner/repo", + "private": false, + "owner": { + "login": "owner", + "id": 8826520, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjg4MjY1MjA=", + "avatar_url": "https://avatars.githubusercontent.com/u/8826520?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/owner", + "html_url": "https://github.com/owner", + "followers_url": "https://api.github.com/users/owner/followers", + "following_url": "https://api.github.com/users/owner/following{/other_user}", + "gists_url": "https://api.github.com/users/owner/gists{/gist_id}", + "starred_url": "https://api.github.com/users/owner/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/owner/subscriptions", + "organizations_url": "https://api.github.com/users/owner/orgs", + "repos_url": "https://api.github.com/users/owner/repos", + "events_url": "https://api.github.com/users/owner/events{/privacy}", + "received_events_url": "https://api.github.com/users/owner/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/owner/repo", + "description": "A workflow automation tool for `compliance-trestle`", + "fork": false, + "url": "https://api.github.com/repos/owner/repo", + "forks_url": "https://api.github.com/repos/owner/repo/forks", + "keys_url": "https://api.github.com/repos/owner/repo/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/owner/repo/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/owner/repo/teams", + "hooks_url": "https://api.github.com/repos/owner/repo/hooks", + "issue_events_url": "https://api.github.com/repos/owner/repo/issues/events{/number}", + "events_url": "https://api.github.com/repos/owner/repo/events", + "assignees_url": "https://api.github.com/repos/owner/repo/assignees{/user}", + "branches_url": "https://api.github.com/repos/owner/repo/branches{/branch}", + "tags_url": "https://api.github.com/repos/owner/repo/tags", + "blobs_url": "https://api.github.com/repos/owner/repo/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/owner/repo/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/owner/repo/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/owner/repo/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/owner/repo/statuses/{sha}", + "languages_url": "https://api.github.com/repos/owner/repo/languages", + "stargazers_url": "https://api.github.com/repos/owner/repo/stargazers", + "contributors_url": "https://api.github.com/repos/owner/repo/contributors", + "subscribers_url": "https://api.github.com/repos/owner/repo/subscribers", + "subscription_url": "https://api.github.com/repos/owner/repo/subscription", + "commits_url": "https://api.github.com/repos/owner/repo/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/owner/repo/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/owner/repo/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/owner/repo/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/owner/repo/contents/{+path}", + "compare_url": "https://api.github.com/repos/owner/repo/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/owner/repo/merges", + "archive_url": "https://api.github.com/repos/owner/repo/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/owner/repo/downloads", + "issues_url": "https://api.github.com/repos/owner/repo/issues{/number}", + "pulls_url": "https://api.github.com/repos/owner/repo/pulls{/number}", + "milestones_url": "https://api.github.com/repos/owner/repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/owner/repo/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/owner/repo/labels{/name}", + "releases_url": "https://api.github.com/repos/owner/repo/releases{/id}", + "deployments_url": "https://api.github.com/repos/owner/repo/deployments", + "created_at": "2023-06-15T19:44:03Z", + "updated_at": "2023-10-30T20:55:12Z", + "pushed_at": "2023-12-07T15:36:41Z", + "git_url": "git://github.com/owner/repo.git", + "ssh_url": "git@github.com:owner/repo.git", + "clone_url": "https://github.com/owner/repo.git", + "svn_url": "https://github.com/owner/repo", + "homepage": "", + "size": 673, + "stargazers_count": 4, + "watchers_count": 4, + "language": "Python", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": true, + "forks_count": 3, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 10, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 3, + "open_issues": 10, + "watchers": 4, + "default_branch": "main", + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_auto_merge": true, + "delete_branch_on_merge": false, + "allow_update_branch": true, + "use_squash_pr_title_as_default": false, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "network_count": 3, + "subscribers_count": 6 + } + }, + "base": { + "label": "owner:main", + "ref": "main", + "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e", + "user": { + "login": "owner", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/owner_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/owner", + "html_url": "https://github.com/owner", + "followers_url": "https://api.github.com/users/owner/followers", + "following_url": "https://api.github.com/users/owner/following{/other_user}", + "gists_url": "https://api.github.com/users/owner/gists{/gist_id}", + "starred_url": "https://api.github.com/users/owner/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/owner/subscriptions", + "organizations_url": "https://api.github.com/users/owner/orgs", + "repos_url": "https://api.github.com/users/owner/repos", + "events_url": "https://api.github.com/users/owner/events{/privacy}", + "received_events_url": "https://api.github.com/users/owner/received_events", + "type": "User", + "site_admin": false + }, + "repo": { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "repo", + "full_name": "owner/repo", + "owner": { + "login": "owner", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/owner_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/owner", + "html_url": "https://github.com/owner", + "followers_url": "https://api.github.com/users/owner/followers", + "following_url": "https://api.github.com/users/owner/following{/other_user}", + "gists_url": "https://api.github.com/users/owner/gists{/gist_id}", + "starred_url": "https://api.github.com/users/owner/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/owner/subscriptions", + "organizations_url": "https://api.github.com/users/owner/orgs", + "repos_url": "https://api.github.com/users/owner/repos", + "events_url": "https://api.github.com/users/owner/events{/privacy}", + "received_events_url": "https://api.github.com/users/owner/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/owner/repo", + "description": "This your first repo!", + "fork": false, + "url": "https://api.github.com/repos/owner/repo", + "archive_url": "https://api.github.com/repos/owner/repo/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/owner/repo/assignees{/user}", + "blobs_url": "https://api.github.com/repos/owner/repo/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/owner/repo/branches{/branch}", + "collaborators_url": "https://api.github.com/repos/owner/repo/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/owner/repo/comments{/number}", + "commits_url": "https://api.github.com/repos/owner/repo/commits{/sha}", + "compare_url": "https://api.github.com/repos/owner/repo/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/owner/repo/contents/{+path}", + "contributors_url": "https://api.github.com/repos/owner/repo/contributors", + "deployments_url": "https://api.github.com/repos/owner/repo/deployments", + "downloads_url": "https://api.github.com/repos/owner/repo/downloads", + "events_url": "https://api.github.com/repos/owner/repo/events", + "forks_url": "https://api.github.com/repos/owner/repo/forks", + "git_commits_url": "https://api.github.com/repos/owner/repo/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/owner/repo/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/owner/repo/git/tags{/sha}", + "git_url": "git:github.com/owner/repo.git", + "issue_comment_url": "https://api.github.com/repos/owner/repo/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/owner/repo/issues/events{/number}", + "issues_url": "https://api.github.com/repos/owner/repo/issues{/number}", + "keys_url": "https://api.github.com/repos/owner/repo/keys{/key_id}", + "labels_url": "https://api.github.com/repos/owner/repo/labels{/name}", + "languages_url": "https://api.github.com/repos/owner/repo/languages", + "merges_url": "https://api.github.com/repos/owner/repo/merges", + "milestones_url": "https://api.github.com/repos/owner/repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/owner/repo/notifications{?since,all,participating}", + "pulls_url": "https://api.github.com/repos/owner/repo/pulls{/number}", + "releases_url": "https://api.github.com/repos/owner/repo/releases{/id}", + "ssh_url": "git@github.com:owner/repo.git", + "stargazers_url": "https://api.github.com/repos/owner/repo/stargazers", + "statuses_url": "https://api.github.com/repos/owner/repo/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/owner/repo/subscribers", + "subscription_url": "https://api.github.com/repos/owner/repo/subscription", + "tags_url": "https://api.github.com/repos/owner/repo/tags", + "teams_url": "https://api.github.com/repos/owner/repo/teams", + "trees_url": "https://api.github.com/repos/owner/repo/git/trees{/sha}", + "clone_url": "https://github.com/owner/repo.git", + "mirror_url": "git:git.example.com/owner/repo", + "hooks_url": "https://api.github.com/repos/owner/repo/hooks", + "svn_url": "https://svn.github.com/owner/repo", + "homepage": "https://github.com", + "language": null, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "size": 108, + "default_branch": "main", + "open_issues_count": 0, + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "has_discussions": false, + "archived": false, + "disabled": false, + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_merge_commit": true, + "forks": 123, + "open_issues": 123, + "watchers": 123 + } + }, + "_links": { + "self": { + "href": "https://api.github.com/repos/owner/repo/pulls/123" + }, + "html": { + "href": "https://github.com/owner/repo/pull/123" + }, + "issue": { + "href": "https://api.github.com/repos/owner/repo/issues/123" + }, + "comments": { + "href": "https://api.github.com/repos/owner/repo/issues/123/comments" + }, + "review_comments": { + "href": "https://api.github.com/repos/owner/repo/pulls/123/comments" + }, + "review_comment": { + "href": "https://api.github.com/repos/owner/repo/pulls/comments{/number}" + }, + "commits": { + "href": "https://api.github.com/repos/owner/repo/pulls/123/commits" + }, + "statuses": { + "href": "https://api.github.com/repos/owner/repo/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e" + } + }, + "author_association": "OWNER", + "auto_merge": null, + "draft": false, + "merged": false, + "mergeable": true, + "rebaseable": true, + "mergeable_state": "clean", + "comments": 10, + "review_comments": 0, + "maintainer_can_modify": true, + "commits": 3, + "additions": 100, + "deletions": 3, + "changed_files": 5 +} \ No newline at end of file diff --git a/tests/data/json/github_example_repo_response.json b/tests/data/json/github_example_repo_response.json new file mode 100644 index 00000000..dd692805 --- /dev/null +++ b/tests/data/json/github_example_repo_response.json @@ -0,0 +1,114 @@ +{ + "id": 654286523, + "node_id": "R_kgDOJv-euw", + "name": "repo", + "full_name": "owner/repo", + "private": false, + "owner": { + "login": "owner", + "id": 8826520, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjg4MjY1MjA=", + "avatar_url": "https://avatars.githubusercontent.com/u/8826520?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/owner", + "html_url": "https://github.com/owner", + "followers_url": "https://api.github.com/users/owner/followers", + "following_url": "https://api.github.com/users/owner/following{/other_user}", + "gists_url": "https://api.github.com/users/owner/gists{/gist_id}", + "starred_url": "https://api.github.com/users/owner/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/owner/subscriptions", + "organizations_url": "https://api.github.com/users/owner/orgs", + "repos_url": "https://api.github.com/users/owner/repos", + "events_url": "https://api.github.com/users/owner/events{/privacy}", + "received_events_url": "https://api.github.com/users/owner/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/owner/repo", + "description": "An example project", + "fork": false, + "url": "https://api.github.com/repos/owner/repo", + "forks_url": "https://api.github.com/repos/owner/repo/forks", + "keys_url": "https://api.github.com/repos/owner/repo/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/owner/repo/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/owner/repo/teams", + "hooks_url": "https://api.github.com/repos/owner/repo/hooks", + "issue_events_url": "https://api.github.com/repos/owner/repo/issues/events{/number}", + "events_url": "https://api.github.com/repos/owner/repo/events", + "assignees_url": "https://api.github.com/repos/owner/repo/assignees{/user}", + "branches_url": "https://api.github.com/repos/owner/repo/branches{/branch}", + "tags_url": "https://api.github.com/repos/owner/repo/tags", + "blobs_url": "https://api.github.com/repos/owner/repo/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/owner/repo/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/owner/repo/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/owner/repo/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/owner/repo/statuses/{sha}", + "languages_url": "https://api.github.com/repos/owner/repo/languages", + "stargazers_url": "https://api.github.com/repos/owner/repo/stargazers", + "contributors_url": "https://api.github.com/repos/owner/repo/contributors", + "subscribers_url": "https://api.github.com/repos/owner/repo/subscribers", + "subscription_url": "https://api.github.com/repos/owner/repo/subscription", + "commits_url": "https://api.github.com/repos/owner/repo/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/owner/repo/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/owner/repo/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/owner/repo/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/owner/repo/contents/{+path}", + "compare_url": "https://api.github.com/repos/owner/repo/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/owner/repo/merges", + "archive_url": "https://api.github.com/repos/owner/repo/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/owner/repo/downloads", + "issues_url": "https://api.github.com/repos/owner/repo/issues{/number}", + "pulls_url": "https://api.github.com/repos/owner/repo/pulls{/number}", + "milestones_url": "https://api.github.com/repos/owner/repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/owner/repo/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/owner/repo/labels{/name}", + "releases_url": "https://api.github.com/repos/owner/repo/releases{/id}", + "deployments_url": "https://api.github.com/repos/owner/repo/deployments", + "created_at": "2023-06-15T19:44:03Z", + "updated_at": "2023-10-30T20:55:12Z", + "pushed_at": "2023-12-07T15:36:41Z", + "git_url": "git://github.com/owner/repo.git", + "ssh_url": "git@github.com:owner/repo.git", + "clone_url": "https://github.com/owner/repo.git", + "svn_url": "https://github.com/owner/repo", + "homepage": "", + "size": 673, + "stargazers_count": 4, + "watchers_count": 4, + "language": "Python", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": true, + "forks_count": 3, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 10, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 3, + "open_issues": 10, + "watchers": 4, + "default_branch": "main", + "permissions": {}, + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_auto_merge": true, + "delete_branch_on_merge": false, + "allow_update_branch": true, + "use_squash_pr_title_as_default": false, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "network_count": 3, + "subscribers_count": 6 + } + \ No newline at end of file From 9146e02b8e05d97af94998eb33a8786e6698eebd Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Thu, 7 Dec 2023 15:12:58 -0500 Subject: [PATCH 4/5] test: add test with RequestsMock for create_pull_request in test_github.py Signed-off-by: Jennifer Power --- tests/trestlebot/test_github.py | 43 +++++++++++++++++++++++++++++++-- tests/trestlebot/test_gitlab.py | 2 +- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/trestlebot/test_github.py b/tests/trestlebot/test_github.py index 8948cb11..13f43fec 100644 --- a/tests/trestlebot/test_github.py +++ b/tests/trestlebot/test_github.py @@ -16,13 +16,16 @@ """Test for GitHub provider logic""" -from typing import Tuple +import json +import re +from typing import Generator, Tuple from unittest.mock import patch import pytest from git.repo import Repo +from responses import GET, POST, RequestsMock -from tests.testutils import clean +from tests.testutils import JSON_TEST_DATA_PATH, clean from trestlebot.github import GitHub from trestlebot.provider import GitProviderException @@ -73,6 +76,42 @@ def test_parse_repository_with_incorrect_name() -> None: gh.parse_repository("https://notgithub.com/owner/repo.git") +@pytest.fixture +def resp_merge_requests() -> Generator[RequestsMock, None, None]: + """Mock the GitHub API for pull request creation""" + repo_content = json.load( + open(JSON_TEST_DATA_PATH / "github_example_repo_response.json") + ) + pr_content = json.load( + open(JSON_TEST_DATA_PATH / "github_example_pull_response.json") + ) + with RequestsMock() as rsps: + rsps.add( + method=POST, + url=re.compile(r"https://api.github.com/repos/owner/repo/pulls"), + json=pr_content, + content_type="application/json", + status=201, + ) + rsps.add( + method=GET, + url=re.compile(r"https://api.github.com/repos/owner/repo"), + json=repo_content, + content_type="application/json", + status=200, + ) + yield rsps + + +def test_create_pull_request(resp_merge_requests: RequestsMock) -> None: + """Test creating a pull request""" + gh = GitHub("fake") + pr_number = gh.create_pull_request( + "owner", "repo", "main", "test", "My PR", "Has Changes" + ) + assert pr_number == 123 + + def test_create_pull_request_invalid_repo() -> None: """Test triggering an error during pull request creation""" gh = GitHub("fake") diff --git a/tests/trestlebot/test_gitlab.py b/tests/trestlebot/test_gitlab.py index 2fe4878c..2443cd5e 100644 --- a/tests/trestlebot/test_gitlab.py +++ b/tests/trestlebot/test_gitlab.py @@ -135,7 +135,7 @@ def resp_merge_requests() -> Generator[RequestsMock, None, None]: url=re.compile(r"http://localhost/api/v4/projects/1/merge_requests"), json=mr_content, content_type="application/json", - status=200, + status=201, ) rsps.add( method=GET, From 12cc09324f3788fe966e909d19bf1a9e0f9bd07c Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Thu, 7 Dec 2023 16:10:50 -0500 Subject: [PATCH 5/5] fix: removes regexp for urls in test_gitlab.py and test_github.py files Signed-off-by: Jennifer Power --- tests/trestlebot/test_github.py | 5 ++--- tests/trestlebot/test_gitlab.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/trestlebot/test_github.py b/tests/trestlebot/test_github.py index 13f43fec..78b6d21c 100644 --- a/tests/trestlebot/test_github.py +++ b/tests/trestlebot/test_github.py @@ -17,7 +17,6 @@ """Test for GitHub provider logic""" import json -import re from typing import Generator, Tuple from unittest.mock import patch @@ -88,14 +87,14 @@ def resp_merge_requests() -> Generator[RequestsMock, None, None]: with RequestsMock() as rsps: rsps.add( method=POST, - url=re.compile(r"https://api.github.com/repos/owner/repo/pulls"), + url="https://api.github.com/repos/owner/repo/pulls", json=pr_content, content_type="application/json", status=201, ) rsps.add( method=GET, - url=re.compile(r"https://api.github.com/repos/owner/repo"), + url="https://api.github.com/repos/owner/repo", json=repo_content, content_type="application/json", status=200, diff --git a/tests/trestlebot/test_gitlab.py b/tests/trestlebot/test_gitlab.py index 2443cd5e..57e81110 100644 --- a/tests/trestlebot/test_gitlab.py +++ b/tests/trestlebot/test_gitlab.py @@ -16,7 +16,6 @@ """Test for GitLab provider logic""" -import re from typing import Callable, Generator, Tuple from unittest.mock import patch @@ -132,14 +131,14 @@ def resp_merge_requests() -> Generator[RequestsMock, None, None]: with RequestsMock() as rsps: rsps.add( method=POST, - url=re.compile(r"http://localhost/api/v4/projects/1/merge_requests"), + url="http://localhost/api/v4/projects/1/merge_requests", json=mr_content, content_type="application/json", status=201, ) rsps.add( method=GET, - url=re.compile(r"http://localhost/api/v4/projects/owner%2Frepo"), + url="http://localhost/api/v4/projects/owner%2Frepo", json={"name": "name", "id": 1}, content_type="application/json", status=200,