def setUp(self): self.myReq = weblib.RequestBuilder().build(method="GET", querystring="", path="/", form={}, cookie={}, content={}) self.myRes = weblib.Response() self.sess = Sess(InMemorySessPool(), self.myReq, self.myRes)
def test_QuerySid(self): """ if no cookie, sess should read from the querystring """ req = self.builder.build(querystring="weblib.Sess=ABC") sess = weblib.Sess(self.pool, req, weblib.Response()) actual = sess._getSid() assert actual == "ABC", \ "getSid doesn't read the querystring (fallback): %s" % actual
def test_CookieSid(self): """ sess should read sid from the cookie. """ req = self.builder.build(cookie={"weblib.Sess": "123"}, querystring="weblib.Sess=ABC") sess = weblib.Sess(self.pool, req, weblib.Response()) actual = sess._getSid() assert actual == "123", \ "getSid doesn't read the cookie: %s.." % actual
def setUp(self): # auth requires a PATH_INFO variable.. otherwise, # it doesn't know where to redirect the form. # # @TODO: is PATH_INFO correct? I think standard might be SCRIPT_NAME # self.myReq = weblib.Request(environ={"PATH_INFO":"dummy.py"}) self.myRes = weblib.Response() self.sess = weblib.Sess(weblib.SessPool.InMemorySessPool(), self.myReq, self.myRes)
def check_prompt(self): wres = weblib.Response() sess = weblib.Sess(weblib.SessPool.InMemorySessPool(), self.myReq, wres) auth = zikebase.UserAuth(sess, self.ds) try: auth.check() gotExit = 0 except SystemExit: gotExit = 1 assert gotExit, \ "should have demanded login" assert string.find(wres.buffer, auth.PLEASELOGIN) > -1, \ "doesn't show prompt!"
def setUp(self, sid=None): self.builder = weblib.RequestBuilder() self.pool = SessPool.InMemorySessPool({}) self.sess = weblib.Sess(self.pool, self.builder.build(), weblib.Response()) self.sess.start(sid)
def makeResponse(self): return weblib.Response()
def check_checkout(self): ## THIS IS ONE *LONG* TEST............... import zikeshop from zikeshop.public.checkout import CheckoutApp import weblib weblib.request = weblib.Request() myCart = zikeshop.Cart({}) myCart.add("super-evil-destructo-ray") app = CheckoutApp({}, myCart, clerk, self.sess) # check for xxxData app.enter() assert app.billData["fname"] == "", "didn't create blank bill address" assert app.shipData["fname"] == "", "didn't create blank ship address" assert app.cardData["number"] is None, "didn't create blank card" # just call get_billing to make sure no error. # @TODO: compare this to an expected version.. RES = weblib.Response() app.do("get_billing") # try adding a bad address app.input = { "context": "bill", "fname": "michal", "lname": "wallace", "email": "INVALID_EMAIL", "address1": "123 easy street", "city": "Atlanta", "stateCD": "GA", "countryCD": "US", "postal": "76126", } app.do("add_address") assert app.model["errors"], \ "didn't get errors with invalid email: %s" \ % str(app.model["errors"]) assert app.next == "get_billing", "didn't redirect to billing page" # fix the error, try again: app.model["errors"] = [] app.input["email"] = "*****@*****.**" self.assertRaises(weblib.Redirect, app.do, "add_address") assert not app.model["errors"], \ "STILL got error: %s" % str(app.model["errors"]) assert app.next=="get_shipping", \ "didn't redirect to shipping page when no shipToBilling: %s" \ % app.next # try showing the get_shipping form: # @TODO: compare this to an expected version.. app.do("get_shipping") # ship to billing box.. app.input["shipToBilling"] = "1" self.assertRaises(weblib.Redirect, app.do, "add_address") assert app.next=="get_card", \ "didn't redirect to card page when shipToBilling: %s" \ % app.next assert app.billData == app.shipData, "didn't copy billing data" assert app.shipData["fname"]=="michal", \ "REALLY didn't copy billing data" # send that super-evil-destructo-ray to my mom instead: app.input["context"] = "ship" app.input["fname"] = "cathy" app.input["city"] = "benbrook" app.input["stateCD"] = "TX" self.assertRaises(weblib.Redirect, app.do, "add_address") assert app.shipData["fname"] == "cathy", "didn't set ship data" assert app.billData["fname"] == "michal", "overwrote bill data" assert app.next=="get_card",\ "didn't redirect to card page after shipping: %s" \ % app.next # credit card form # @TODO: compare this to an expected version.. app.do("get_card") assert app.cardData["name"]=="michal wallace", \ "didn't guess name from billing" # submit a card: fakeCard = "4111111111111119" goodCard = "4111111111111111" from zikeshop.Card import validate assert validate(fakeCard) == 0, "didn't catch fake card" assert validate(goodCard) == 1, "didn't pass good card" import time nowYear, nowMonth = time.localtime(time.time())[0:2] app.input = { "name": "Michal J Wallace", "number": fakeCard, "expMonth": str(nowMonth + 1), "expYear": str(nowYear), } #import pdb; pdb.set_trace() app.do("add_card") #@TODO: these ought not be called "add"_XXX anymore #@TODO: app.errors ought to jump automatically into model["errors"] assert app.model["errors"]==[{"error":"Invalid credit card number."}],\ "didn't catch invalid card: %s" % str(app.model["errors"]) assert app.next == "get_card", "didn't cue get_card after bad card" # expired card: app.model["errors"] = [] app.input["number"] = goodCard app.input["expYear"] = str(nowYear - 1) app.do("add_card") assert app.model["errors"]==[{"error":"Expired card."}],\ "didn't catch expired card: %s" % str(app.model["errors"]) # finally, get it all right... app.model["errors"] = [] app.input["expYear"] = nowYear + 1 self.assertRaises(weblib.Redirect, app.do, "add_card") assert app.model["errors"]==[], \ "STILL got error after everything is right" assert app.next=="confirm", \ "didn't redirect to confirmation page: %s" \ % app.next # show the confirmation page #@TODO: compare to expected app.do("confirm")