Skip to content

Commit

Permalink
test appmaker
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdonc committed Nov 23, 2010
1 parent a7bcf68 commit 6fbce72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
14 changes: 3 additions & 11 deletions cluegun/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import transaction

from datetime import datetime
from persistent import Persistent

Expand Down Expand Up @@ -26,19 +28,9 @@ def __init__(self, author_name, paste, language):
self.language = language
self.date = datetime.now()

def appmaker(root):
def appmaker(root, transaction=transaction):
if not root.has_key('cluegun.pastebin'):
root['cluegun.pastebin'] = PasteBin()
import transaction
transaction.commit()
return root['cluegun.pastebin']

def NonPersistentRootFinder(db_path):
bin = PasteBin()
def get_root(environ):
return bin
return get_root




25 changes: 25 additions & 0 deletions cluegun/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,28 @@ def test_ctor(self):
self.assertEqual(entry.language, 'language')
self.failUnless(entry.date)

class Test_appmaker(unittest.TestCase):
def _callFUT(self, root, txn):
from cluegun.models import appmaker
return appmaker(root, txn)

def test_already_exists(self):
root = {'cluegun.pastebin':'abc'}
txn = DummyTransaction()
result = self._callFUT(root, txn)
self.assertEqual(result, 'abc')
self.failIf(txn.committed)

def test_doesnt_exist(self):
from cluegun.models import PasteBin
root = {}
txn = DummyTransaction()
result = self._callFUT(root, txn)
self.assertEqual(result.__class__, PasteBin)
self.failUnless(txn.committed)

class DummyTransaction(object):
committed = False
def commit(self):
self.committed = True

0 comments on commit 6fbce72

Please sign in to comment.