def test_save(self):
     eval_id = Evaluation.create('Edit Test Name', self.card_id).id()
     category1_id = EvalCategory.create('Eval Save Test Cat 1', self.card_id).id()
     category2_id = EvalCategory.create('Eval Save Test Cat 2', self.card_id).id()
     item1_id = EvalItem.create('Eval Save Test Item 1', category1_id).id()
     item2_id = EvalItem.create('Eval Save Test Item 2', category1_id).id()
     item3_id = EvalItem.create('Eval Save Test Item 3', category2_id).id()
     text_line1_id = TextLine.create('Eval Save Test Text Line 1', self.card_id).id()
     text_line2_id = TextLine.create('Eval Save Test Text Line 2', self.card_id).id()
     
     response = self.testapp.post('/eval/%d/save' % eval_id, 
         {'comments': 'Comments', 
          'item_%d_score' % item1_id: '1', 
          'item_%d_score' % item2_id: '2', 
          'item_%d_score' % item3_id: '3',
          'text_%d_value' % text_line1_id: 'Text 1',
          'text_%d_value' % text_line2_id: 'Text 2',
         }
     )
     self.assertRedirect('/eval/\d*/fill$', response)
     eval = Evaluation.find_by_id(eval_id)
     data = eval.all_data()
     self.assertEqual('Comments', data['comments'])
     self.assertEqual('1', data['items'][item1_id])
     self.assertEqual('2', data['items'][item2_id])
     self.assertEqual('3', data['items'][item3_id])
     self.assertEqual('Text 1', data['text'][text_line1_id])
     self.assertEqual('Text 2', data['text'][text_line2_id])
 def test_move_up(self):
     text_line1_id = TextLine.create('Move Up Test Name 1', self.card_id).id()
     text_line2_id = TextLine.create('Move Up Test Name 2', self.card_id).id()
     self.assertRaises(Exception, self.testapp.post, '/text_line/%d/move_up' % text_line1_id)
     response = self.testapp.post('/text_line/%d/move_up' % text_line2_id)
     self.assertSuccess(response)
     card = ReportCard.find_by_id(self.card_id)
     text_lines = card.text_lines()
     self.assertEqual(2, len(text_lines))
     self.assertEqual(text_line2_id, text_lines[0].key().id())
     self.assertEqual(text_line1_id, text_lines[1].key().id())
 def test_preview(self):
     e = Evaluation.create('Preview Test Name', self.card_id)
     category1_id = EvalCategory.create('Eval Preview Test Cat 1', self.card_id).id()
     category2_id = EvalCategory.create('Eval Preview Test Cat 2', self.card_id).id()
     item1_id = EvalItem.create('Eval Preview Test Item 1', category1_id).id()
     item2_id = EvalItem.create('Eval Preview Test Item 2', category1_id).id()
     item3_id = EvalItem.create('Eval Preview Test Item 3', category2_id).id()
     text_line1_id = TextLine.create('Eval Preview Test Text Line 1', self.card_id).id()
     text_line2_id = TextLine.create('Eval Preview Test Text Line 2', self.card_id).id()
     response = self.testapp.get('/eval/%d/preview' % e.id())
     self.assertSuccess(response)
 def add(self, card_id):
     card = ReportCard.find_by_id(int(card_id))
     if card.is_authorized():
         text_line_id = TextLine.create(self.request.get('name'), int(card_id)).id()
         text_line = TextLine.find_by_id(text_line_id)
         template = JinjaEnv.get().get_template('templates/text_line/edit_row.html')
         self.response.out.write(template.render({'text_line': text_line}))
 def test_edit(self):
     text_line_id = TextLine.create('Edit Test Name', self.card_id).id()
     response = self.testapp.post('/text_line/%d/edit' % text_line_id, {'name': 'Edit Test New Name'})
     self.assertSuccess(response)
     card = ReportCard.find_by_id(self.card_id)
     self.assertEqual(1, len(card.text_lines()))
     self.assertEqual('Edit Test New Name', card.text_lines()[0].name)
 def test_delete(self):
     text_line_id = TextLine.create('Delete Test Name', self.card_id).id()
     response = self.testapp.post('/text_line/%d/delete' % text_line_id)
     self.assertSuccess(response)
     card = ReportCard.find_by_id(self.card_id)
     self.assertEqual(0, len(card.text_lines()))
 def test_delete_form(self):
     text_line_id = TextLine.create('Delete Form Test Name', self.card_id).id()
     response = self.testapp.get('/text_line/%d/delete_form' % text_line_id)
     self.assertSuccess(response)