~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_commands.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-15 18:14:08 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120315181408-zgl94hzo0x4n99an
Tags: 0.1+bzr295+dfsg-0ubuntu2
* debian/patches:
  - 01-fix-database-settings.patch: Update to set PSERV_URL.
  - 02-pserv-config.patch: Set port to 8001.
* debian/maas.postinst: Run maas-import-isos on install.
* debian/control: Depends on rabbitmq-server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
__metaclass__ = type
12
12
__all__ = []
13
13
 
 
14
from io import BytesIO
14
15
import os
15
16
 
16
17
from django.conf import settings
 
18
from django.contrib.auth.models import User
17
19
from django.core.management import call_command
18
20
from maasserver.models import FileStorage
19
 
from maastesting import TestCase
 
21
from maasserver.testing.factory import factory
 
22
from maastesting.testcase import TestCase
20
23
 
21
24
 
22
25
class TestCommands(TestCase):
33
36
        call_command('gc')
34
37
        # The test is that we get here without errors.
35
38
        pass
 
39
 
 
40
    def test_createadmin_requires_username(self):
 
41
        stderr = BytesIO()
 
42
        self.assertRaises(
 
43
            SystemExit, call_command, 'createadmin', stderr=stderr)
 
44
        command_output = stderr.getvalue().strip()
 
45
 
 
46
        self.assertIn(
 
47
            "Error: You must provide a username with --username.",
 
48
             command_output)
 
49
 
 
50
    def test_createadmin_requires_password(self):
 
51
        username = factory.getRandomString()
 
52
        stderr = BytesIO()
 
53
        self.assertRaises(
 
54
            SystemExit, call_command, 'createadmin', username=username,
 
55
            stderr=stderr)
 
56
        command_output = stderr.getvalue().strip()
 
57
 
 
58
        self.assertIn(
 
59
            "Error: You must provide a password with --password.",
 
60
             command_output)
 
61
 
 
62
    def test_createadmin_creates_admin(self):
 
63
        stderr = BytesIO()
 
64
        stdout = BytesIO()
 
65
        username = factory.getRandomString()
 
66
        password = factory.getRandomString()
 
67
        call_command(
 
68
            'createadmin', username=username, password=password,
 
69
            stderr=stderr, stdout=stdout)
 
70
        users = list(User.objects.filter(username=username))
 
71
 
 
72
        self.assertEquals('', stderr.getvalue().strip())
 
73
        self.assertEquals('', stdout.getvalue().strip())
 
74
        self.assertEqual(1, len(users))  # One user with that name.
 
75
        self.assertTrue(users[0].check_password(password))
 
76
        self.assertTrue(users[0].is_superuser)
 
77
        self.assertEqual('', users[0].email)  # His email is empty.