old_contents: #!/usr/bin/python
  #
  # Copyright 2011 Friday Film Club. All Rights Reserved.
  
  """Api unit tests."""
  
  
  __author__ = 'adamjmcgrath@gmail.com (Adam McGrath)'
  
  import datetime
  import os
  import sys
  import unittest
  import webtest
  import webapp2
  
  from google.appengine.api import memcache
  from google.appengine.ext import testbed
  
  TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
  sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))
  sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))
  
  import api
  import main
  import models
  
  class ApiTestCase(unittest.TestCase):
  
    def setUp(self):
      self.testbed = testbed.Testbed()
      self.testbed.activate()
      self.testbed.init_memcache_stub()
      self.testbed.init_datastore_v3_stub()
      self.testapp = webtest.TestApp(main.routes)
      question = models.Question(
          clues=[],
          answer_id='foo',
          answer_title='bar',
          answer_year=2000,
          posed=datetime.datetime.now(),
          is_current=True,
          imdb_url='http://imdb.com',
          packshot=None,
          email_msg='Message',
          # season=models.Season,
          week=1,
          answered=0
      )
  
    def tearDown(self):
      self.testbed.deactivate()
  
    def testLeaderBoardSetCache(self):
      api.set_leaderboard_cache('foo', 'bar')
      self.assertEqual(memcache.get('foo'), 'bar')
      self.assertEqual(memcache.get(api._LB_CACHE), '|foo')
  
      api.set_leaderboard_cache('bar', 'baz')
      self.assertEqual(memcache.get('bar'), 'baz')
      self.assertEqual(memcache.get(api._LB_CACHE), '|foo|bar')
  
    def testLeaderBoardSetCacheWithExisting(self):
      api.set_leaderboard_cache('foo', 'bar', existing_cache='qux|quux')
      self.assertEqual(memcache.get('foo'), 'bar')
      self.assertEqual(memcache.get(api._LB_CACHE), 'qux|quux|foo')
  
    def testLeaderBoardDeleteCache(self):
      api.set_leaderboard_cache('bar', 'baz')
      api.set_leaderboard_cache('foo', 'bar')
      api.delete_leaderboard_cache()
      self.assertEqual(memcache.get('foo'), None)
      self.assertEqual(memcache.get('bar'), None)
      self.assertEqual(memcache.get(api._LB_CACHE), None)
  
  
  if __name__ == '__main__':
      unittest.main()
new_contents: #!/usr/bin/python
  #
  # Copyright 2011 Friday Film Club. All Rights Reserved.
  
  """Api unit tests."""
  
  
  __author__ = 'adamjmcgrath@gmail.com (Adam McGrath)'
  
  import datetime
  import os
  import sys
  import unittest
  import webtest
  import webapp2
  
  from google.appengine.api import memcache
  from google.appengine.ext import testbed
  
  TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
  sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))
  sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))
  
  import api
  import main
  import mocks
  
  class ApiTestCase(unittest.TestCase):
  
    def setUp(self):
      self.testbed = testbed.Testbed()
      self.testbed.activate()
      self.testbed.init_memcache_stub()
      self.testbed.init_datastore_v3_stub()
      self.testapp = webtest.TestApp(main.routes)
      print mocks.question()
  
    def tearDown(self):
      self.testbed.deactivate()
  
    def testLeaderBoardSetCache(self):
      api.set_leaderboard_cache('foo', 'bar')
      self.assertEqual(memcache.get('foo'), 'bar')
      self.assertEqual(memcache.get(api._LB_CACHE), '|foo')
  
      api.set_leaderboard_cache('bar', 'baz')
      self.assertEqual(memcache.get('bar'), 'baz')
      self.assertEqual(memcache.get(api._LB_CACHE), '|foo|bar')
  
    def testLeaderBoardSetCacheWithExisting(self):
      api.set_leaderboard_cache('foo', 'bar', existing_cache='qux|quux')
      self.assertEqual(memcache.get('foo'), 'bar')
      self.assertEqual(memcache.get(api._LB_CACHE), 'qux|quux|foo')
  
    def testLeaderBoardDeleteCache(self):
      api.set_leaderboard_cache('bar', 'baz')
      api.set_leaderboard_cache('foo', 'bar')
      api.delete_leaderboard_cache()
      self.assertEqual(memcache.get('foo'), None)
      self.assertEqual(memcache.get('bar'), None)
      self.assertEqual(memcache.get(api._LB_CACHE), None)
  
  
  if __name__ == '__main__':
      unittest.main()
subject: add mock question