Ejemplo n.º 1
0
    def test_get_digest_algorithm_specified(self):
        '''
		Getting a specific digest algorithm should yield that algorithm if it
		exists.
		'''
        self.assertEqual(utils._get_digest_algorithm('md5'), hashlib.md5)
        self.assertEqual(utils._get_digest_algorithm('MD5'), hashlib.md5)

        with self.assertRaises(exceptions.AlgorithmNotSupported):
            utils._get_digest_algorithm('abcdef')
Ejemplo n.º 2
0
    def test_get_digest_algorithm_none(self):
        '''
		Get the digest algorithm when no valid ones are specified.
		An error should be raised.
		'''
        with self.assertRaises(exceptions.AlgorithmNotSupported):
            with mock.patch.object(settings, 'ALLOWED_DIGEST_ALGORITHMS',
                                   ['ABCDE']):
                utils._get_digest_algorithm()

        with self.assertRaises(exceptions.AlgorithmNotSupported):
            with mock.patch.object(settings, 'ALLOWED_DIGEST_ALGORITHMS', []):
                utils._get_digest_algorithm()
Ejemplo n.º 3
0
    def test_get_digest_algorithm(self):
        '''
		Getting a digest algorithm should yield the first one from the possible
		options.
		'''
        self.assertEqual(utils._get_digest_algorithm(), hashlib.sha256)

        self.assertEqual(utils._get_digest_algorithm(), hashlib.sha256)

        with mock.patch.object(settings, 'ALLOWED_DIGEST_ALGORITHMS',
                               ['ABCDEF', 'SHA256']):
            self.assertEqual(utils._get_digest_algorithm(), hashlib.sha256)

        with mock.patch.object(settings, 'ALLOWED_DIGEST_ALGORITHMS', ['MD5']):
            self.assertEqual(utils._get_digest_algorithm(), hashlib.md5)