from unittest.mock import Mock, patch

from django.core.exceptions import ValidationError
from django.conf import settings
from django.test import TestCase

from ..remote_user_auth import email_to_username


class AuthTests(TestCase):

    def test_email_domain_validation(self):
        """Ensure that a given email address is a member of the right domain"""

        with self.settings(ALLOWED_EMAIL_DOMAINS={'gsa.gov'}):
            email = '<EMAIL>'
            self.assertEqual('sean.herron', email_to_username(email))
            with self.assertRaises(ValidationError):
                email = '<EMAIL>'
                email_to_username(email)

    def test_username_stripping(self):
        """Ensure that a proper username is created"""
        email = '<EMAIL>'
        self.assertEqual('sean.herron', email_to_username(email))
        email = '<EMAIL>'
        self.assertEqual('sean.herronherronherronherron', email_to_username(email))
from unittest.mock import Mock, patch

from django.core.exceptions import ValidationError
from django.conf import settings
from django.test import TestCase

from ..remote_user_auth import email_to_username


class AuthTests(TestCase):

    def test_email_domain_validation(self):
        """Ensure that a given email address is a member of the right domain"""

        with self.settings(ALLOWED_EMAIL_DOMAINS={'gsa.gov'}):
            email = '<EMAIL>'
            self.assertEqual('sean.herron', email_to_username(email))
            with self.assertRaises(ValidationError):
                email = '<EMAIL>'
                email_to_username(email)

    def test_username_stripping(self):
        """Ensure that a proper username is created"""
        email = '<EMAIL>'
        self.assertEqual('sean.herron', email_to_username(email))
        email = '<EMAIL>'
        self.assertEqual('sean.herronherronherronherron', email_to_username(email))
Ensure that a given email address is a member of the right domain Ensure that a proper username is created