Merge lp:~stevanr/linaro-license-protection/add-setsuperuser-command into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Stevan Radaković
Status: Merged
Approved by: Данило Шеган
Approved revision: 111
Merged at revision: 111
Proposed branch: lp:~stevanr/linaro-license-protection/add-setsuperuser-command
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 81 lines (+52/-0)
3 files modified
license_protected_downloads/management/commands/setsuperuser.py (+23/-0)
license_protected_downloads/tests/__init__.py (+3/-0)
license_protected_downloads/tests/test_custom_commands.py (+26/-0)
To merge this branch: bzr merge lp:~stevanr/linaro-license-protection/add-setsuperuser-command
Reviewer Review Type Date Requested Status
Данило Шеган (community) Approve
Review via email: mp+120879@code.launchpad.net

Description of the change

Add setsuperuser custom command for license_protected_downloads application.

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :

I hate that we are already starting to duplicate this code. Let's thing tomorrow how we can start producing a shared django base for Linaro.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'license_protected_downloads/management'
=== added file 'license_protected_downloads/management/__init__.py'
=== added directory 'license_protected_downloads/management/commands'
=== added file 'license_protected_downloads/management/commands/__init__.py'
=== added file 'license_protected_downloads/management/commands/setsuperuser.py'
--- license_protected_downloads/management/commands/setsuperuser.py 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/management/commands/setsuperuser.py 2012-08-22 21:52:18 +0000
@@ -0,0 +1,23 @@
1from django.core.management.base import BaseCommand, CommandError
2from django.contrib.auth.models import User
3
4
5class Command(BaseCommand):
6 args = '<username username ...>'
7 help = 'Sets specified user as superuser of the ' + \
8 'license_protected_downloads admin app'
9
10 def handle(self, *args, **options):
11 for username in args:
12 self.find_and_update_user(username)
13 self.stdout.write('Successfully updated user "%s" \n' % username)
14
15 def find_and_update_user(self, username):
16 try:
17 user = User.objects.get(username=username)
18 except User.DoesNotExist:
19 raise CommandError('User "%s" does not exist' % username)
20
21 user.is_staff = True
22 user.is_superuser = True
23 user.save()
024
=== modified file 'license_protected_downloads/tests/__init__.py'
--- license_protected_downloads/tests/__init__.py 2012-07-11 13:08:55 +0000
+++ license_protected_downloads/tests/__init__.py 2012-08-22 21:52:18 +0000
@@ -4,6 +4,8 @@
4from license_protected_downloads.tests.test_pyflakes import TestPyflakes4from license_protected_downloads.tests.test_pyflakes import TestPyflakes
5from license_protected_downloads.tests.test_views import ViewTests5from license_protected_downloads.tests.test_views import ViewTests
6from license_protected_downloads.tests.test_openid_auth import TestOpenIDAuth6from license_protected_downloads.tests.test_openid_auth import TestOpenIDAuth
7from license_protected_downloads.tests.test_custom_commands \
8 import SetsuperuserCommandTest
79
8#starts the test suite10#starts the test suite
9__test__ = {11__test__ = {
@@ -13,4 +15,5 @@
13 'TestPep8': TestPep8,15 'TestPep8': TestPep8,
14 'TestPyflakes': TestPyflakes,16 'TestPyflakes': TestPyflakes,
15 'TestOpenIDAuth': TestOpenIDAuth,17 'TestOpenIDAuth': TestOpenIDAuth,
18 'SetsuperuserCommandTest': SetsuperuserCommandTest,
16}19}
1720
=== added file 'license_protected_downloads/tests/test_custom_commands.py'
--- license_protected_downloads/tests/test_custom_commands.py 1970-01-01 00:00:00 +0000
+++ license_protected_downloads/tests/test_custom_commands.py 2012-08-22 21:52:18 +0000
@@ -0,0 +1,26 @@
1#!/usr/bin/env python
2
3import license_protected_downloads.management.commands.setsuperuser \
4 as setsuperuser
5from django.contrib.auth.models import User
6from django.core.management.base import CommandError
7from django.test import TestCase
8
9
10class SetsuperuserCommandTest(TestCase):
11
12 def setUp(self):
13 self.command = setsuperuser.Command()
14
15 def test_find_and_update_user_non_existing(self):
16 self.assertRaises(CommandError,
17 self.command.find_and_update_user,
18 ("non_existing_user"))
19
20 def test_find_and_update_user(self):
21 user = User(username="existing_user")
22 user.save()
23 self.command.find_and_update_user("existing_user")
24 user = User.objects.get(username="existing_user")
25 self.assertEquals(user.is_staff, True)
26 self.assertEquals(user.is_superuser, True)

Subscribers

People subscribed via source and target branches