Exemplo n.º 1
0
 def test_learner_flow_with_collection_not_in_passed_group(self):
     """Check if learner_flow function is called with incorrect collection_id raise proper exception."""
     request = self.rf.post(self.not_correct_url)
     with pytest.raises(Http404):
         learner_flow(
             request,
             lti_consumer=None,
             tool_provider=None,
             collection_id=self.not_correct_kw['collection_id'],
             group_slug=self.not_correct_kw['group_slug'],
         )
Exemplo n.º 2
0
 def test_learner_flow_with_incorrect_collection_id(self):
     """Check if learner_flow function is called with incorrect collection_id raise proper exception."""
     request = self.rf.post(self.url)
     with pytest.raises(Http404):
         learner_flow(
             request,
             lti_consumer=None,
             tool_provider=None,
             collection_id=1000,
             group_slug=self.test_cg.slug,
         )
Exemplo n.º 3
0
 def test_learner_flow_with_incorrect_collection_order_slug(self):
     """
     Check if learner_flow function is called with incorrect collection_slug raise proper exception.
     """
     request = self.rf.post(self.url)
     with pytest.raises(Http404):
         learner_flow(
             request,
             lti_lms_platform=None,
             tool_provider=None,
             collection_order_slug=self.not_correct_kw["collection_order_slug"]
         )
Exemplo n.º 4
0
    def test_learner_flow_different_user_creation(self):
        """
        Test different user creation.
        """
        mock_request = RequestFactory().post(
            '',
            data={
                'oauth_nonce': 'oauth_nonce',
                'oauth_consumer_key': self.lti_lms_platform.consumer_key,
                'roles': 'Learner',
                'user_id': 'user_id',
                'context_id': 'some+course+id'
            }
        )
        middleware = SessionMiddleware()
        middleware.process_request(mock_request)
        mock_request.session.save()

        tool_provider = DjangoToolProvider.from_django_request(request=mock_request)

        count_of_the_sequence = Sequence.objects.all().count()
        count_of_lti_users = LtiUser.objects.all().count()

        # learner_flow is called 2 times (here and below) to ensure that implement logic works correctly

        learner_flow(
            mock_request,
            self.lti_lms_platform,
            tool_provider,
            self.collection_order1.slug,
        )
        learner_flow(
            mock_request,
            self.lti_lms_platform,
            tool_provider,
            self.collection_order1.slug,
        )
        self.assertEqual(Sequence.objects.all().count(), count_of_the_sequence + 1)

        count_of_the_sequence += 1

        learner_flow(
            mock_request,
            self.lti_lms_platform,
            tool_provider,
            self.collection_order1.slug,
            'marker',
        )
        learner_flow(
            mock_request,
            self.lti_lms_platform,
            tool_provider,
            self.collection_order1.slug,
            'marker',
        )
        self.assertEqual(Sequence.objects.all().count(), count_of_the_sequence + 1)

        count_of_the_sequence += 1
        learner_flow(
            mock_request,
            self.lti_lms_platform,
            tool_provider,
            self.collection_order1.slug,
            'marker1',
        )
        learner_flow(
            mock_request,
            self.lti_lms_platform,
            tool_provider,
            self.collection_order1.slug,
            'marker2',
        )
        self.assertEqual(Sequence.objects.all().count(), count_of_the_sequence + 2)

        # Ensure that only one LTI user was created.
        self.assertEqual(LtiUser.objects.all().count(), count_of_lti_users + 1)