Esempio n. 1
0
 def test_get_filter_kwargs_ip(self):
     self.assertEqual(
         dict(
             get_client_parameters(self.username, self.ip_address,
                                   self.user_agent)),
         {"ip_address": self.ip_address},
     )
Esempio n. 2
0
 def test_get_filter_kwargs_user(self):
     self.assertEqual(
         get_client_parameters(self.username, self.ip_address,
                               self.user_agent),
         [{
             "username": self.username
         }],
     )
Esempio n. 3
0
def filter_user_attempts(request: AxesHttpRequest, credentials: dict = None) -> QuerySet:
    """
    Return a queryset of AccessAttempts that match the given request and credentials.
    """

    username = get_client_username(request, credentials)

    filter_kwargs = get_client_parameters(username, request.axes_ip_address, request.axes_user_agent)

    return AccessAttempt.objects.filter(**filter_kwargs)
Esempio n. 4
0
 def test_get_filter_kwargs_ip_and_agent(self):
     self.assertEqual(
         get_client_parameters(self.username, self.ip_address,
                               self.user_agent),
         [{
             "ip_address": self.ip_address
         }, {
             "user_agent": self.user_agent
         }],
     )
Esempio n. 5
0
 def test_get_filter_kwargs_ip_and_agent(self):
     self.assertEqual(
         dict(
             get_client_parameters(self.username, self.ip_address,
                                   self.user_agent)),
         {
             'ip_address': self.ip_address,
             'user_agent': self.user_agent
         },
     )
Esempio n. 6
0
def filter_user_attempts(request, credentials: dict = None) -> QuerySet:
    """
    Return a queryset of AccessAttempts that match the given request and credentials.
    """

    username = get_client_username(request, credentials)

    filter_kwargs = get_client_parameters(username, request.axes_ip_address,
                                          request.axes_user_agent)

    return AccessAttempt.objects.filter(**filter_kwargs)
Esempio n. 7
0
def filter_user_attempts(request, credentials: dict = None) -> List[QuerySet]:
    """
    Return a list querysets of AccessAttempts that match the given request and credentials.
    """

    username = get_client_username(request, credentials)

    filter_kwargs_list = get_client_parameters(username,
                                               request.axes_ip_address,
                                               request.axes_user_agent)
    attempts_list = [
        AccessAttempt.objects.filter(**filter_kwargs)
        for filter_kwargs in filter_kwargs_list
    ]
    return attempts_list
Esempio n. 8
0
 def test_get_filter_kwargs_user_ip_agent(self):
     self.assertEqual(
         dict(get_client_parameters(self.username, self.ip_address, self.user_agent)),
         {'username': self.username, 'ip_address': self.ip_address, 'user_agent': self.user_agent},
     )