Пример #1
0
    def test_sessions_token(self):
        token1 = UserToken.get_sessions_token(self.user1)
        token2 = UserToken.get_sessions_token(self.user1)

        self.assertEqual(token1, token2)
        self.assertEqual(token1.user, self.user1)
        self.assertEqual(token1.name, "Sessions token")
        self.assertEqual(token1.notes, 'Token used by Stencila when launching sessions on your behalf')
Пример #2
0
    def start(self):
        '''
        Start the session. This is a separate method from `launch`
        because it is useful for testing when you want to create a
        session in the admin and start it from there
        '''
        if self.started is None:
            # Just-in-time initalization of attributes required for running
            # a session (to save having to enter these in the admin)
            #
            # Get the sessions token for the user, creating
            # one if necessary
            self.token = UserToken.get_sessions_token(self.user).string
            # Apply session type limits to this session
            # is they have not bee cutomised
            if self.memory is None:
                self.memory = self.type.memory
            if self.cpu is None:
                self.cpu = self.type.cpu
            if self.network is None:
                self.network = self.type.network

            # If worker not yet assigned (eg. in admin)
            if not self.worker:
                # Find the best worker to start the session on
                self.worker = Worker.choose(self)

            # Start on the worker
            self.status = 'Starting'
            # Session could be started asynchronously but for now
            # it is started here
            result = self.worker.start(self)
            self.uuid = result.get('uuid')
            if result.get('warning'):
                logger.warning('Session start warning', exc_info=True, extra=dict(
                    session=self.id,
                    warning=result.get('warning')
                ))
            if result.get('error'):
                logger.error('Session start error', exc_info=True, extra=dict(
                    session=self.id,
                    error=result.get('error')
                ))

            # Update
            self.active = True
            self.started = timezone.now()
            self.save()
Пример #3
0
    def test_start(self):
        '''
        Has the session started properly?
        '''
        self.assertEqual(self.session.component, self.stencil)
        self.assertEqual(self.session.user, self.user1)

        token = UserToken.get_sessions_token(self.user1)
        self.assertEqual(self.session.token, token.string)

        self.assertEqual(self.session.memory, '1g')
        self.assertEqual(self.session.cpu, 1024)

        self.assertEqual(self.session.worker, self.worker)
        self.assertTrue(self.session.uuid is not None)
        self.assertEqual(self.session.status, 'Starting')
        self.assertTrue(self.session.started > timezone.now()-datetime.timedelta(seconds=1))