示例#1
0
 def test_duplicate_username_counter(self, filter):
     filter = (filter.expects_call().returns_fake().expects('count')
                                                   .returns(1)
                                                   .next_call()
                                                   .returns(1)
                                                   .next_call()
                                                   .returns(0))
     eq_(autocreate_username('existingname'), 'existingname3')
示例#2
0
 def test_too_many_tries(self, filter):
     filter = filter.is_callable().returns_fake().provides("count").returns(1)
     for i in range(3):
         # Simulate existing username.
         filter = filter.next_call().returns(1)
     # Simulate available username.
     filter = filter.next_call().returns(0)
     # After the third try, give up, and generate a random string username.
     un = autocreate_username("base")
     assert not un.startswith("base"), "Unexpected: %s" % un
示例#3
0
 def test_too_many_tries(self, filter):
     filter = (
         filter.is_callable().returns_fake().provides('count').returns(1))
     for i in range(3):
         # Simulate existing username.
         filter = filter.next_call().returns(1)
     # Simulate available username.
     filter = filter.next_call().returns(0)
     # After the third try, give up, and generate a random string username.
     un = autocreate_username('base')
     assert not un.startswith('base'), 'Unexpected: %s' % un
示例#4
0
 def test_duplicate_username_counter(self, filter):
     filter = (
         filter.expects_call()
         .returns_fake()
         .expects("count")
         .returns(1)
         .next_call()
         .returns(1)
         .next_call()
         .returns(0)
     )
     eq_(autocreate_username("existingname"), "existingname3")
示例#5
0
 def test_duplicate_django_username_counter(self, du, up):
     up = up.expects_call().returns_fake().expects("count").returns(0)
     du = (
         du.expects_call()
         .returns_fake()
         .expects("count")
         .returns(1)
         .next_call()
         .returns(1)
         .next_call()
         .returns(1)
         .next_call()
         .returns(0)
     )
     eq_(autocreate_username("existingname"), "existingname4")
示例#6
0
 def test_empty_username_is_a_random_hash(self):
     un = autocreate_username('.+')  # this shouldn't happen but it could!
     assert len(un) and not un.startswith('.+'), 'Unexpected: %s' % un
示例#7
0
 def test_invalid_characters(self):
     eq_(autocreate_username('testaccount+slug'), 'testaccountslug')
示例#8
0
 def test_duplicate_django_username_counter(self, du, up):
     up = up.expects_call().returns_fake().expects('count').returns(0)
     du = (du.expects_call().returns_fake().expects('count').returns(
         1).next_call().returns(1).next_call().returns(
             1).next_call().returns(0))
     eq_(autocreate_username('existingname'), 'existingname4')
示例#9
0
 def test_too_long(self):
     un = autocreate_username('f' + 'u' * 255)
     assert not un.startswith('fuuuuuuuuuuuuuuuuuu'), 'Unexpected: %s' % un
示例#10
0
 def test_blacklisted(self):
     BlacklistedUsername.objects.create(username='******')
     un = autocreate_username('firefox')
     assert un != 'firefox', 'Unexpected: %s' % un
示例#11
0
 def test_empty_username_is_a_random_hash(self):
     un = autocreate_username('.+')  # this shouldn't happen but it could!
     assert len(un) and not un.startswith('.+'), 'Unexpected: %s' % un
示例#12
0
 def test_invalid_characters(self):
     eq_(autocreate_username('testaccount+slug'), 'testaccountslug')
示例#13
0
 def test_too_long(self):
     un = autocreate_username('f' + 'u' * 255)
     assert not un.startswith('fuuuuuuuuuuuuuuuuuu'), 'Unexpected: %s' % un
示例#14
0
 def test_blacklisted(self):
     BlacklistedName.objects.create(name='firefox')
     un = autocreate_username('firefox')
     assert un != 'firefox', 'Unexpected: %s' % un
示例#15
0
 def test_too_long(self):
     un = autocreate_username("f" + "u" * 255)
     assert not un.startswith("fuuuuuuuuuuuuuuuuuu"), "Unexpected: %s" % un
示例#16
0
 def test_blacklisted(self):
     BlacklistedUsername.objects.create(username="******")
     un = autocreate_username("firefox")
     assert un != "firefox", "Unexpected: %s" % un