def check_inject(self): """ basic test case. """ schema = Schema({ Foreign: "foregin", Local: "local", Local.ref: "foreignID", }) clerk = MockClerk(schema) obj = Local() assert obj.ref is None clerk.store(Foreign(data="Here I come to save the day!")) obj.ref = Foreign(ID=1) obj.ref.addInjector(LinkInjector(clerk, Foreign, 1).inject) assert len(obj.ref.private.injectors) == 1 # should be able to fetch the ID without triggering load assert obj.ref.ID == 1 assert obj.ref.private.data == "" assert len(obj.ref.private.injectors) == 1 # but getting any other field triggers the load! assert obj.ref.data == "Here I come to save the day!" assert len(obj.ref.private.injectors) == 0
def test_validate(self): clerk = MockClerk(schema) clerk.store(Account(username="******", password="******")) auth = AccountAuth({}, clerk) assert not auth.validate({"username":"******", "password":"******"}) assert auth.validate({"username":"******", "password":"******"})
def test_recursion_bug(self): p = Node(name="project") g = Node(name="goal") p.children << g m = MockClerk(DBMAP) m.store(p) n = m.fetch(Node, g.ID) assert len(n.crumbs) == 1, len(n.crumbs)
def setUp(self): """ our test bank has two accounts: wanda and rufus. """ self.clerk = MockClerk(schema) self.clerk.store(Account(username="******")) self.clerk.store(Account(username="******")) self.bank = Bank(self.clerk)
def check_with_linkset(self): """ what happens if the thing we're injecting has a linkset of its own (this used to fail) """ class Kid(Strongbox): ID = attr(long) parent = link(forward) class Parent(Strongbox): ID = attr(long) name = attr(str) kids = linkset(Kid, "parent") Kid.parent.type = Parent class Uncle(Strongbox): brother = link(Parent) schema = Schema({ Kid: "kid", Kid.parent: "parentID", Parent: "parent", Uncle: "uncle", Uncle.brother: "brotherID", }) clerk = MockClerk(schema) kid = Kid() dad = Parent(name="Brother Dad") dad.kids << kid clerk.store(dad) unc = Uncle() unc.brother = Parent(ID=1) unc.brother.addInjector(LinkInjector(clerk, Parent, 1).inject) ## this next line threw an AttributeError because the ## injector tried to include "kids" in the .update() call assert unc.brother.name=="Brother Dad"
class BankTest(unittest.TestCase): def setUp(self): """ our test bank has two accounts: wanda and rufus. """ self.clerk = MockClerk(schema) self.clerk.store(Account(username="******")) self.clerk.store(Account(username="******")) self.bank = Bank(self.clerk) def test_zerosum(self): """ LETS currency is a zero sum game. Every credit holding account is offset by another account holding debt. """ zeroSum = lambda: 0 == sum([self.bank.balanceFor(a.username) for a in self.clerk.match(Account)]) assert zeroSum() self.bank.transfer("rufus", "wanda", 5, "test") self.assertEquals(self.bank.balanceFor("rufus"), -5) self.assertEquals(self.bank.balanceFor("wanda"), 5) assert zeroSum() def test_positive(self): """ you can't give someone a debt, or a 'nothing' """ self.assertRaises(ValueError, self.bank.transfer, "wanda", "rufus", -1, "whatever") self.assertRaises(ValueError, self.bank.transfer, "wanda", "rufus", 0, "whatever") def test_transfer_to_self(self): self.assertRaises(ValueError, self.bank.transfer, "wanda", "wanda", 1, "self transfer") def test_history(self): assert len(self.clerk.match(Transaction)) == 0 self.bank.transfer("wanda", "rufus", 1, "history test") assert len(self.clerk.match(Transaction)) == 1 t = self.clerk.fetch(Transaction, 1) assert t.src.username == "wanda" assert t.dst.username == "rufus" assert t.amount == 1 assert self.bank.balanceFor("wanda") == -1 assert len(self.bank.historyFor("wanda")) == 1
""" test cases for zikeshop.Style """ __ver__ = "$Id$" import unittest import zikeshop import zdc from zikeshop import Style from arlo import MockClerk clerk = MockClerk() #@TODO: test picture attribute class StyleTest(unittest.TestCase): pass