Skip to content

Commit

Permalink
feat: Add tests and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekMasher committed Feb 22, 2024
1 parent 8bd64f2 commit 20344e1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/ghastoolkit/octokit/octokit.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def get(
if expected and response.status_code != expected:
if display_errors:
logger.error(f"Error code from server :: {response.status_code}")
logger.error(f"Content :: {response_json}")

known_error = __OCTOKIT_ERRORS__.get(response.status_code)
if known_error:
Expand Down
9 changes: 7 additions & 2 deletions tests/test_octokit.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from dataclasses import dataclass, is_dataclass
import unittest

from ghastoolkit.octokit.octokit import OctoItem, Octokit, GraphQLRequest, loadOctoItem
from ghastoolkit.octokit.octokit import (
OctoItem,
Octokit,
GraphQLRequest,
loadOctoItem,
)
from ghastoolkit.octokit.github import GitHub


class TestOctokit(unittest.TestCase):
def setUp(self) -> None:
GitHub.init(repository="GeekMasher/ghastoolkit@main")
GitHub.init(repository="GeekMasher/ghastoolkit@main", token="1234567890")
return super().setUp()

def test_route(self):
Expand Down
61 changes: 61 additions & 0 deletions tests/test_restrequest.py
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
)

0 comments on commit 20344e1

Please sign in to comment.