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