from django.http import HttpRequest
from django.test import SimpleTestCase

from apps.lyric.authentication import PasswordlessAuthenticationBackend
from apps.lyric.models import User


class SimpleAuthenticateTest(SimpleTestCase):
    def test_returns_None_if_token_is_invalid_uuid(self):
        result = PasswordlessAuthenticationBackend().authenticate(
            HttpRequest(), "no-such-token"
        )
        self.assertIsNone(result)

    def test_returns_None_if_no_uuid(self):
        result = PasswordlessAuthenticationBackend().authenticate(HttpRequest())
        self.assertIsNone(result)

class UserPermissionsTest(SimpleTestCase):
    def test_superuser_has_perm(self):
        user = User(is_superuser=True)
        self.assertTrue(user.has_perm("any.permission"))

    def test_superuser_has_module_perms(self):
        user = User(is_superuser=True)
        self.assertTrue(user.has_module_perms("any_app"))

    def test_non_superuser_has_no_perm(self):
        user = User(is_superuser=False)
        self.assertFalse(user.has_perm("any.permission"))

