Skip to content

Commit 8ed8df3

Browse files
convert APP_ID from settings to int to match GitHub event data (#62)
1 parent 34be3ab commit 8ed8df3

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

src/django_github_app/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class SyncGitHubAPI(AsyncGitHubAPI):
100100
delete = async_to_sync_method(AsyncGitHubAPI.delete) # type: ignore[arg-type]
101101
graphql = async_to_sync_method(AsyncGitHubAPI.graphql)
102102

103-
@override # type: ignore[override]
104-
def sleep(self, seconds: float) -> None:
103+
@override
104+
def sleep(self, seconds: float) -> None: # type: ignore[override]
105105
raise NotImplementedError(
106106
"sleep() is not supported in SyncGitHubAPI due to abstractmethod"
107107
"gidgethub.abc.GitHubAPI.sleep's async requirements. "

src/django_github_app/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class InstallationManager(models.Manager["Installation"]):
6565
async def acreate_from_event(self, event: sansio.Event):
6666
app_id = event.data["installation"]["app_id"]
6767

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

7171
await Repository.objects.acreate_from_gh_data(

tests/conftest.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from django.test import override_settings
1212
from django.urls import clear_url_caches
1313
from django.urls import path
14-
from model_bakery import baker
1514

1615
from django_github_app.conf import GITHUB_APP_SETTINGS_NAME
1716
from django_github_app.github import AsyncGitHubAPI
@@ -63,6 +62,13 @@ def pytest_configure(config):
6362
}
6463

6564

65+
@pytest.fixture
66+
def baker():
67+
from model_bakery import baker
68+
69+
return baker
70+
71+
6672
@pytest.fixture
6773
def override_app_settings():
6874
@contextlib.contextmanager
@@ -142,7 +148,7 @@ async def mock_getiter(*args, **kwargs):
142148

143149

144150
@pytest.fixture
145-
def installation(get_mock_github_api):
151+
def installation(get_mock_github_api, baker):
146152
installation = baker.make(
147153
"django_github_app.Installation", installation_id=seq.next()
148154
)
@@ -158,7 +164,7 @@ def installation(get_mock_github_api):
158164

159165

160166
@pytest.fixture
161-
async def ainstallation(get_mock_github_api):
167+
async def ainstallation(get_mock_github_api, baker):
162168
installation = await sync_to_async(baker.make)(
163169
"django_github_app.Installation", installation_id=seq.next()
164170
)
@@ -174,7 +180,7 @@ async def ainstallation(get_mock_github_api):
174180

175181

176182
@pytest.fixture
177-
def repository(installation, get_mock_github_api):
183+
def repository(installation, get_mock_github_api, baker):
178184
repository = baker.make(
179185
"django_github_app.Repository",
180186
repository_id=seq.next(),
@@ -201,7 +207,7 @@ def repository(installation, get_mock_github_api):
201207

202208

203209
@pytest.fixture
204-
async def arepository(ainstallation, get_mock_github_api):
210+
async def arepository(ainstallation, get_mock_github_api, baker):
205211
installation = await ainstallation
206212
repository = await sync_to_async(baker.make)(
207213
"django_github_app.Repository",

tests/events/test_ainstallation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
pytestmark = [pytest.mark.asyncio, pytest.mark.django_db]
1919

2020

21+
@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
2122
async def test_acreate_installation(
22-
installation_id, repository_id, override_app_settings
23+
app_settings_app_id_type, installation_id, repository_id, override_app_settings
2324
):
2425
data = {
2526
"installation": {
@@ -32,7 +33,11 @@ async def test_acreate_installation(
3233
}
3334
event = sansio.Event(data, event="installation", delivery_id="1234")
3435

35-
with override_app_settings(APP_ID=str(data["installation"]["app_id"])):
36+
with override_app_settings(
37+
APP_ID=data["installation"]["app_id"]
38+
if isinstance(app_settings_app_id_type, int)
39+
else str(data["installation"]["app_id"])
40+
):
3641
await acreate_installation(event, None)
3742

3843
installation = await Installation.objects.aget(

tests/events/test_installation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
pytestmark = [pytest.mark.django_db]
1818

1919

20-
def test_create_installation(installation_id, repository_id, override_app_settings):
20+
@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
21+
def test_create_installation(
22+
app_settings_app_id_type, installation_id, repository_id, override_app_settings
23+
):
2124
data = {
2225
"installation": {
2326
"id": installation_id,
@@ -29,7 +32,11 @@ def test_create_installation(installation_id, repository_id, override_app_settin
2932
}
3033
event = sansio.Event(data, event="installation", delivery_id="1234")
3134

32-
with override_app_settings(APP_ID=str(data["installation"]["app_id"])):
35+
with override_app_settings(
36+
APP_ID=data["installation"]["app_id"]
37+
if isinstance(app_settings_app_id_type, int)
38+
else str(data["installation"]["app_id"])
39+
):
3340
create_installation(event, None)
3441

3542
installation = Installation.objects.get(installation_id=data["installation"]["id"])

tests/test_models.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ def test_action_property(self, payload, expected):
127127

128128
class TestInstallationManager:
129129
@pytest.mark.asyncio
130-
async def test_acreate_from_event(self, create_event, override_app_settings):
130+
@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
131+
async def test_acreate_from_event(
132+
self, app_settings_app_id_type, create_event, override_app_settings
133+
):
131134
repositories = [
132135
{"id": seq.next(), "node_id": "node1", "full_name": "owner/repo1"},
133136
{"id": seq.next(), "node_id": "node2", "full_name": "owner/repo2"},
@@ -144,7 +147,11 @@ async def test_acreate_from_event(self, create_event, override_app_settings):
144147
"installation",
145148
)
146149

147-
with override_app_settings(APP_ID=str(installation_data["app_id"])):
150+
with override_app_settings(
151+
APP_ID=installation_data["app_id"]
152+
if isinstance(app_settings_app_id_type, int)
153+
else str(installation_data["app_id"])
154+
):
148155
installation = await Installation.objects.acreate_from_event(event)
149156

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

156-
def test_create_from_event(self, create_event, override_app_settings):
163+
@pytest.mark.parametrize("app_settings_app_id_type", [int, str])
164+
def test_create_from_event(
165+
self, app_settings_app_id_type, create_event, override_app_settings
166+
):
157167
repositories = [
158168
{"id": seq.next(), "node_id": "node1", "full_name": "owner/repo1"},
159169
{"id": seq.next(), "node_id": "node2", "full_name": "owner/repo2"},
@@ -170,7 +180,11 @@ def test_create_from_event(self, create_event, override_app_settings):
170180
"installation",
171181
)
172182

173-
with override_app_settings(APP_ID=str(installation_data["app_id"])):
183+
with override_app_settings(
184+
APP_ID=installation_data["app_id"]
185+
if isinstance(app_settings_app_id_type, int)
186+
else str(installation_data["app_id"])
187+
):
174188
installation = Installation.objects.create_from_event(event)
175189

176190
assert installation.installation_id == installation_data["id"]

0 commit comments

Comments
 (0)