コード例 #1
0
 def test_length(self):
   default_length = 8
   self.assertEqual(len(random.generate_random_hex_string()), default_length,
                    "Length does not match "\
                    "default expected length of %d." % default_length)
   self.assertEqual(len(random.generate_random_hex_string(length=10)), 10,
                    "Length does not match expected length.")
コード例 #2
0
ファイル: protocol.py プロジェクト: Eah300muse/pyoauth
def _generate_hex_verification_code(length=8):
    """
    Generates an OAuth verification code.

    The verification code will be displayed by the server if a callback URL
    is not provided by the client. The resource owner (the end-user) may
    need to enter this verification code on a limited device. Therefore,
    we limit the length of this code to 8 characters to keep it suitable
    for manual entry.

    :see:
        Resource Owner Authorization
        (http://tools.ietf.org/html/rfc5849#section-2.2)
    :param length:
        Length of the verification code to be returned. Default 8.
        The length MUST be a positive even number.
    :returns:
        A string representation of a randomly-generated hexadecimal OAuth
        verification code.
    """
    return generate_random_hex_string(length)
コード例 #3
0
 def test_is_string(self):
   self.assertTrue(builtins.is_bytes(random.generate_random_hex_string()),
                   "Not a bytestring.")
コード例 #4
0
 def test_uniqueness(self):
   # The likelyhood of recurrence should be tiny if a large enough
   # length is chosen.
   self.assertNotEqual(random.generate_random_hex_string(),
                       random.generate_random_hex_string(),
                       "Not unique.")
コード例 #5
0
 def test_is_string(self):
   self.assertTrue(is_bytes(generate_random_hex_string()),
                   "Not a bytestring.")