def test_sequence_completed_in_select_next_sequence_item(self): self.sequence_item_5 = SequenceItem.objects.create( sequence=self.sequence, activity=self.activity5, position=5) sequence_item = self.sequence_item_5 expected_result = (sequence_item, True, None) result = select_next_sequence_item(sequence_item, update_activity=False, last_item=5, position=6) self.assertEqual(expected_result, result)
def test_select_next_sequence_item(self, item_index, update_activity, last_item, position, pre_expected_result): next_item = getattr(self, f"sequence_item_{pre_expected_result[0]}", None) result = select_next_sequence_item( getattr(self, f"sequence_item_{item_index}"), update_activity, last_item, position, ) if position > last_item or update_activity: next_item = self.sequence.items.last() expected_result = (next_item, *pre_expected_result[1:]) self.assertEqual(expected_result, result)
def demo_collection(request, collection_order_slug): """ View for the demonstration and testing of the adaptivity behaviour. """ __, collection_order = get_engine_and_collection_order( collection_order_slug) lti_lms_platform = LtiLmsPlatform.objects.first() test_lti_user, created = LtiUser.objects.get_or_create( user_id=DEMO_USER, lti_lms_platform=lti_lms_platform, ) test_sequence, created = Sequence.objects.get_or_create( lti_user=test_lti_user, collection_order=collection_order) strict_forward = collection_order.strict_forward request.session['Lti_sequence'] = test_sequence.id request.session['Lti_strict_forward'] = strict_forward back_url = request.GET.get('back_url', '') context = { 'sequence_pk': test_sequence.id, 'back_url': back_url, 'forbidden': request.GET.get('forbidden', ''), } if created or not test_sequence.items.exists(): suffix = int(datetime.datetime.now().timestamp()) cache.set(settings.TEST_SEQUENCE_SUFFIX, suffix) test_sequence.suffix = suffix test_sequence.save() log.debug("Sequence {} was created".format(test_sequence)) start_activity = utils.choose_activity(sequence=test_sequence) if not start_activity: log.warning('Instructor configured empty Collection.') return stub_page( request, title="Warning", message="Cannot get the first question to start.", tip="Please try again later", demo=True, sequence=test_sequence, back_url=back_url, ) sequence_item = SequenceItem.objects.create(sequence=test_sequence, activity=start_activity, position=1) next_forbidden, _, _ = _check_next_forbidden(sequence_item.id) context.update({"forbidden": next_forbidden}) else: s_item_id = request.GET.get( 'sequence_item_id') or test_sequence.items.last().id log.debug(f'SequienceItem id: {s_item_id}') next_forbidden, last_item, sequence_item = _check_next_forbidden( s_item_id) position = int(request.GET.get('position') or 1) if not (next_forbidden and position > sequence_item.position): update_activity = request.session.pop('Lti_update_activity', None) sequence_item, sequence_complete, stub = utils.select_next_sequence_item( sequence_item, update_activity, last_item, position, ) next_forbidden, _, _ = _check_next_forbidden(sequence_item.id) context.update({"forbidden": next_forbidden}) if sequence_complete: context.update({ 'sequence_items': test_sequence.items.all(), 'demo': True, 'sequence_item': sequence_item }) return render(request, template_name='module/sequence_complete.html', context=context) elif stub: return stub_page( request, title="Warning", message="Cannot get next activity from the engine.", tip="Try again later or connect with the instructor.", demo=True, sequence=test_sequence, back_url=back_url, ) context.update({ 'sequence_item': sequence_item, 'sequence_items': test_sequence.items.all(), 'demo': True, 'position': sequence_item.position + 1 }) return render(request, template_name="module/sequence_item.html", context=context)