1
- from unittest .mock import patch
1
+ from unittest .mock import Mock , patch
2
2
3
- from django .core .exceptions import ObjectDoesNotExist
4
3
from django .urls import reverse
5
4
6
5
from .base import AuthenticatedAPITestCase
7
- from ..models import Role , User
6
+ from ..models import Infraction , Role , User
8
7
from ..models .bot .metricity import NotFoundError
9
8
from ..viewsets .bot .user import UserListPagination
10
9
@@ -424,7 +423,7 @@ def test_get_metricity_data(self):
424
423
self .assertCountEqual (response .json (), {
425
424
"joined_at" : joined_at ,
426
425
"total_messages" : total_messages ,
427
- "voice_banned " : False ,
426
+ "voice_gate_blocked " : False ,
428
427
"activity_blocks" : total_blocks
429
428
})
430
429
@@ -451,23 +450,36 @@ def test_no_metricity_user_for_review(self):
451
450
self .assertEqual (response .status_code , 404 )
452
451
453
452
def test_metricity_voice_banned (self ):
453
+ queryset_with_values = Mock (spec = Infraction .objects )
454
+ queryset_with_values .filter .return_value = queryset_with_values
455
+ queryset_with_values .exists .return_value = True
456
+
457
+ queryset_without_values = Mock (spec = Infraction .objects )
458
+ queryset_without_values .filter .return_value = queryset_without_values
459
+ queryset_without_values .exists .return_value = False
454
460
cases = [
455
- {'exception ' : None , 'voice_banned ' : True },
456
- {'exception ' : ObjectDoesNotExist , 'voice_banned ' : False },
461
+ {'voice_infractions ' : queryset_with_values , 'voice_gate_blocked ' : True },
462
+ {'voice_infractions ' : queryset_without_values , 'voice_gate_blocked ' : False },
457
463
]
458
464
459
465
self .mock_metricity_user ("foo" , 1 , 1 , [["bar" , 1 ]])
460
466
461
467
for case in cases :
462
- with self .subTest (exception = case ['exception' ], voice_banned = case ['voice_banned' ]):
463
- with patch ("pydis_site.apps.api.viewsets.bot.user.Infraction.objects.get" ) as p :
464
- p .side_effect = case ['exception' ]
468
+ with self .subTest (
469
+ voice_infractions = case ['voice_infractions' ],
470
+ voice_gate_blocked = case ['voice_gate_blocked' ]
471
+ ):
472
+ with patch ("pydis_site.apps.api.viewsets.bot.user.Infraction.objects.filter" ) as p :
473
+ p .return_value = case ['voice_infractions' ]
465
474
466
475
url = reverse ('api:bot:user-metricity-data' , args = [0 ])
467
476
response = self .client .get (url )
468
477
469
478
self .assertEqual (response .status_code , 200 )
470
- self .assertEqual (response .json ()["voice_banned" ], case ["voice_banned" ])
479
+ self .assertEqual (
480
+ response .json ()["voice_gate_blocked" ],
481
+ case ["voice_gate_blocked" ]
482
+ )
471
483
472
484
def test_metricity_review_data (self ):
473
485
# Given
0 commit comments