Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/django_github_app/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class SyncGitHubAPI(AsyncGitHubAPI):
delete = async_to_sync_method(AsyncGitHubAPI.delete) # type: ignore[arg-type]
graphql = async_to_sync_method(AsyncGitHubAPI.graphql)

@override # type: ignore[override]
def sleep(self, seconds: float) -> None:
@override
def sleep(self, seconds: float) -> None: # type: ignore[override]
raise NotImplementedError(
"sleep() is not supported in SyncGitHubAPI due to abstractmethod"
"gidgethub.abc.GitHubAPI.sleep's async requirements. "
Expand Down
2 changes: 1 addition & 1 deletion src/django_github_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class InstallationManager(models.Manager["Installation"]):
async def acreate_from_event(self, event: sansio.Event):
app_id = event.data["installation"]["app_id"]

if str(app_id) == app_settings.APP_ID:
if app_id == int(app_settings.APP_ID):
installation = await self.acreate_from_gh_data(event.data["installation"])

await Repository.objects.acreate_from_gh_data(
Expand Down
16 changes: 11 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django.test import override_settings
from django.urls import clear_url_caches
from django.urls import path
from model_bakery import baker

from django_github_app.conf import GITHUB_APP_SETTINGS_NAME
from django_github_app.github import AsyncGitHubAPI
Expand Down Expand Up @@ -63,6 +62,13 @@ def pytest_configure(config):
}


@pytest.fixture
def baker():
from model_bakery import baker

return baker


@pytest.fixture
def override_app_settings():
@contextlib.contextmanager
Expand Down Expand Up @@ -142,7 +148,7 @@ async def mock_getiter(*args, **kwargs):


@pytest.fixture
def installation(get_mock_github_api):
def installation(get_mock_github_api, baker):
installation = baker.make(
"django_github_app.Installation", installation_id=seq.next()
)
Expand All @@ -158,7 +164,7 @@ def installation(get_mock_github_api):


@pytest.fixture
async def ainstallation(get_mock_github_api):
async def ainstallation(get_mock_github_api, baker):
installation = await sync_to_async(baker.make)(
"django_github_app.Installation", installation_id=seq.next()
)
Expand All @@ -174,7 +180,7 @@ async def ainstallation(get_mock_github_api):


@pytest.fixture
def repository(installation, get_mock_github_api):
def repository(installation, get_mock_github_api, baker):
repository = baker.make(
"django_github_app.Repository",
repository_id=seq.next(),
Expand All @@ -201,7 +207,7 @@ def repository(installation, get_mock_github_api):


@pytest.fixture
async def arepository(ainstallation, get_mock_github_api):
async def arepository(ainstallation, get_mock_github_api, baker):
installation = await ainstallation
repository = await sync_to_async(baker.make)(
"django_github_app.Repository",
Expand Down
9 changes: 7 additions & 2 deletions tests/events/test_ainstallation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
pytestmark = [pytest.mark.asyncio, pytest.mark.django_db]


@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
async def test_acreate_installation(
installation_id, repository_id, override_app_settings
app_settings_app_id_type, installation_id, repository_id, override_app_settings
):
data = {
"installation": {
Expand All @@ -32,7 +33,11 @@ async def test_acreate_installation(
}
event = sansio.Event(data, event="installation", delivery_id="1234")

with override_app_settings(APP_ID=str(data["installation"]["app_id"])):
with override_app_settings(
APP_ID=data["installation"]["app_id"]
if isinstance(app_settings_app_id_type, int)
else str(data["installation"]["app_id"])
):
await acreate_installation(event, None)

installation = await Installation.objects.aget(
Expand Down
11 changes: 9 additions & 2 deletions tests/events/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
pytestmark = [pytest.mark.django_db]


def test_create_installation(installation_id, repository_id, override_app_settings):
@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
def test_create_installation(
app_settings_app_id_type, installation_id, repository_id, override_app_settings
):
data = {
"installation": {
"id": installation_id,
Expand All @@ -29,7 +32,11 @@ def test_create_installation(installation_id, repository_id, override_app_settin
}
event = sansio.Event(data, event="installation", delivery_id="1234")

with override_app_settings(APP_ID=str(data["installation"]["app_id"])):
with override_app_settings(
APP_ID=data["installation"]["app_id"]
if isinstance(app_settings_app_id_type, int)
else str(data["installation"]["app_id"])
):
create_installation(event, None)

installation = Installation.objects.get(installation_id=data["installation"]["id"])
Expand Down
22 changes: 18 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def test_action_property(self, payload, expected):

class TestInstallationManager:
@pytest.mark.asyncio
async def test_acreate_from_event(self, create_event, override_app_settings):
@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
async def test_acreate_from_event(
self, app_settings_app_id_type, create_event, override_app_settings
):
repositories = [
{"id": seq.next(), "node_id": "node1", "full_name": "owner/repo1"},
{"id": seq.next(), "node_id": "node2", "full_name": "owner/repo2"},
Expand All @@ -144,7 +147,11 @@ async def test_acreate_from_event(self, create_event, override_app_settings):
"installation",
)

with override_app_settings(APP_ID=str(installation_data["app_id"])):
with override_app_settings(
APP_ID=installation_data["app_id"]
if isinstance(app_settings_app_id_type, int)
else str(installation_data["app_id"])
):
installation = await Installation.objects.acreate_from_event(event)

assert installation.installation_id == installation_data["id"]
Expand All @@ -153,7 +160,10 @@ async def test_acreate_from_event(self, create_event, override_app_settings):
installation=installation
).acount() == len(repositories)

def test_create_from_event(self, create_event, override_app_settings):
@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
def test_create_from_event(
self, app_settings_app_id_type, create_event, override_app_settings
):
repositories = [
{"id": seq.next(), "node_id": "node1", "full_name": "owner/repo1"},
{"id": seq.next(), "node_id": "node2", "full_name": "owner/repo2"},
Expand All @@ -170,7 +180,11 @@ def test_create_from_event(self, create_event, override_app_settings):
"installation",
)

with override_app_settings(APP_ID=str(installation_data["app_id"])):
with override_app_settings(
APP_ID=installation_data["app_id"]
if isinstance(app_settings_app_id_type, int)
else str(installation_data["app_id"])
):
installation = Installation.objects.create_from_event(event)

assert installation.installation_id == installation_data["id"]
Expand Down