def testGenerateQuestion(self): varDomain = Domain(type=Domain.WHOLE_NUMBER, low=Integer(0), high=Integer(100)) template = pt.ProblemTemplate(problemName = "DirectProportionRatioProblem", body = "This is a {{amount1}} and a {{quantity1}} and a {{amount2}} and {{quantity2}}", author = None, varDomains = self.varDomains) template.put() for var in self.varDomains.keys(): v = Variable(name=var.name, domain=self.varDomains[var], parent=template) v.put() p = pt.GenerateQuestion(init.directProportionCategory, varDomain, 'mc', False) variables = Variable.all().ancestor(template) for v in variables: v.delete() template.delete() self.assertEqual(p, "This is a 30 and a 60 and a 66 and ?<ol type='a'><li>132</li><li>43</li><li>15</li><li>58</li><li>60</li></ol>")
def post(self): template = self.processPostData() template.put() key = self.request.params.get("_key") problemName = template.problemName action = self.request.params.get("action") if key: if action == "Delete": for variable in Variable.all().ancestor(template): variable.delete() template.delete() else: for variable in Variable.all().ancestor(template): type = self.request.params.get(variable.name) variable.setDomain(Domain.defaultDomain(Domain.externalToInternalType(type))) variable.put() else: problem = Category.allProblems[problemName] for v in problem.variables: type = self.request.params.get(v.name) vdomain = Domain.defaultDomain(Domain.externalToInternalType(type)) variable = Variable(name=v.name, domain=vdomain, parent=template) variable.put() self.render(template)