launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #08493
[Merge] lp:~jtv/maas/migrate-userprofile-tests into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/migrate-userprofile-tests into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/migrate-userprofile-tests/+merge/108657
As per the migration plan. No surprises, really. I'm finding that the planned-out steps remove a lot of the room for error. The biggest problem I've had so far was forgetting to “bzr add” newly-added modules; I deal with that now by getting that step over with before I even start editing a new module.
Jeroen
--
https://code.launchpad.net/~jtv/maas/migrate-userprofile-tests/+merge/108657
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/migrate-userprofile-tests into lp:maas.
=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py 2012-05-31 10:56:10 +0000
+++ src/maasserver/tests/test_models.py 2012-06-04 23:26:20 +0000
@@ -18,7 +18,6 @@
)
from django.conf import settings
-from django.contrib.auth.models import User
from django.core.exceptions import (
PermissionDenied,
ValidationError,
@@ -30,22 +29,16 @@
NODE_STATUS_CHOICES,
NODE_STATUS_CHOICES_DICT,
)
-from maasserver.exceptions import (
- CannotDeleteUserException,
- NodeStateViolation,
- )
+from maasserver.exceptions import NodeStateViolation
from maasserver.models import (
Config,
create_auth_token,
- GENERIC_CONSUMER,
get_auth_tokens,
get_db_state,
MACAddress,
Node,
NODE_TRANSITIONS,
now,
- SYSTEM_USERS,
- UserProfile,
)
from maasserver.provisioning import get_provisioning_api_proxy
from maasserver.testing import reload_object
@@ -66,10 +59,8 @@
NodeUserData,
)
from piston.models import (
- Consumer,
KEY_SIZE,
SECRET_SIZE,
- Token,
)
from provisioningserver.enum import POWER_TYPE
from provisioningserver.power.poweraction import PowerAction
@@ -947,83 +938,3 @@
token.is_approved = False
token.save()
self.assertNotIn(token, get_auth_tokens(user))
-
-
-# Scheduled for model migration on 2012-06-05
-class UserProfileTest(TestCase):
-
- def test_profile_creation(self):
- # A profile is created each time a user is created.
- user = factory.make_user()
- self.assertIsInstance(user.get_profile(), UserProfile)
- self.assertEqual(user, user.get_profile().user)
-
- def test_consumer_creation(self):
- # A generic consumer is created each time a user is created.
- user = factory.make_user()
- consumers = Consumer.objects.filter(user=user, name=GENERIC_CONSUMER)
- self.assertEqual([user], [consumer.user for consumer in consumers])
-
- def test_token_creation(self):
- # A token is created each time a user is created.
- user = factory.make_user()
- [token] = get_auth_tokens(user)
- self.assertEqual(user, token.user)
-
- def test_create_authorisation_token(self):
- # UserProfile.create_authorisation_token calls create_auth_token.
- user = factory.make_user()
- profile = user.get_profile()
- consumer, token = profile.create_authorisation_token()
- self.assertEqual(user, token.user)
- self.assertEqual(user, consumer.user)
-
- def test_get_authorisation_tokens(self):
- # UserProfile.get_authorisation_tokens calls get_auth_tokens.
- user = factory.make_user()
- consumer, token = user.get_profile().create_authorisation_token()
- self.assertIn(token, user.get_profile().get_authorisation_tokens())
-
- def test_delete(self):
- # Deleting a profile also deletes the related user.
- profile = factory.make_user().get_profile()
- profile_id = profile.id
- user_id = profile.user.id
- self.assertTrue(User.objects.filter(id=user_id).exists())
- self.assertTrue(
- UserProfile.objects.filter(id=profile_id).exists())
- profile.delete()
- self.assertFalse(User.objects.filter(id=user_id).exists())
- self.assertFalse(
- UserProfile.objects.filter(id=profile_id).exists())
-
- def test_delete_consumers_tokens(self):
- # Deleting a profile deletes the related tokens and consumers.
- profile = factory.make_user().get_profile()
- token_ids = []
- consumer_ids = []
- for i in range(3):
- token, consumer = profile.create_authorisation_token()
- token_ids.append(token.id)
- consumer_ids.append(consumer.id)
- profile.delete()
- self.assertFalse(Consumer.objects.filter(id__in=consumer_ids).exists())
- self.assertFalse(Token.objects.filter(id__in=token_ids).exists())
-
- def test_delete_attached_nodes(self):
- # Cannot delete a user with nodes attached to it.
- profile = factory.make_user().get_profile()
- factory.make_node(owner=profile.user)
- self.assertRaises(CannotDeleteUserException, profile.delete)
-
- def test_manager_all_users(self):
- users = set(factory.make_user() for i in range(3))
- all_users = set(UserProfile.objects.all_users())
- self.assertEqual(users, all_users)
-
- def test_manager_all_users_no_system_user(self):
- for i in range(3):
- factory.make_user()
- usernames = set(
- user.username for user in UserProfile.objects.all_users())
- self.assertTrue(set(SYSTEM_USERS).isdisjoint(usernames))
=== added file 'src/maasserver/tests/test_userprofile.py'
--- src/maasserver/tests/test_userprofile.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_userprofile.py 2012-06-04 23:26:20 +0000
@@ -0,0 +1,107 @@
+# Copyright 2012 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the UserProfile model."""
+
+from __future__ import (
+ absolute_import,
+ print_function,
+ unicode_literals,
+ )
+
+__metaclass__ = type
+__all__ = []
+
+from django.contrib.auth.models import User
+from maasserver.exceptions import CannotDeleteUserException
+from maasserver.models import (
+ GENERIC_CONSUMER,
+ get_auth_tokens,
+ SYSTEM_USERS,
+ UserProfile,
+ )
+from maasserver.testing.factory import factory
+from maasserver.testing.testcase import TestCase
+from piston.models import (
+ Consumer,
+ Token,
+ )
+
+
+class UserProfileTest(TestCase):
+
+ def test_profile_creation(self):
+ # A profile is created each time a user is created.
+ user = factory.make_user()
+ self.assertIsInstance(user.get_profile(), UserProfile)
+ self.assertEqual(user, user.get_profile().user)
+
+ def test_consumer_creation(self):
+ # A generic consumer is created each time a user is created.
+ user = factory.make_user()
+ consumers = Consumer.objects.filter(user=user, name=GENERIC_CONSUMER)
+ self.assertEqual([user], [consumer.user for consumer in consumers])
+
+ def test_token_creation(self):
+ # A token is created each time a user is created.
+ user = factory.make_user()
+ [token] = get_auth_tokens(user)
+ self.assertEqual(user, token.user)
+
+ def test_create_authorisation_token(self):
+ # UserProfile.create_authorisation_token calls create_auth_token.
+ user = factory.make_user()
+ profile = user.get_profile()
+ consumer, token = profile.create_authorisation_token()
+ self.assertEqual(user, token.user)
+ self.assertEqual(user, consumer.user)
+
+ def test_get_authorisation_tokens(self):
+ # UserProfile.get_authorisation_tokens calls get_auth_tokens.
+ user = factory.make_user()
+ consumer, token = user.get_profile().create_authorisation_token()
+ self.assertIn(token, user.get_profile().get_authorisation_tokens())
+
+ def test_delete(self):
+ # Deleting a profile also deletes the related user.
+ profile = factory.make_user().get_profile()
+ profile_id = profile.id
+ user_id = profile.user.id
+ self.assertTrue(User.objects.filter(id=user_id).exists())
+ self.assertTrue(
+ UserProfile.objects.filter(id=profile_id).exists())
+ profile.delete()
+ self.assertFalse(User.objects.filter(id=user_id).exists())
+ self.assertFalse(
+ UserProfile.objects.filter(id=profile_id).exists())
+
+ def test_delete_consumers_tokens(self):
+ # Deleting a profile deletes the related tokens and consumers.
+ profile = factory.make_user().get_profile()
+ token_ids = []
+ consumer_ids = []
+ for i in range(3):
+ token, consumer = profile.create_authorisation_token()
+ token_ids.append(token.id)
+ consumer_ids.append(consumer.id)
+ profile.delete()
+ self.assertFalse(Consumer.objects.filter(id__in=consumer_ids).exists())
+ self.assertFalse(Token.objects.filter(id__in=token_ids).exists())
+
+ def test_delete_attached_nodes(self):
+ # Cannot delete a user with nodes attached to it.
+ profile = factory.make_user().get_profile()
+ factory.make_node(owner=profile.user)
+ self.assertRaises(CannotDeleteUserException, profile.delete)
+
+ def test_manager_all_users(self):
+ users = set(factory.make_user() for i in range(3))
+ all_users = set(UserProfile.objects.all_users())
+ self.assertEqual(users, all_users)
+
+ def test_manager_all_users_no_system_user(self):
+ for i in range(3):
+ factory.make_user()
+ usernames = set(
+ user.username for user in UserProfile.objects.all_users())
+ self.assertTrue(set(SYSTEM_USERS).isdisjoint(usernames))
Follow ups