How to use the impostor.models.ImpostorLog.objects.first function in Impostor

To help you get started, we’ve selected a few Impostor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samastur / Impostor / tests / test_impostor.py View on Github external
:param password:
        :param impersonated_user:
        :param expected:
        :param custom_settings:
        :param rf:
        :return:
        """
        setattr(rf, 'META', {})
        rf.META['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,192.168.0.1'
        assert ImpostorLog.objects.count() == 0
        composed_username = '{} as {}'.format(first_user.username, impersonated_user.username)
        authenticated_user = authenticate(request=rf, username=composed_username, password=password)
        if expected == 'ok':
            assert authenticated_user == impersonated_user
            assert ImpostorLog.objects.count() == 1
            log = ImpostorLog.objects.first()
            assert log.impostor == first_user
            assert log.imposted_as == impersonated_user
            assert log.impostor_ip == '127.0.0.1'
        else:
            assert authenticated_user is None