Merge pull request #52 from pabluk/creatersakey-command-py3

Fix creatersakey management command support for Python 3.x
This commit is contained in:
Juan Ignacio Fiorentino 2015-10-19 17:10:42 -03:00
commit 4c9dfefedd
2 changed files with 14 additions and 3 deletions

View file

@ -1,7 +1,7 @@
from Crypto.PublicKey import RSA
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
class Command(BaseCommand):
@ -11,8 +11,8 @@ class Command(BaseCommand):
try:
key = RSA.generate(1024)
file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
with open(file_path, 'w') as f:
with open(file_path, 'wb') as f:
f.write(key.exportKey('PEM'))
self.stdout.write('RSA key successfully created at: ' + file_path)
except Exception as e:
self.stdout.write('Something goes wrong: ' + e.message)
self.stdout.write('Something goes wrong: {0}'.format(e))

View file

@ -0,0 +1,11 @@
from django.core.management import call_command
from django.test import TestCase, override_settings
from django.utils.six import StringIO
class CreateRSAKeyTest(TestCase):
@override_settings(BASE_DIR='/tmp')
def test_command_output(self):
out = StringIO()
call_command('creatersakey', stdout=out)
self.assertIn('RSA key successfully created', out.getvalue())