tests/app/soc/cache/test_sidebar.py
author Sverre Rabbelier <srabbelier@gmail.com>
Fri, 13 Feb 2009 23:18:39 +0000
changeset 1308 35b75ffcbb37
parent 1055 61c2d296cd91
child 1477 c724a6eda7ef
permissions -rw-r--r--
Partially reverted "Update the copyright notice for 2009." This partially reverts commit r1933. Only the files that were created in 2008 were reverted. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1055
diff changeset
     3
# Copyright 2009 the Melange authors.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
__authors__ = [
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
  ]
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    23
import unittest
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    24
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from google.appengine.api import users
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from google.appengine.api import memcache
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from soc.cache import sidebar
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
class SidebarCacheTest(unittest.TestCase):
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    32
  """Tests that the sidebar properly uses caching.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
  """
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
  def setUp(self):
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
    self.called = 0
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
    self.user = users.get_current_user()
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
  def tearDown(self):
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
    memcache.flush_all()
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  def testGetCurrentUser(self):
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    43
    """Sanity check to see if get_current_user returns same value.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
    """
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    self.assertEqual(self.user, users.get_current_user())
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  def testKey(self):
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    49
    """Test that the key method returns a unique key.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
    """
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    self.assertEqual("sidebar_for_users.User(email='test@example.com')",
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
                     sidebar.key(self.user))
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
  def testGet(self):
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    56
    """Test that get without setting something returns None.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
    """
1055
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    58
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    59
    self.assertEqual(None, sidebar.get('id', None))
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
  def testGetPut(self):
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    62
    """Test that getting after putting gives back what you put in.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    """
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
1055
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    65
    sidebar.put(42, 'id', None)
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    66
    self.assertEqual(42, sidebar.get('id', None))
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
  def testFlush(self):
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    69
    """Test that getting after putting and flushing returns None.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
    """
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
1055
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    72
    sidebar.put(42, 'id', None)
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    73
    sidebar.flush('id')
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    74
    self.assertEqual(None, sidebar.get('id', None))
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
  def testCache(self):
1027
9633a6a5e5f9 Style and import sorting fixes in tests modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1009
diff changeset
    77
    """Test that the result of a cached sidebar is cached.
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
    """
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
    @sidebar.cache
1055
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    81
    def getAnswer(x, y):
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
      self.called = self.called + 1
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
      return 42
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
1055
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    85
    self.assertEqual(42, getAnswer('id', None))
61c2d296cd91 Update test to match new sidebar caching signature
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1027
diff changeset
    86
    self.assertEqual(42, getAnswer('id', None))
1009
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
    self.assertEqual(self.called, 1)
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
7abbbfc79f3a Added some very basic tests for the sidebar and access modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89