1
1
from __future__ import annotations
2
2
3
3
import pytest
4
- from gidgethub .abc import sansio
5
4
from model_bakery import baker
6
5
7
6
from django_github_app .events .installation import create_installation
19
18
20
19
@pytest .mark .parametrize ("app_settings_app_id_type" , [int , str ])
21
20
def test_create_installation (
22
- app_settings_app_id_type , installation_id , repository_id , override_app_settings
21
+ app_settings_app_id_type ,
22
+ installation_id ,
23
+ repository_id ,
24
+ override_app_settings ,
25
+ create_event ,
23
26
):
24
27
data = {
25
28
"installation" : {
@@ -30,7 +33,7 @@ def test_create_installation(
30
33
{"id" : repository_id , "node_id" : "node1234" , "full_name" : "owner/repo" }
31
34
],
32
35
}
33
- event = sansio . Event ( data , event = "installation" , delivery_id = "1234" )
36
+ event = create_event ( "installation" , delivery_id = "1234" , ** data )
34
37
35
38
with override_app_settings (
36
39
APP_ID = data ["installation" ]["app_id" ]
@@ -44,13 +47,13 @@ def test_create_installation(
44
47
assert installation .data == data ["installation" ]
45
48
46
49
47
- def test_delete_installation (installation ):
50
+ def test_delete_installation (installation , create_event ):
48
51
data = {
49
52
"installation" : {
50
53
"id" : installation .installation_id ,
51
54
}
52
55
}
53
- event = sansio . Event ( data , event = "installation" , delivery_id = "1234" )
56
+ event = create_event ( "installation" , delivery_id = "1234" , ** data )
54
57
55
58
delete_installation (event , None )
56
59
@@ -66,7 +69,9 @@ def test_delete_installation(installation):
66
69
(InstallationStatus .INACTIVE , "unsuspend" , InstallationStatus .ACTIVE ),
67
70
],
68
71
)
69
- def test_toggle_installation_status_suspend (status , action , expected , installation ):
72
+ def test_toggle_installation_status_suspend (
73
+ status , action , expected , installation , create_event
74
+ ):
70
75
installation .status = status
71
76
installation .save ()
72
77
@@ -76,7 +81,7 @@ def test_toggle_installation_status_suspend(status, action, expected, installati
76
81
"id" : installation .installation_id ,
77
82
},
78
83
}
79
- event = sansio . Event ( data , event = "installation" , delivery_id = "1234" )
84
+ event = create_event ( "installation" , delivery_id = "1234" , ** data )
80
85
81
86
assert installation .status != expected
82
87
@@ -86,13 +91,13 @@ def test_toggle_installation_status_suspend(status, action, expected, installati
86
91
assert installation .status == expected
87
92
88
93
89
- def test_sync_installation_data (installation ):
94
+ def test_sync_installation_data (installation , create_event ):
90
95
data = {
91
96
"installation" : {
92
97
"id" : installation .installation_id ,
93
98
},
94
99
}
95
- event = sansio . Event ( data , event = "installation" , delivery_id = "1234" )
100
+ event = create_event ( "installation" , delivery_id = "1234" , ** data )
96
101
97
102
assert installation .data != data
98
103
@@ -102,7 +107,7 @@ def test_sync_installation_data(installation):
102
107
assert installation .data == data ["installation" ]
103
108
104
109
105
- def test_sync_installation_repositories (installation ):
110
+ def test_sync_installation_repositories (installation , create_event ):
106
111
existing_repo = baker .make (
107
112
"django_github_app.Repository" ,
108
113
installation = installation ,
@@ -126,7 +131,7 @@ def test_sync_installation_repositories(installation):
126
131
}
127
132
],
128
133
}
129
- event = sansio . Event ( data , event = "installation" , delivery_id = "1234" )
134
+ event = create_event ( "installation" , delivery_id = "1234" , ** data )
130
135
131
136
assert Repository .objects .filter (
132
137
repository_id = data ["repositories_removed" ][0 ]["id" ]
0 commit comments