def testGridToDesigner(self): """Tests instantiating a DesignerAction from an Action.""" # clear the existing DesignerActions, if any. for des_act in DesignerAction.objects.filter(draft=self.draft, slug=self.action_slug): des_act.delete() action = smartgrid_mgr.get_smartgrid_action(self.action_slug) des_action = smartgrid_mgr.instantiate_designer_action_from_smartgrid(self.draft, \ slug=action.slug) self.assertTrue( des_action, "Couldn't instantiate designer action %s" % action.slug) self.assertTrue(smartgrid_mgr.get_designer_action(self.draft, self.action_slug), \ "Couldn't retrieve the designer action %s" % self.action_slug) # ensure the TextPropmptQuestions are there for tpq in TextPromptQuestion.objects.filter(action=action): try: des_tpq = get_object_or_404(DesignerTextPromptQuestion, draft=self.draft, \ question=tpq.question, answer=tpq.answer, \ action=des_action) self.assertTrue(des_tpq, "Couldn't get DesignerTextPromptQuestion") except Http404: self.fail("Couldn't find DesignerTextPromptQuestion for %s" % tpq)
def testGridToDesigner(self): """Tests instantiating a DesignerAction from an Action.""" # clear the existing DesignerActions, if any. for des_act in DesignerAction.objects.filter(draft=self.draft, slug=self.action_slug): des_act.delete() action = smartgrid_mgr.get_smartgrid_action(self.action_slug) des_action = smartgrid_mgr.instantiate_designer_action_from_smartgrid(self.draft, \ slug=action.slug) self.assertTrue(des_action, "Couldn't instantiate designer action %s" % action.slug) self.assertTrue(smartgrid_mgr.get_designer_action(self.draft, self.action_slug), \ "Couldn't retrieve the designer action %s" % self.action_slug) # ensure the TextPropmptQuestions are there for tpq in TextPromptQuestion.objects.filter(action=action): try: des_tpq = get_object_or_404(DesignerTextPromptQuestion, draft=self.draft, \ question=tpq.question, answer=tpq.answer, \ action=des_action) self.assertTrue(des_tpq, "Couldn't get DesignerTextPromptQuestion") except Http404: self.fail("Couldn't find DesignerTextPromptQuestion for %s" % tpq)
def testPublishToGrid(self): """Tests publishing a DesignerGrid to the SmartGrid.""" # set up really fake designer grid self.client.get(reverse('instantiate_action', \ args=(self.action_slug, self.level_slug, 2, 2, self.draft_slug))) self.client.get(reverse('instantiate_column', \ args=(self.column_slug, self.level_slug, 2, self.draft_slug))) response = self.client.post(reverse('publish_to_grid', args=(self.draft_slug, )), \ {}, follow=True) self.failUnlessEqual(response.status_code, 200) try: level = smartgrid_mgr.get_smartgrid_level(slug=self.level_slug) except Http404: self.fail("Didn't copy level to smartgrid") try: column = smartgrid_mgr.get_smartgrid_column_name(slug=self.column_slug) except Http404: self.fail("Didn't copy ColumnName to smartgrid") try: action = smartgrid_mgr.get_smartgrid_action(slug=self.action_slug) except Http404: self.fail("Didn't copy Action to smartgrid") qs = ColumnGrid.objects.filter(name=column) self.failUnlessEqual(len(qs), 1, "Didn't put column in the grid") loc = qs[0] self.failUnlessEqual(loc.level, level, "Wrong level for column name") self.failUnlessEqual(loc.column, 2, "Wrong column for column name") qs = Grid.objects.filter(action=action) self.failUnlessEqual(len(qs), 1, "Didn't put action in the grid") loc = qs[0] self.failUnlessEqual(loc.level, level, "Wrong level for action") self.failUnlessEqual(loc.column, 2, "Wrong column for action") self.failUnlessEqual(loc.row, 2, "Wrong row for action")