-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigest_tool_tests.py
More file actions
31 lines (25 loc) · 981 Bytes
/
digest_tool_tests.py
File metadata and controls
31 lines (25 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
import digest_tool
import hashlib
import unittest
class DigestToolTestCase(unittest.TestCase):
def setUp(self):
digest_tool.app.config['TESTING'] = True
self.app = digest_tool.app.test_client()
self.message = 'Hello World!'
def test_builtin_algorithms(self):
for algorithm in hashlib.algorithms:
h = hashlib.new(algorithm)
h.update(self.message)
rv = self.app.post('/hash/%s' % algorithm, data={'message': self.message})
assert rv.data == h.hexdigest()
def test_ripemd160(self):
h = hashlib.new('ripemd160')
h.update(self.message)
rv = self.app.post('/hash/ripemd160', data={'message': self.message})
assert rv.data == h.hexdigest()
def test_wrong_algorithm(self):
rv = self.app.post('/hash/wrong', data={'message': self.message})
assert rv.status_code == 404
if __name__ == '__main__':
unittest.main()