# Path: django_core/utils/random_utils.py
# ALPHANUM = NUMBERS + LETTERS
# 
# Path: django_core/utils/random_utils.py
# def random_alphanum(length=10, lower_only=False):
#     """
#     Gets a random alphanumeric value using both letters and numbers.
# 
#     :param length: size of the random alphanumeric string.
#     :param lower_only: boolean indicating if only lower case letters should be
#         used.
#     :return: alphanumeric string size of length
# 
#     This function uses all number except for:
# 
#     * 0
#     * 1
# 
#     and uses all letters except for:
# 
#     * lower case "l" (el)
#     * lower and upper case "o" and "O" (oh)
# 
#     For upper and lower cased letters...
#     ------------------------------------
#     Upper and lower cased letters and numbers can be used more than once which
#     leaves the possible combinations as follows:
# 
#         8 numbers used + 49 letters used (upper and lower) = 57 total characters
# 
#     Which leads us to the following equation:
# 
#         57 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         57 ^ 1 = 57
#         57 ^ 2 = 3,249
#         57 ^ 3 = 185,193
#         57 ^ 4 = 10,556,001
#         57 ^ 5 = 601,692,057
#         57 ^ 6 = 34,296,447,249
#         57 ^ 7 = 1,954,897,493,193
#         57 ^ 8 = 111,429,157,112,001
#         57 ^ 9 = 6,351,461,955,384,057
#         57 ^ 10 = 362,033,331,456,891,249
#         ...
# 
#     For lower cased letters...
#     --------------------------
#     Lower cased letters and numbers can be used more than once which leaves the
#     possible combinations as follows:
# 
#         8 numbers used + 24 letters used (lower only) = 32 total characters
# 
#     Which leads us to the following equation:
# 
#         32 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         32 ^ 1 = 32
#         32 ^ 2 = 1,024
#         32 ^ 3 = 32,768
#         32 ^ 4 = 1,048,576
#         32 ^ 5 = 33,554,432
#         32 ^ 6 = 1,073,741,824
#         32 ^ 7 = 34,359,738,368
#         32 ^ 8 = 1,099,511,627,776
#         32 ^ 9 = 35,184,372,088,832
#         32 ^ 10 = 1,125,899,906,842,624
#         ...
# 
#     """
#     character_set = ALPHANUM_LOWER if lower_only else ALPHANUM
#     sample_size = 5
#     chars = random.sample(character_set, sample_size)
# 
#     while len(chars) < length:
#         chars += random.sample(character_set, sample_size)
# 
#     random.shuffle(chars)
#     return ''.join(chars[:length])


from django.http.response import Http404
from django.utils.text import slugify
from django_core.utils.random_utils import ALPHANUM
from django_core.utils.random_utils import random_alphanum
from django_testing.testcases.users import SingleUserTestCase
from django_testing.user_utils import create_user
from test_objects.models import TestManagerModel
from test_objects.models import TestModel

    def test_get_by_token(self):
        """Test model manager get by token."""
        token = random_alphanum()
        obj = TestManagerModel.objects.create(created_user=self.user,
                                              token=token)
        obj_db = TestManagerModel.objects.get_by_token(token=token)
        self.assertEqual(obj, obj_db)

    def test_get_by_token_or_404(self):
        """Test model manager get by token."""
        with self.assertRaises(Http404):
            TestManagerModel.objects.get_by_token_or_404(token=123455678)

    def test_get_by_user(self):
        """Test model manager get by user."""
        user = create_user()
        obj = TestManagerModel.objects.create(created_user=self.user,
                                              user=user)
        obj_db = TestManagerModel.objects.get_by_user(user=user)
        self.assertEqual(obj, obj_db[0])

    def test_is_slug_available(self):
        """Test if a slug is available."""
        self.assertTrue(TestManagerModel.objects.is_slug_available(
            slug=random_alphanum())
        )

    def test_not_is_slug_available(self):
        """Test if a slug is not available."""

# Path: django_core/utils/random_utils.py
# ALPHANUM = NUMBERS + LETTERS
# 
# Path: django_core/utils/random_utils.py
# def random_alphanum(length=10, lower_only=False):
#     """
#     Gets a random alphanumeric value using both letters and numbers.
# 
#     :param length: size of the random alphanumeric string.
#     :param lower_only: boolean indicating if only lower case letters should be
#         used.
#     :return: alphanumeric string size of length
# 
#     This function uses all number except for:
# 
#     * 0
#     * 1
# 
#     and uses all letters except for:
# 
#     * lower case "l" (el)
#     * lower and upper case "o" and "O" (oh)
# 
#     For upper and lower cased letters...
#     ------------------------------------
#     Upper and lower cased letters and numbers can be used more than once which
#     leaves the possible combinations as follows:
# 
#         8 numbers used + 49 letters used (upper and lower) = 57 total characters
# 
#     Which leads us to the following equation:
# 
#         57 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         57 ^ 1 = 57
#         57 ^ 2 = 3,249
#         57 ^ 3 = 185,193
#         57 ^ 4 = 10,556,001
#         57 ^ 5 = 601,692,057
#         57 ^ 6 = 34,296,447,249
#         57 ^ 7 = 1,954,897,493,193
#         57 ^ 8 = 111,429,157,112,001
#         57 ^ 9 = 6,351,461,955,384,057
#         57 ^ 10 = 362,033,331,456,891,249
#         ...
# 
#     For lower cased letters...
#     --------------------------
#     Lower cased letters and numbers can be used more than once which leaves the
#     possible combinations as follows:
# 
#         8 numbers used + 24 letters used (lower only) = 32 total characters
# 
#     Which leads us to the following equation:
# 
#         32 total characters ^ length = total possible combinations
# 
#     The following total possible combinations are below for a given length:
# 
#         32 ^ 1 = 32
#         32 ^ 2 = 1,024
#         32 ^ 3 = 32,768
#         32 ^ 4 = 1,048,576
#         32 ^ 5 = 33,554,432
#         32 ^ 6 = 1,073,741,824
#         32 ^ 7 = 34,359,738,368
#         32 ^ 8 = 1,099,511,627,776
#         32 ^ 9 = 35,184,372,088,832
#         32 ^ 10 = 1,125,899,906,842,624
#         ...
# 
#     """
#     character_set = ALPHANUM_LOWER if lower_only else ALPHANUM
#     sample_size = 5
#     chars = random.sample(character_set, sample_size)
# 
#     while len(chars) < length:
#         chars += random.sample(character_set, sample_size)
# 
#     random.shuffle(chars)
#     return ''.join(chars[:length])


# Path: tests/test_managers.py
from django.http.response import Http404
from django.utils.text import slugify
from django_core.utils.random_utils import ALPHANUM
from django_core.utils.random_utils import random_alphanum
from django_testing.testcases.users import SingleUserTestCase
from django_testing.user_utils import create_user
from test_objects.models import TestManagerModel
from test_objects.models import TestModel


    def test_get_by_token(self):
        """Test model manager get by token."""
        token = random_alphanum()
        obj = TestManagerModel.objects.create(created_user=self.user,
                                              token=token)
        obj_db = TestManagerModel.objects.get_by_token(token=token)
        self.assertEqual(obj, obj_db)

    def test_get_by_token_or_404(self):
        """Test model manager get by token."""
        with self.assertRaises(Http404):
            TestManagerModel.objects.get_by_token_or_404(token=123455678)

    def test_get_by_user(self):
        """Test model manager get by user."""
        user = create_user()
        obj = TestManagerModel.objects.create(created_user=self.user,
                                              user=user)
        obj_db = TestManagerModel.objects.get_by_user(user=user)
        self.assertEqual(obj, obj_db[0])

    def test_is_slug_available(self):
        """Test if a slug is available."""
        self.assertTrue(TestManagerModel.objects.is_slug_available(
            slug=random_alphanum())
        )

    def test_not_is_slug_available(self):
        """Test if a slug is not available."""

        slug = slugify(random_alphanum())