Commits

Ronny Pfannschmidt committed ae59eb6

b64 roundtriping test now uses parametrize

Comments (0)

Files changed (1)

 # -*- coding: utf-8 -*-
+import pytest
 from datetime import datetime, timedelta
 from Crypto.PublicKey import RSA
 import unittest, persona, os
 
 try:
-	import simplejson as json
+    import simplejson as json
 except ImportError:
-	import json
+    import json
 
 KEY = RSA.importKey(open('tests.pem'))
 SECRETS = json.load(open('tests.json'))
 
 class Readable(object):
-	def __init__(self, data):
-		self.data = data
-	def read(self):
-		return self.data
+    def __init__(self, data):
+        self.data = data
+    def read(self):
+        return self.data
 
 def testenv(data):
 	return {
 		'wsgi.input': Readable(data),
 	}
 
+
+@pytest.mark.parametrize('input', [
+    'test',
+    'a',
+    'ab',
+    'abc',
+    'Iñtërnâtiônàlizætiøn',
+    ])
+def test_b64u_roundtriping(input):
+    middle = persona.b64uencode(input)
+    res = persona.b64udecode(middle)
+    assert res == input
+
+
 class IdPTests(unittest.TestCase):
 	
 	@classmethod
 		persona.KEY = KEY
 		persona.SECRETS = SECRETS
 	
-	def test_b64u(self):
-		
-		res = persona.b64udecode(persona.b64uencode('test'))
-		assert res == 'test'
-		
-		res = persona.b64udecode(persona.b64uencode('a'))
-		assert res == 'a'
-		
-		res = persona.b64udecode(persona.b64uencode('ab'))
-		assert res == 'ab'
-		
-		res = persona.b64udecode(persona.b64uencode('abc'))
-		assert res == 'abc'
-		
-		res = persona.b64udecode(persona.b64uencode('Iñtërnâtiônàlizætiøn'))
-		assert res == 'Iñtërnâtiônàlizætiøn'
 	
 	def test_jws(self):