test: mock github API calls (#21450)

[skip ci]
This commit is contained in:
Ankush Menat 2023-06-21 16:33:09 +05:30 committed by GitHub
parent 7d352d7c34
commit b3840596fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -20,7 +20,7 @@ from PIL import Image
import frappe
from frappe.installer import parse_app_name
from frappe.model.document import Document
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.tests.utils import FrappeTestCase, MockedRequestTestCase, change_settings
from frappe.utils import (
ceil,
dict_to_str,
@ -815,8 +815,14 @@ class TestLinkTitle(FrappeTestCase):
prop_setter.delete()
class TestAppParser(FrappeTestCase):
class TestAppParser(MockedRequestTestCase):
def test_app_name_parser(self):
self.responses.add(
"HEAD",
"https://api.github.com/repos/frappe/healthcare",
status=200,
json={},
)
bench_path = get_bench_path()
frappe_app = os.path.join(bench_path, "apps", "frappe")
self.assertEqual("frappe", parse_app_name(frappe_app))

View file

@ -93,6 +93,19 @@ class FrappeTestCase(unittest.TestCase):
frappe.db.sql = orig_sql
class MockedRequestTestCase(FrappeTestCase):
def setUp(self):
import responses
self.responses = responses.RequestsMock()
self.responses.start()
self.addCleanup(self.responses.stop)
self.addCleanup(self.responses.reset)
return super().setUp()
def _commit_watcher():
import traceback