Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 13b13185d5
Fetching contributors…

Cannot retrieve contributors at this time

file 41 lines (29 sloc) 0.933 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#!/usr/bin/python
"""Fake model classes used in unit tests.
"""

__author__ = ['Ryan Barrett <salmon@ryanb.org>']

import models

from google.appengine.ext import db


class FakeBase(db.Model):
  """Not thread safe.
"""

  key_name_counter = 1

  @classmethod
  def new(cls, handler, **props):
    if 'url' not in props:
      props['url'] = 'http://fake/url'
    inst = cls(key_name=str(cls.key_name_counter), **props)
    cls.key_name_counter += 1
    return inst


class FakeSource(FakeBase, models.Source):
  """A fake Source class.

Class attributes:
salmon: dict mapping FakeSource string key to list of dicts to be
returned by poll(). Can't just store in an instance attribute because
tasks.py code loads entities from the datastore.
"""
  salmon = {}

  def set_salmon(self, salmon):
    FakeSource.salmon[str(self.key())] = salmon

  def get_salmon(self):
    return FakeSource.salmon[str(self.key())]
Something went wrong with that request. Please try again.