-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bd64f2
commit 20344e1
Showing
3 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Test RestRequest class.""" | ||
import unittest | ||
import responses | ||
|
||
from ghastoolkit.octokit.octokit import RestRequest | ||
from ghastoolkit.octokit.github import GitHub | ||
|
||
|
||
class TestRestRequest(unittest.TestCase): | ||
def setUp(self) -> None: | ||
GitHub.init(repository="GeekMasher/ghastoolkit@main") | ||
|
||
self.rest = RestRequest() | ||
|
||
return super().setUp() | ||
|
||
@responses.activate | ||
def test_errors(self): | ||
responses.add( | ||
responses.GET, | ||
"https://api.github.com/repos/GeekMasher/ghastoolkit/secret-scanning/alerts", | ||
json={ | ||
"message": "Secret scanning is disabled on this repository.", | ||
"documentation_url": "https://docs.github.com/rest/secret-scanning/secret-scanning", | ||
}, | ||
status=404, | ||
) | ||
responses.add( | ||
responses.GET, | ||
"https://api.github.com/repos/GeekMasher/ghastoolkit/secret-scanning/alerts/1", | ||
json={ | ||
"message": "Not Found", | ||
"documentation_url": "https://docs.github.com/rest/secret-scanning/secret-scanning", | ||
}, | ||
status=404, | ||
) | ||
|
||
with self.assertRaises(Exception): | ||
self.rest.get("/repos/{owner}/{repo}/secret-scanning/alerts") | ||
|
||
with self.assertRaises(Exception): | ||
self.rest.get("/repos/{owner}/{repo}/secret-scanning/alerts/1") | ||
|
||
@responses.activate | ||
def test_error_handler(self): | ||
responses.add( | ||
responses.GET, | ||
"https://api.github.com/repos/GeekMasher/ghastoolkit/secret-scanning/alerts", | ||
json={ | ||
"message": "Secret scanning is disabled on this repository.", | ||
"documentation_url": "https://docs.github.com/rest/secret-scanning/secret-scanning", | ||
}, | ||
status=404, | ||
) | ||
|
||
def handle(code, _): | ||
self.assertEqual(code, 404) | ||
|
||
self.rest.get( | ||
"/repos/{owner}/{repo}/secret-scanning/alerts", error_handler=handle | ||
) |