2025-01-06 20:59:46 +00:00
|
|
|
import unittest
|
2025-01-06 21:25:16 +00:00
|
|
|
import unittest.mock
|
|
|
|
import json
|
|
|
|
|
|
|
|
from typer.testing import CliRunner
|
2025-01-06 20:59:46 +00:00
|
|
|
|
|
|
|
from nixprstatus.app import app
|
2025-01-06 21:25:16 +00:00
|
|
|
|
|
|
|
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,
|
2025-01-06 21:44:50 +00:00
|
|
|
"nixos-24.11": False,
|
2025-01-06 21:25:16 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
output = json.loads(result.output)
|
|
|
|
self.assertEqual(output, expected)
|