@@ -30,15 +30,11 @@ def test_add_arguments(self):
3030 "--offset" , default = 0 , required = False , type = int
3131 )
3232
33- @patch ("apps.github.management.commands.github_update_users.MemberProfile" )
3433 @patch ("apps.github.management.commands.github_update_users.User" )
3534 @patch ("apps.github.management.commands.github_update_users.RepositoryContributor" )
3635 @patch ("apps.github.management.commands.github_update_users.BATCH_SIZE" , 2 )
37- def test_handle_with_default_offset (
38- self , mock_repository_contributor , mock_user , mock_member_profile
39- ):
36+ def test_handle_with_default_offset (self , mock_repository_contributor , mock_user ):
4037 """Test command execution with default offset."""
41- mock_member_profile .objects .get_or_create .return_value = (MagicMock (), False )
4238 mock_user1 = MagicMock (id = 1 , title = "User 1" , contributions_count = 0 )
4339 mock_user2 = MagicMock (id = 2 , title = "User 2" , contributions_count = 0 )
4440 mock_user3 = MagicMock (id = 3 , title = "User 3" , contributions_count = 0 )
@@ -80,15 +76,11 @@ def test_handle_with_default_offset(
8076 assert mock_user .bulk_save .call_count == 2
8177 assert mock_user .bulk_save .call_args_list [- 1 ][0 ][0 ] == [mock_user1 , mock_user2 , mock_user3 ]
8278
83- @patch ("apps.github.management.commands.github_update_users.MemberProfile" )
8479 @patch ("apps.github.management.commands.github_update_users.User" )
8580 @patch ("apps.github.management.commands.github_update_users.RepositoryContributor" )
8681 @patch ("apps.github.management.commands.github_update_users.BATCH_SIZE" , 2 )
87- def test_handle_with_custom_offset (
88- self , mock_repository_contributor , mock_user , mock_member_profile
89- ):
82+ def test_handle_with_custom_offset (self , mock_repository_contributor , mock_user ):
9083 """Test command execution with custom offset."""
91- mock_member_profile .objects .get_or_create .return_value = (MagicMock (), False )
9284 mock_user1 = MagicMock (id = 2 , title = "User 2" , contributions_count = 0 )
9385 mock_user2 = MagicMock (id = 3 , title = "User 3" , contributions_count = 0 )
9486
@@ -123,15 +115,13 @@ def test_handle_with_custom_offset(
123115 assert mock_user .bulk_save .call_count == 2
124116 assert mock_user .bulk_save .call_args_list [- 1 ][0 ][0 ] == [mock_user1 , mock_user2 ]
125117
126- @patch ("apps.github.management.commands.github_update_users.MemberProfile" )
127118 @patch ("apps.github.management.commands.github_update_users.User" )
128119 @patch ("apps.github.management.commands.github_update_users.RepositoryContributor" )
129120 @patch ("apps.github.management.commands.github_update_users.BATCH_SIZE" , 3 )
130121 def test_handle_with_users_having_no_contributions (
131- self , mock_repository_contributor , mock_user , mock_member_profile
122+ self , mock_repository_contributor , mock_user
132123 ):
133124 """Test command execution when users have no contributions."""
134- mock_member_profile .objects .get_or_create .return_value = (MagicMock (), False )
135125 mock_user1 = MagicMock (id = 1 , title = "User 1" , contributions_count = 0 )
136126 mock_user2 = MagicMock (id = 2 , title = "User 2" , contributions_count = 0 )
137127
@@ -159,15 +149,11 @@ def test_handle_with_users_having_no_contributions(
159149 assert mock_user .bulk_save .call_count == 1
160150 assert mock_user .bulk_save .call_args_list [- 1 ][0 ][0 ] == [mock_user1 , mock_user2 ]
161151
162- @patch ("apps.github.management.commands.github_update_users.MemberProfile" )
163152 @patch ("apps.github.management.commands.github_update_users.User" )
164153 @patch ("apps.github.management.commands.github_update_users.RepositoryContributor" )
165154 @patch ("apps.github.management.commands.github_update_users.BATCH_SIZE" , 1 )
166- def test_handle_with_single_user (
167- self , mock_repository_contributor , mock_user , mock_member_profile
168- ):
155+ def test_handle_with_single_user (self , mock_repository_contributor , mock_user ):
169156 """Test command execution with single user."""
170- mock_member_profile .objects .get_or_create .return_value = (MagicMock (), False )
171157 mock_user1 = MagicMock (id = 1 , title = "User 1" , contributions_count = 0 )
172158
173159 mock_users_queryset = MagicMock ()
@@ -193,15 +179,11 @@ def test_handle_with_single_user(
193179 assert mock_user .bulk_save .call_count == 2
194180 assert mock_user .bulk_save .call_args_list [- 1 ][0 ][0 ] == [mock_user1 ]
195181
196- @patch ("apps.github.management.commands.github_update_users.MemberProfile" )
197182 @patch ("apps.github.management.commands.github_update_users.User" )
198183 @patch ("apps.github.management.commands.github_update_users.RepositoryContributor" )
199184 @patch ("apps.github.management.commands.github_update_users.BATCH_SIZE" , 2 )
200- def test_handle_with_empty_user_list (
201- self , mock_repository_contributor , mock_user , mock_member_profile
202- ):
185+ def test_handle_with_empty_user_list (self , mock_repository_contributor , mock_user ):
203186 """Test command execution with no users."""
204- mock_member_profile .objects .get_or_create .return_value = (MagicMock (), False )
205187 mock_users_queryset = MagicMock ()
206188 mock_users_queryset .count .return_value = 0
207189 mock_users_queryset .__getitem__ .return_value = []
@@ -220,18 +202,12 @@ def test_handle_with_empty_user_list(
220202
221203 assert mock_user .bulk_save .call_count == 1
222204 assert mock_user .bulk_save .call_args_list [- 1 ][0 ][0 ] == []
223- assert mock_member_profile .bulk_save .call_count == 1
224- assert mock_member_profile .bulk_save .call_args_list [- 1 ][0 ][0 ] == []
225205
226- @patch ("apps.github.management.commands.github_update_users.MemberProfile" )
227206 @patch ("apps.github.management.commands.github_update_users.User" )
228207 @patch ("apps.github.management.commands.github_update_users.RepositoryContributor" )
229208 @patch ("apps.github.management.commands.github_update_users.BATCH_SIZE" , 2 )
230- def test_handle_with_exact_batch_size (
231- self , mock_repository_contributor , mock_user , mock_member_profile
232- ):
209+ def test_handle_with_exact_batch_size (self , mock_repository_contributor , mock_user ):
233210 """Test command execution when user count equals batch size."""
234- mock_member_profile .objects .get_or_create .return_value = (MagicMock (), False )
235211 mock_user1 = MagicMock (id = 1 , title = "User 1" , contributions_count = 0 )
236212 mock_user2 = MagicMock (id = 2 , title = "User 2" , contributions_count = 0 )
237213
@@ -261,41 +237,3 @@ def test_handle_with_exact_batch_size(
261237
262238 assert mock_user .bulk_save .call_count == 2
263239 assert mock_user .bulk_save .call_args_list [- 1 ][0 ][0 ] == [mock_user1 , mock_user2 ]
264-
265- @patch ("apps.github.management.commands.github_update_users.MemberProfile" )
266- @patch ("apps.github.management.commands.github_update_users.User" )
267- @patch ("apps.github.management.commands.github_update_users.RepositoryContributor" )
268- @patch ("apps.github.management.commands.github_update_users.BATCH_SIZE" , 2 )
269- def test_handle_member_profile_created (
270- self , mock_repository_contributor , mock_user , mock_member_profile
271- ):
272- """Test command execution when MemberProfile is newly created."""
273- mock_profile = MagicMock ()
274- mock_member_profile .objects .get_or_create .return_value = (mock_profile , True )
275-
276- mock_user1 = MagicMock (
277- id = 1 ,
278- contributions_count = 0 ,
279- is_owasp_staff = True ,
280- has_public_member_page = False ,
281- )
282-
283- mock_users_queryset = MagicMock ()
284- mock_users_queryset .count .return_value = 1
285- mock_users_queryset .__getitem__ .return_value = [mock_user1 ]
286- mock_user .objects .order_by .return_value = mock_users_queryset
287-
288- mock_rc_objects = MagicMock ()
289- mock_rc_objects .exclude .return_value .values .return_value .annotate .return_value = [
290- {"user_id" : 1 , "total_contributions" : 5 }
291- ]
292- mock_repository_contributor .objects = mock_rc_objects
293-
294- command = Command ()
295- command .handle (offset = 0 )
296-
297- assert mock_profile .github_user == mock_user1
298- assert mock_profile .contributions_count == 5
299- assert mock_profile .is_owasp_staff is True
300- assert mock_profile .has_public_member_page is False
301- mock_member_profile .bulk_save .assert_called_once ()
0 commit comments