Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_login_admin_as_user(self):
"""
checks that an admin user can impersonate a regular user via impostor backend
and that the login get reflected into the ImpostorLog table
:return:
"""
assert ImpostorLog.objects.count() == 0
composed_username = '{} as {}'.format(admin_username, user_username)
u = authenticate(username=composed_username, password=admin_pass)
real_user = get_user_model().objects.get(username=user_username)
assert u == real_user
# Check if logs contain an entry now
logs_entries = ImpostorLog.objects.all()
assert len(logs_entries) == 1
entry = logs_entries[0]
# today = datetime.date.today()
# lin = entry.logged_in
assert entry.impostor.username == admin_username
assert entry.imposted_as.username == user_username
# assert (lin.year == today.year and lin.month == today.month and lin.day == today.day)
assert (entry.token and entry.token.strip() != "")