コード例 #1
0
    def test_betatest_accepted(self):
        """
        Provision an instance, spawn an AppServer and accepts the application.
        """
        OpenEdXInstanceFactory(
            name='Integration - test_betatest_accepted',
            deploy_simpletheme=True,
        )
        instance = OpenEdXInstance.objects.get()

        # Add an lms user, as happens with beta registration
        user, _ = get_user_model().objects.get_or_create(
            username='******', email='*****@*****.**')
        instance.lms_users.add(user)

        # Simulate that the application form was filled. This doesn't create another instance nor user
        BetaTestApplication.objects.create(
            user=user,
            subdomain='betatestdomain',
            instance_name=instance.name,
            public_contact_email='*****@*****.**',
            project_description='I want to beta test OpenCraft IM',
            status=BetaTestApplication.PENDING,
            instance=instance,
        )

        appserver = MagicMock()
        appserver.status = AppServer.Status.Running
        instance.refresh_from_db()

        # Test accepting beta test application
        on_appserver_spawned(None, instance=instance, appserver=appserver)
        self.assertEqual(instance.betatestapplication_set.first().status,
                         BetaTestApplication.ACCEPTED)
コード例 #2
0
    def test_no_application(self):
        """ Basic test for appserver_spawned() without an application """

        appserver = mock.Mock()
        instance = mock.Mock()
        instance.betatestapplication_set.first = lambda: None

        # Test nothing happens without an application
        with mock.patch('registration.approval.accept_application'
                        ) as mock_application:
            on_appserver_spawned(sender=None,
                                 instance=instance,
                                 appserver=appserver)
            mock_application.assert_not_called()
コード例 #3
0
    def test_accepted_application(self):
        """ Basic test for appserver_spawned() with ACCEPTED application """

        appserver = mock.Mock()
        instance = mock.Mock()
        application = mock.Mock(status=BetaTestApplication.ACCEPTED)
        instance.betatestapplication_set.first = lambda: application

        # Test accepted application does nothing
        with mock.patch('registration.approval.accept_application'
                        ) as mock_application:
            on_appserver_spawned(sender=None,
                                 instance=instance,
                                 appserver=appserver)
            mock_application.assert_not_called()
コード例 #4
0
    def test_appserver_spawned(self):
        """ Basic test for appserver_spawned() failure and success behaviour """

        instance = mock.Mock()
        application = mock.Mock(status=BetaTestApplication.PENDING)
        instance.betatestapplication_set.first = lambda: application

        # Test failed spawning generates an exception in case of pending application
        with mock.patch('registration.approval.accept_application'
                        ) as mock_application:
            with self.assertRaises(ApplicationNotReady):
                on_appserver_spawned(sender=None,
                                     instance=instance,
                                     appserver=None)
            mock_application.assert_not_called()
コード例 #5
0
    def test_pending_application(self):
        """ Basic test for appserver_spawned() success """

        appserver = mock.Mock()
        instance = mock.Mock()
        application = mock.Mock(status=BetaTestApplication.PENDING)
        instance.betatestapplication_set.first = lambda: application

        # Test accepted application does nothing
        with mock.patch('registration.approval.accept_application'
                        ) as mock_application:
            on_appserver_spawned(sender=None,
                                 instance=instance,
                                 appserver=appserver)
            self.assertEqual(mock_application.call_count, 1)
コード例 #6
0
    def test_first_appserver_is_active(self):
        """
        Check if the the first Appserver is correctly activated even when
        spawned manually
        """
        appserver = mock.Mock(status=AppServer.Status.Running)
        instance = mock.Mock(first_activated=None)
        application = mock.Mock(status=BetaTestApplication.PENDING)

        application.instance = instance
        instance.betatestapplication_set.first = lambda: application

        # Test accepted application does nothing
        on_appserver_spawned(sender=None,
                             instance=instance,
                             appserver=appserver)
        self.assertEqual(appserver.make_active.call_count, 1)