Ticket #701: test_catwalk_701.py

File test_catwalk_701.py, 1.7 kB (added by JoostM, 2 years ago)

testcase

Line 
1 import unittest
2 from turbogears import testutil
3 from turbogears.toolbox.catwalk import CatWalk
4
5 from sqlobject import *
6 import cherrypy
7
8 # creating a fake model
9 sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
10 class PetOwner(SQLObject):
11     name = StringCol()
12     pets = MultipleJoin('Pet')
13
14 class Pet(SQLObject):
15     name = StringCol()
16     # Note that SQLObject 0.7.x uses the MixedCaseStyle.
17     # (http://www.sqlobject.org/SQLObject.html#changing-the-naming-style)
18     petOwner = ForeignKey('PetOwner', default=None)
19
20
21 # Setting up the testing environment
22 import new
23 model = new.module('model')
24 model.PetOwner = PetOwner
25 model.Pet = Pet
26 cherrypy.root = CatWalk(model)
27
28 # testcase for ticket 701
29 class TestTicket701(testutil.DBTest):
30     model=model
31
32     def test_model(self):
33         assert model.PetOwner.select().count() == 0
34         model.PetOwner(name='Tim')
35         assert model.PetOwner.select().count() == 1
36         assert model.PetOwner.select()[0].name == 'Tim'
37         assert model.PetOwner.select()[0].pets == []
38        
39     def test_ticket_701(self):
40         # /browse works when there are no SecLevel instances
41         assert model.PetOwner.select().count() == 0
42         testutil.createRequest("/browse/?object_name=PetOwner")
43         assert cherrypy.response.status == '200 OK', cherrypy.response.status
44         # so we create one
45         testutil.createRequest("/add?objectName=PetOwner&name=Tim")
46         assert cherrypy.response.status == '200 OK', cherrypy.response.status
47         assert model.PetOwner.select().count() == 1
48         # request /browse wille now bomb out
49         testutil.createRequest("/browse/?object_name=PetOwner")
50         assert cherrypy.response.status == '200 OK', cherrypy.response.status
51