def test_order_is_not_dependent_on_another_batch(self): question = Question.objects.create(text="This is a question", answer_type=Question.NUMBER) question_2 = Question.objects.create(text="This is another question", answer_type=Question.NUMBER) question_3 = Question.objects.create( text="This is a question in other batch", answer_type=Question.NUMBER) batch = Batch.objects.create(order=1, name="Batch A") batch_2 = Batch.objects.create(order=2, name="Batch B") question.batches.add(batch) question_2.batches.add(batch_2) question_3.batches.add(batch_2) BatchQuestionOrder.objects.create(question=question, batch=batch, order=1) BatchQuestionOrder.objects.create(question=question_2, batch=batch_2, order=2) BatchQuestionOrder.objects.create(question=question_3, batch=batch_2, order=1) self.assertEqual(2, BatchQuestionOrder.next_question_order_for(batch)) self.assertEqual(3, BatchQuestionOrder.next_question_order_for(batch_2))
def test_order_is_not_dependent_on_another_batch(self): question = Question.objects.create(text="This is a question", answer_type=Question.NUMBER) question_2 = Question.objects.create(text="This is another question", answer_type=Question.NUMBER) question_3 = Question.objects.create(text="This is a question in other batch", answer_type=Question.NUMBER) batch = Batch.objects.create(order=1, name="Batch A") batch_2 = Batch.objects.create(order=2, name="Batch B") question.batches.add(batch) question_2.batches.add(batch_2) question_3.batches.add(batch_2) BatchQuestionOrder.objects.create(question=question, batch=batch, order=1) BatchQuestionOrder.objects.create(question=question_2, batch=batch_2, order=2) BatchQuestionOrder.objects.create(question=question_3, batch=batch_2, order=1) self.assertEqual(2, BatchQuestionOrder.next_question_order_for(batch)) self.assertEqual(3, BatchQuestionOrder.next_question_order_for(batch_2))
def test_knows_order_is_plus_one_order_of_last_question_assigned_to_batch(self): question = Question.objects.create(text="This is a question", answer_type=Question.NUMBER) batch = Batch.objects.create(order=1, name="Batch A") question.batches.add(batch) BatchQuestionOrder.objects.create(question=question, batch=batch, order=1) self.assertEqual(2, BatchQuestionOrder.next_question_order_for(batch))
def forwards(self, orm): for batch in orm["survey.batch"].objects.all(): for question in batch.questions.all(): BatchQuestionOrder.objects.create( question_id=question.id, batch_id=batch.id, order=BatchQuestionOrder.next_question_order_for(batch))
def test_knows_order_is_plus_one_order_of_last_question_assigned_to_batch( self): question = Question.objects.create(text="This is a question", answer_type=Question.NUMBER) batch = Batch.objects.create(order=1, name="Batch A") question.batches.add(batch) BatchQuestionOrder.objects.create(question=question, batch=batch, order=1) self.assertEqual(2, BatchQuestionOrder.next_question_order_for(batch))
def test_knows_the_order_for_question_is_one_for_first_question_assigned_in_batch( self): batch = Batch.objects.create(order=1, name="Batch A") self.assertEqual(1, BatchQuestionOrder.next_question_order_for(batch))
def test_knows_the_order_for_question_is_one_for_first_question_assigned_in_batch(self): batch = Batch.objects.create(order=1, name="Batch A") self.assertEqual(1, BatchQuestionOrder.next_question_order_for(batch))
def forwards(self, orm): for batch in orm["survey.batch"].objects.all(): for question in batch.questions.all(): BatchQuestionOrder.objects.create(question_id=question.id, batch_id=batch.id, order=BatchQuestionOrder.next_question_order_for(batch))
def save_question_to_batch(self, batch): for question in self.cleaned_data['questions']: question.save() order = BatchQuestionOrder.next_question_order_for(batch) BatchQuestionOrder.objects.create(question=question, batch=batch, order=order) question.batches.add(batch)