launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06821
[Merge] lp:~rvb/maas/maas-createadmin-restore into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/maas-createadmin-restore into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/maas-createadmin-restore/+merge/98639
This branch resotres the createadmin command. It now also take a third (mandatory) command line argument: --email=adminemail@xxxxxxxxxxx.
--
https://code.launchpad.net/~rvb/maas/maas-createadmin-restore/+merge/98639
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-createadmin-restore into lp:maas.
=== modified file 'src/maasserver/tests/test_commands.py'
--- src/maasserver/tests/test_commands.py 2012-03-21 07:12:23 +0000
+++ src/maasserver/tests/test_commands.py 2012-03-21 14:09:22 +0000
@@ -11,11 +11,14 @@
__metaclass__ = type
__all__ = []
+from io import BytesIO
import os
from django.conf import settings
+from django.contrib.auth.models import User
from django.core.management import call_command
from maasserver.models import FileStorage
+from maasserver.testing.factory import factory
from maastesting.testcase import TestCase
@@ -33,3 +36,56 @@
call_command('gc')
# The test is that we get here without errors.
pass
+
+ def test_createadmin_requires_username(self):
+ stderr = BytesIO()
+ self.assertRaises(
+ SystemExit, call_command, 'createadmin', stderr=stderr)
+ command_output = stderr.getvalue().strip()
+
+ self.assertIn(
+ "Error: You must provide a username with --username.",
+ command_output)
+
+ def test_createadmin_requires_password(self):
+ username = factory.getRandomString()
+ stderr = BytesIO()
+ self.assertRaises(
+ SystemExit, call_command, 'createadmin', username=username,
+ stderr=stderr)
+ command_output = stderr.getvalue().strip()
+
+ self.assertIn(
+ "Error: You must provide a password with --password.",
+ command_output)
+
+ def test_createadmin_requires_email(self):
+ username = factory.getRandomString()
+ password = factory.getRandomString()
+ stderr = BytesIO()
+ self.assertRaises(
+ SystemExit, call_command, 'createadmin', username=username,
+ password=password, stderr=stderr)
+ command_output = stderr.getvalue().strip()
+
+ self.assertIn(
+ "Error: You must provide a email with --email.",
+ command_output)
+
+ def test_createadmin_creates_admin(self):
+ stderr = BytesIO()
+ stdout = BytesIO()
+ username = factory.getRandomString()
+ password = factory.getRandomString()
+ email = '%s@xxxxxxxxxxx' % factory.getRandomString()
+ call_command(
+ 'createadmin', username=username, password=password,
+ email=email, stderr=stderr, stdout=stdout)
+ users = list(User.objects.filter(username=username))
+
+ self.assertEquals('', stderr.getvalue().strip())
+ self.assertEquals('', stdout.getvalue().strip())
+ self.assertEqual(1, len(users)) # One user with that name.
+ self.assertTrue(users[0].check_password(password))
+ self.assertTrue(users[0].is_superuser)
+ self.assertEqual(email, users[0].email)