Add some simple cli tests

This commit is contained in:
Torjus Håkestad 2025-01-06 22:25:16 +01:00
parent 28b6695206
commit c2641ad961
Signed by: torjus
SSH Key Fingerprint: SHA256:KjAds8wHfD2mBYK2H815s/+ABcSdcIHUndwHEdSxml4
3 changed files with 407 additions and 0 deletions

177
tests/fixtures/comments_345583.json vendored Normal file
View File

@ -0,0 +1,177 @@
[
{
"url": "https://api.github.com/repos/NixOS/nixpkgs/issues/comments/2388655041",
"html_url": "https://github.com/NixOS/nixpkgs/pull/345769#issuecomment-2388655041",
"issue_url": "https://api.github.com/repos/NixOS/nixpkgs/issues/345769",
"id": 2388655041,
"node_id": "IC_kwDOAEVQ_M6OX_vB",
"user": {
"login": "mweinelt",
"id": 131599,
"node_id": "MDQ6VXNlcjEzMTU5OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/131599?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mweinelt",
"html_url": "https://github.com/mweinelt",
"followers_url": "https://api.github.com/users/mweinelt/followers",
"following_url": "https://api.github.com/users/mweinelt/following{/other_user}",
"gists_url": "https://api.github.com/users/mweinelt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mweinelt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mweinelt/subscriptions",
"organizations_url": "https://api.github.com/users/mweinelt/orgs",
"repos_url": "https://api.github.com/users/mweinelt/repos",
"events_url": "https://api.github.com/users/mweinelt/events{/privacy}",
"received_events_url": "https://api.github.com/users/mweinelt/received_events",
"type": "User",
"site_admin": false
},
"created_at": "2024-10-02T13:31:48Z",
"updated_at": "2024-10-02T13:31:48Z",
"author_association": "MEMBER",
"body_text": "@ofborg build firefox-unwrapped.tests",
"reactions": {
"url": "https://api.github.com/repos/NixOS/nixpkgs/issues/comments/2388655041/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"performed_via_github_app": null
},
{
"url": "https://api.github.com/repos/NixOS/nixpkgs/issues/comments/2389811254",
"html_url": "https://github.com/NixOS/nixpkgs/pull/345769#issuecomment-2389811254",
"issue_url": "https://api.github.com/repos/NixOS/nixpkgs/issues/345769",
"id": 2389811254,
"node_id": "IC_kwDOAEVQ_M6OcaA2",
"user": {
"login": "github-actions[bot]",
"id": 41898282,
"node_id": "MDM6Qm90NDE4OTgyODI=",
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
"html_url": "https://github.com/apps/github-actions",
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
"type": "Bot",
"site_admin": false
},
"created_at": "2024-10-02T22:45:02Z",
"updated_at": "2024-10-02T22:45:02Z",
"author_association": "CONTRIBUTOR",
"body_text": "Successfully created backport PR for `release-24.05`:\n\n#346022",
"reactions": {
"url": "https://api.github.com/repos/NixOS/nixpkgs/issues/comments/2389811254/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"performed_via_github_app": {
"id": 15368,
"client_id": "Iv1.05c79e9ad1f6bdfa",
"slug": "github-actions",
"node_id": "MDM6QXBwMTUzNjg=",
"owner": {
"login": "github",
"id": 9919,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github",
"html_url": "https://github.com/github",
"followers_url": "https://api.github.com/users/github/followers",
"following_url": "https://api.github.com/users/github/following{/other_user}",
"gists_url": "https://api.github.com/users/github/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github/subscriptions",
"organizations_url": "https://api.github.com/users/github/orgs",
"repos_url": "https://api.github.com/users/github/repos",
"events_url": "https://api.github.com/users/github/events{/privacy}",
"received_events_url": "https://api.github.com/users/github/received_events",
"type": "Organization",
"site_admin": false
},
"name": "GitHub Actions",
"description": "Automate your workflow from idea to production",
"external_url": "https://help.github.com/en/actions",
"html_url": "https://github.com/apps/github-actions",
"created_at": "2018-07-30T09:30:17Z",
"updated_at": "2024-04-10T20:33:16Z",
"permissions": {
"actions": "write",
"administration": "read",
"attestations": "write",
"checks": "write",
"contents": "write",
"deployments": "write",
"discussions": "write",
"issues": "write",
"merge_queues": "write",
"metadata": "read",
"packages": "write",
"pages": "write",
"pull_requests": "write",
"repository_hooks": "write",
"repository_projects": "write",
"security_events": "write",
"statuses": "write",
"vulnerability_alerts": "read"
},
"events": [
"branch_protection_rule",
"check_run",
"check_suite",
"create",
"delete",
"deployment",
"deployment_status",
"discussion",
"discussion_comment",
"fork",
"gollum",
"issues",
"issue_comment",
"label",
"merge_group",
"milestone",
"page_build",
"project",
"project_card",
"project_column",
"public",
"pull_request",
"pull_request_review",
"pull_request_review_comment",
"push",
"registry_package",
"release",
"repository",
"repository_dispatch",
"status",
"watch",
"workflow_dispatch",
"workflow_run"
]
}
}
]

View File

@ -0,0 +1,180 @@
{
"url": "https://api.github.com/repos/NixOS/nixpkgs/compare/nixos-unstable...2c5fac3edf2d00d948253e392ec1604b29b38f14",
"html_url": "https://github.com/NixOS/nixpkgs/compare/nixos-unstable...2c5fac3edf2d00d948253e392ec1604b29b38f14",
"permalink_url": "https://github.com/NixOS/nixpkgs/compare/NixOS:bc947f5...NixOS:2c5fac3",
"diff_url": "https://github.com/NixOS/nixpkgs/compare/nixos-unstable...2c5fac3edf2d00d948253e392ec1604b29b38f14.diff",
"patch_url": "https://github.com/NixOS/nixpkgs/compare/nixos-unstable...2c5fac3edf2d00d948253e392ec1604b29b38f14.patch",
"base_commit": {
"sha": "bc947f541ae55e999ffdb4013441347d83b00feb",
"node_id": "C_kwDOAEVQ_NoAKGJjOTQ3ZjU0MWFlNTVlOTk5ZmZkYjQwMTM0NDEzNDdkODNiMDBmZWI",
"commit": {
"author": {
"name": "Masum Reza",
"email": "50095635+JohnRTitor@users.noreply.github.com",
"date": "2024-10-04T05:06:13Z"
},
"committer": {
"name": "GitHub",
"email": "noreply@github.com",
"date": "2024-10-04T05:06:13Z"
},
"message": "alpaca: 2.0.3 -> 2.0.5 (#345070)",
"tree": {
"sha": "3e7376cebbaf8793c39bb68447950f1045fd4ea5",
"url": "https://api.github.com/repos/NixOS/nixpkgs/git/trees/3e7376cebbaf8793c39bb68447950f1045fd4ea5"
},
"url": "https://api.github.com/repos/NixOS/nixpkgs/git/commits/bc947f541ae55e999ffdb4013441347d83b00feb",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"signature": "-----BEGIN PGP SIGNATURE-----\n\nwsFcBAABCAAQBQJm/3fFCRC1aQ7uu5UhlAAA2JMQAIz5pfsohrsrdPgPxlZVDuaQ\nVPLlM82MOpkq958U90OnXyC4ZlIX2+YwvCUkuRjYjMv9VlHMHU6olHy/jvt5VF/g\nckoaAMztOsPqgyKUXiMew83j8L8EBqVQQZ3W2Br9EnzG2RNEDUQdP5c6Fwc4tccl\nmb3PPb15Nm0lFnitwUO78KxILhrekjdxxrKC/wUihaL/gH4CzdkReVZJ6FPbq9l6\n/HTTDW+amrpOr2XLQ2dC5Cy/nvZS+MPjduNSPsf5a5/ElKmNltbPFChTY0pnv/dq\nrH1zDsohfbtk5WgcmLhiIOpvO86yLfa82sPUJA65GuAW7gYGbMsN6Sh3CnfY7sxb\n7x5r7/sSodxG4t2lML571JfX2aFCeNKgeYomViRu1ZGyHg3LJAN8jKi1JIyVCpH1\nkiTOmQQWzPJRC2COvMGSdXVc7h4CuInev7MmDDiubJDkFYyT8DBzpqVxUTmni13p\ndwr6QAWZZpjnxZxVFnYLlTSifLUIazEJTqaNWnCCc99hyWAo+f5njUlT+9fPLoKE\nHAgMmC55sOzOXnLLgPIoZe2g3wtHNELY3Y6wq7hfS2K9GCxJnJ3mttiUypnyHEuR\n/dVGOlES5p7xWUZ+zEYOp+cLnMWudB5X5cf/ojooLQJc8CL8gIfOD7KOrKewf2Yi\nUUUYH6/erCgoQE2klAaS\n=Hu+V\n-----END PGP SIGNATURE-----\n",
"payload": "tree 3e7376cebbaf8793c39bb68447950f1045fd4ea5\nparent 674acd883193175de91d37a6b3ea8c814d12c8bb\nparent e229318f7d34f4988a815e6d10b8fb0f7e0e2974\nauthor Masum Reza <50095635+JohnRTitor@users.noreply.github.com> 1728018373 +0530\ncommitter GitHub <noreply@github.com> 1728018373 +0530\n\nalpaca: 2.0.3 -> 2.0.5 (#345070)\n\n"
}
},
"url": "https://api.github.com/repos/NixOS/nixpkgs/commits/bc947f541ae55e999ffdb4013441347d83b00feb",
"html_url": "https://github.com/NixOS/nixpkgs/commit/bc947f541ae55e999ffdb4013441347d83b00feb",
"comments_url": "https://api.github.com/repos/NixOS/nixpkgs/commits/bc947f541ae55e999ffdb4013441347d83b00feb/comments",
"author": {
"login": "JohnRTitor",
"id": 50095635,
"node_id": "MDQ6VXNlcjUwMDk1NjM1",
"avatar_url": "https://avatars.githubusercontent.com/u/50095635?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/JohnRTitor",
"html_url": "https://github.com/JohnRTitor",
"followers_url": "https://api.github.com/users/JohnRTitor/followers",
"following_url": "https://api.github.com/users/JohnRTitor/following{/other_user}",
"gists_url": "https://api.github.com/users/JohnRTitor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/JohnRTitor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/JohnRTitor/subscriptions",
"organizations_url": "https://api.github.com/users/JohnRTitor/orgs",
"repos_url": "https://api.github.com/users/JohnRTitor/repos",
"events_url": "https://api.github.com/users/JohnRTitor/events{/privacy}",
"received_events_url": "https://api.github.com/users/JohnRTitor/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "web-flow",
"id": 19864447,
"node_id": "MDQ6VXNlcjE5ODY0NDQ3",
"avatar_url": "https://avatars.githubusercontent.com/u/19864447?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/web-flow",
"html_url": "https://github.com/web-flow",
"followers_url": "https://api.github.com/users/web-flow/followers",
"following_url": "https://api.github.com/users/web-flow/following{/other_user}",
"gists_url": "https://api.github.com/users/web-flow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/web-flow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/web-flow/subscriptions",
"organizations_url": "https://api.github.com/users/web-flow/orgs",
"repos_url": "https://api.github.com/users/web-flow/repos",
"events_url": "https://api.github.com/users/web-flow/events{/privacy}",
"received_events_url": "https://api.github.com/users/web-flow/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "674acd883193175de91d37a6b3ea8c814d12c8bb",
"url": "https://api.github.com/repos/NixOS/nixpkgs/commits/674acd883193175de91d37a6b3ea8c814d12c8bb",
"html_url": "https://github.com/NixOS/nixpkgs/commit/674acd883193175de91d37a6b3ea8c814d12c8bb"
},
{
"sha": "e229318f7d34f4988a815e6d10b8fb0f7e0e2974",
"url": "https://api.github.com/repos/NixOS/nixpkgs/commits/e229318f7d34f4988a815e6d10b8fb0f7e0e2974",
"html_url": "https://github.com/NixOS/nixpkgs/commit/e229318f7d34f4988a815e6d10b8fb0f7e0e2974"
}
]
},
"merge_base_commit": {
"sha": "2c5fac3edf2d00d948253e392ec1604b29b38f14",
"node_id": "C_kwDOAEVQ_NoAKDJjNWZhYzNlZGYyZDAwZDk0ODI1M2UzOTJlYzE2MDRiMjliMzhmMTQ",
"commit": {
"author": {
"name": "Thomas Gerbet",
"email": "thomas@gerbet.me",
"date": "2024-09-30T18:58:09Z"
},
"committer": {
"name": "Bjørn Forsman",
"email": "bjorn.forsman@gmail.com",
"date": "2024-10-01T06:56:48Z"
},
"message": "wireshark: 4.2.6 -> 4.2.7\n\nFixes CVE-2024-8250.\nhttps://www.wireshark.org/security/wnpa-sec-2024-11.html\n\nChanges:\nhttps://www.wireshark.org/docs/relnotes/wireshark-4.2.7.html",
"tree": {
"sha": "35384ecd1601439a960f3ef76a1974bb7784523f",
"url": "https://api.github.com/repos/NixOS/nixpkgs/git/trees/35384ecd1601439a960f3ef76a1974bb7784523f"
},
"url": "https://api.github.com/repos/NixOS/nixpkgs/git/commits/2c5fac3edf2d00d948253e392ec1604b29b38f14",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/NixOS/nixpkgs/commits/2c5fac3edf2d00d948253e392ec1604b29b38f14",
"html_url": "https://github.com/NixOS/nixpkgs/commit/2c5fac3edf2d00d948253e392ec1604b29b38f14",
"comments_url": "https://api.github.com/repos/NixOS/nixpkgs/commits/2c5fac3edf2d00d948253e392ec1604b29b38f14/comments",
"author": {
"login": "LeSuisse",
"id": 737767,
"node_id": "MDQ6VXNlcjczNzc2Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/737767?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/LeSuisse",
"html_url": "https://github.com/LeSuisse",
"followers_url": "https://api.github.com/users/LeSuisse/followers",
"following_url": "https://api.github.com/users/LeSuisse/following{/other_user}",
"gists_url": "https://api.github.com/users/LeSuisse/gists{/gist_id}",
"starred_url": "https://api.github.com/users/LeSuisse/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/LeSuisse/subscriptions",
"organizations_url": "https://api.github.com/users/LeSuisse/orgs",
"repos_url": "https://api.github.com/users/LeSuisse/repos",
"events_url": "https://api.github.com/users/LeSuisse/events{/privacy}",
"received_events_url": "https://api.github.com/users/LeSuisse/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "bjornfor",
"id": 133602,
"node_id": "MDQ6VXNlcjEzMzYwMg==",
"avatar_url": "https://avatars.githubusercontent.com/u/133602?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bjornfor",
"html_url": "https://github.com/bjornfor",
"followers_url": "https://api.github.com/users/bjornfor/followers",
"following_url": "https://api.github.com/users/bjornfor/following{/other_user}",
"gists_url": "https://api.github.com/users/bjornfor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bjornfor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bjornfor/subscriptions",
"organizations_url": "https://api.github.com/users/bjornfor/orgs",
"repos_url": "https://api.github.com/users/bjornfor/repos",
"events_url": "https://api.github.com/users/bjornfor/events{/privacy}",
"received_events_url": "https://api.github.com/users/bjornfor/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "92bdb0b4e0f698cdde010c2254cdb2afee6e07c3",
"url": "https://api.github.com/repos/NixOS/nixpkgs/commits/92bdb0b4e0f698cdde010c2254cdb2afee6e07c3",
"html_url": "https://github.com/NixOS/nixpkgs/commit/92bdb0b4e0f698cdde010c2254cdb2afee6e07c3"
}
]
},
"status": "behind",
"ahead_by": 0,
"behind_by": 918,
"total_commits": 0,
"commits": [
],
"files": [
]
}

View File

@ -1,3 +1,53 @@
import unittest
import unittest.mock
import json
from typer.testing import CliRunner
from nixprstatus.app import app
from tests.helpers.mocks import mocked_requests_get
runner = CliRunner()
class TestCli(unittest.TestCase):
def test_help(self):
result = runner.invoke(app, ["--help"])
self.assertEqual(result.exit_code, 0)
self.assertIn("Usage: root [OPTIONS] COMMAND [ARGS]...", result.output)
self.assertIn("--show-completion", result.output)
self.assertIn("Commands:", result.output)
self.assertIn("pr", result.output)
self.assertIn("watchlist", result.output)
self.assertIn("since", result.output)
def test_pr_help(self):
result = runner.invoke(app, ["pr", "--help"])
self.assertEqual(result.exit_code, 0)
self.assertIn("Usage: root pr [OPTIONS] PR..", result.output)
self.assertIn("Options:", result.output)
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_pr_single_simple(self, mock_get):
result = runner.invoke(app, ["pr", "345583"])
print(result.exception)
self.assertEqual(result.exit_code, 0)
self.assertIn("wireshark: 4.2.6 -> 4.2.7", result.output)
@unittest.mock.patch("requests.get", side_effect=mocked_requests_get)
def test_pr_single_json(self, mock_get):
result = runner.invoke(app, ["pr", "--format", "json", "345583"])
self.assertEqual(result.exit_code, 0)
expected = {
"title": "wireshark: 4.2.6 -> 4.2.7",
"merged": True,
"branches": {
"master": True,
"nixos-unstable-small": True,
"nixos-unstable": True,
"nixos-24.05 (#346022)": True,
},
}
output = json.loads(result.output)
self.assertEqual(output, expected)