tests/app/soc/logic/models/test_user.py
changeset 1530 83a04a557d0d
child 1547 c8c269ef0498
equal deleted inserted replaced
1529:0800753ebc6a 1530:83a04a557d0d
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2009 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 
       
    18 __authors__ = [
       
    19   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
       
    20   ]
       
    21 
       
    22 
       
    23 import unittest
       
    24 
       
    25 from google.appengine.api import users
       
    26 
       
    27 from soc.models import user
       
    28 from soc.logic.models.user import logic as user_logic
       
    29 
       
    30 
       
    31 class UserTest(unittest.TestCase):
       
    32   """Tests related to user logic.
       
    33   """
       
    34 
       
    35   def setUp(self):
       
    36     """Set up required for the slot allocation tests.
       
    37     """
       
    38 
       
    39     # ensure that current user is created
       
    40     properties = {
       
    41         'account': users.get_current_user(),
       
    42         'link_id': 'current_user',
       
    43         'name': 'Current User',
       
    44         }
       
    45 
       
    46     key_name = user_logic.getKeyNameFromFields(properties)
       
    47     user_logic.updateOrCreateFromKeyName(properties, key_name)
       
    48 
       
    49   def testNormalEntity(self):
       
    50     """
       
    51     """
       
    52 
       
    53     # create a user not in the auth domain
       
    54     email = "test@example.com"
       
    55     account = users.User(email=email)
       
    56     link_id = 'normal_user'
       
    57     name = 'Normal User'
       
    58 
       
    59     properties = {
       
    60         'account': account,
       
    61         'link_id': link_id,
       
    62         'name': name,
       
    63         }
       
    64 
       
    65     key_name = user_logic.getKeyNameFromFields(properties)
       
    66     entity = user_logic.updateOrCreateFromKeyName(properties, key_name)
       
    67 
       
    68     self.failUnlessEqual(account, entity.account)
       
    69     self.failUnlessEqual(link_id, entity.link_id)
       
    70     self.failUnlessEqual(name, entity.name)
       
    71 
       
    72   def testAuthEntity(self):
       
    73     """
       
    74     """
       
    75 
       
    76     # create a user from the auth domain
       
    77     email = "test@gmail.com"
       
    78     account = users.User(email=email)
       
    79     link_id = 'auth_user'
       
    80     name = 'Auth User'
       
    81 
       
    82     properties = {
       
    83         'account': account,
       
    84         'link_id': link_id,
       
    85         'name': name,
       
    86         }
       
    87 
       
    88     key_name = user_logic.getKeyNameFromFields(properties)
       
    89     entity = user_logic.updateOrCreateFromKeyName(properties, key_name)
       
    90 
       
    91     self.failIfEqual(account, entity.account)
       
    92     self.failUnlessEqual('test', entity.account.email())
       
    93     self.failUnlessEqual(link_id, entity.link_id)
       
    94     self.failUnlessEqual(name, entity.name)
       
    95 
       
    96   def testCapsAuthEntity(self):
       
    97     """
       
    98     """
       
    99 
       
   100     # create a user from the auth domain
       
   101     email = "CaPS@example.com"
       
   102     account = users.User(email=email)
       
   103     link_id = 'caps_user'
       
   104     name = 'Caps User'
       
   105 
       
   106     properties = {
       
   107         'account': account,
       
   108         'link_id': link_id,
       
   109         'name': name,
       
   110         }
       
   111 
       
   112     key_name = user_logic.getKeyNameFromFields(properties)
       
   113     entity = user_logic.updateOrCreateFromKeyName(properties, key_name)
       
   114 
       
   115     self.failIfEqual(account, entity.account)
       
   116     self.failUnlessEqual('caps@example.com', entity.account.email())
       
   117     self.failUnlessEqual(link_id, entity.link_id)
       
   118     self.failUnlessEqual(name, entity.name)