# 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
        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())
        TestManagerModel.objects.create(created_user=self.user,
                                        slug=slug)
        self.assertFalse(TestManagerModel.objects.is_slug_available(slug=slug))

    def test_get_next_slug(self):
        """Test getting next available slug."""
        slug = slugify(random_alphanum())
        TestManagerModel.objects.create(created_user=self.user,
                                        slug=slug)
        next_slug = TestManagerModel.objects.get_next_slug(slug=slug)
        self.assertEqual(next_slug, '{0}-1'.format(slug))

    def test_get_next_token(self):
        """Test for getting the next avaible token."""
        used_tokens = [c for c in list(ALPHANUM) if c != '8']
        objs = [TestManagerModel(token=t, created_user=self.user)
                for t in used_tokens]
        TestManagerModel.objects.bulk_create(objs)

        self.assertEqual(TestManagerModel.objects.get_next_token(length=1), '8')

    def test_get_available_tokens(self):
        """Test for getting the next avaible tokens."""

# 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

        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())
        TestManagerModel.objects.create(created_user=self.user,
                                        slug=slug)
        self.assertFalse(TestManagerModel.objects.is_slug_available(slug=slug))

    def test_get_next_slug(self):
        """Test getting next available slug."""
        slug = slugify(random_alphanum())
        TestManagerModel.objects.create(created_user=self.user,
                                        slug=slug)
        next_slug = TestManagerModel.objects.get_next_slug(slug=slug)
        self.assertEqual(next_slug, '{0}-1'.format(slug))

    def test_get_next_token(self):
        """Test for getting the next avaible token."""
        used_tokens = [c for c in list(ALPHANUM) if c != '8']
        objs = [TestManagerModel(token=t, created_user=self.user)
                for t in used_tokens]
        TestManagerModel.objects.bulk_create(objs)

        self.assertEqual(TestManagerModel.objects.get_next_token(length=1), '8')

    def test_get_available_tokens(self):
        """Test for getting the next avaible tokens."""

        used_tokens = [c for c in list(ALPHANUM) if c not in ('8', 'a', 'm')]