mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-19 00:09:21 +11:00
Made the secret_id func more reusable. Added a test that is none.
This commit is contained in:
parent
c687ab125a
commit
ebdd36cfeb
2 changed files with 15 additions and 2 deletions
|
@ -15,8 +15,8 @@ L = getattr(settings, 'DPASTE_SLUG_LENGTH', 4)
|
|||
T = getattr(settings, 'DPASTE_SLUG_CHOICES',
|
||||
'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890')
|
||||
|
||||
def generate_secret_id(length=L):
|
||||
return ''.join([R.choice(T) for i in range(L)])
|
||||
def generate_secret_id(length=L, alphabet=T):
|
||||
return ''.join([R.choice(alphabet) for i in range(length)])
|
||||
|
||||
class Snippet(models.Model):
|
||||
secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True)
|
||||
|
|
|
@ -316,3 +316,16 @@ class SnippetTestCase(TestCase):
|
|||
from dpaste.highlight import pygmentize
|
||||
pygmentize('code', lexer_name='python')
|
||||
pygmentize('code', lexer_name='doesnotexist')
|
||||
|
||||
# This is actually a bad test. It is possible to have duplicates
|
||||
# because even if its random, it can generate two random, equal strings.
|
||||
#
|
||||
# def test_random_slug_generation(self):
|
||||
# """
|
||||
# Generate 1000 random slugs, make sure we have no duplicates.
|
||||
# """
|
||||
# from dpaste.models import generate_secret_id
|
||||
# result_list = []
|
||||
# for i in range(0, 1000):
|
||||
# result_list.append(generate_secret_id())
|
||||
# self.assertEqual(len(set(result_list)), 1000)
|
||||
|
|
Loading…
Reference in a new issue