Friday, January 02, 2009

Fitnesse ArrayFixture: my simple example

Recently I've been fighting with Fitnesse, specifically a pyFit server, trying to get an ArrayFixture to run properly. The only example of ArrayFixture I could find was the generic one. Here is a better example of ArrayFixture.

I'm calling this from within a DoFixture, mind you, so sorry if there's that added complication, but you should be able to figure out what's happening based on this.

class LwRow(object):

_typeDict = {}

def __init__(self):
self.rowNumber = None ; self._typeDict['rowNumber' ] = "Int"
self.indent = None ; self._typeDict['indent' ] = "Int"
self.refobjType = None ; self._typeDict['refobjType'] = "String"
self.refobjId = None ; self._typeDict['refobjId' ] = "Int"
self.sNumber = None ; self._typeDict['sNumber' ] = "String"
# ... blah more here...

def name(self):
self._typeDict['name'] = "String"
return self.linkOrgEditContractorText or ''

def getSetOfRowObjects(self):
rows = []
obj = LwRow()
obj.rowNumber = 1
obj.indent = 3
# ... more setting here...
# blah, repeat, appending more rows...
return rows

class ReviewLwsArrayFixture(ArrayFixture):

def __init__(self, p, c, dr, user, trans=None):
rows = []
#... do stuff here to retrieve data...
retData = getSetOfRowObjects()
print "Have retData=%s" % (pformat(retData))

self.paramCollection = retData

def getTargetClass(self):
return LwRow

def reviewLwsArrayAsUserPpCcDrUser(self, p, c, dr, user, trans):
return self.ReviewLwsArrayFixture(p=p, c=c, dr=dr, user=user, trans=trans)

# then you can write your UAT / Fitnesse code as follows.
# Note that I can use ANY attribute of the lwRow object without declaring it
# in my arrayfixture code (I have LwRow declared in a non-fixture related module)

|review lws array as user | gcUser| pp | p1 | cc | c1 | dr| Dr1 |
|rowNumber|name|indent|refobj type|
|1|manual name one|Manual|False|
|2|subMc1|LW Sub|True|
|3|subMc2|LW Sub|True|
|4|subMc3|LW Sub|True|

and / or:

|review lws array as user | gcUser| pp | p1 | cc | c1 | dr| Dr1 |

That's it!
Post a Comment