示例#1
0
    def test_initialize_lobby(self):
        url = '/lobby/now'
        self.assertIsNone(active_lobby.get())
        c = Client()
        res = c.get(url)
        self.assertEqual(res.status_code, 200)  # No Lobby page
        self.assertRegex(res.content.decode('utf-8'), r'現在開催されているセッションはありません')

        res = decode_json(c.post(url, {'id': 'default'}))
        self.assertEqual(res['status'], 'ok')

        active_lobby_id = active_lobby.get().pk
        res = c.get(url)
        self.assertEqual(res.status_code, 302)  # Moved
        self.assertRegex(res.url, '/lobby/%d' % active_lobby_id)
示例#2
0
    def test_initialize_lobby(self):
        url = '/lobby/now'
        self.assertIsNone(active_lobby.get())
        c = Client()
        res = c.get(url)
        self.assertEqual(res.status_code, 200)  # No Lobby page
        self.assertRegex(res.content.decode('utf-8'), r'現在開催されているセッションはありません')

        res = decode_json(c.post(url, {'id': 'default'}))
        self.assertEqual(res['status'], 'ok')

        active_lobby_id = active_lobby.get().pk
        res = c.get(url)
        self.assertEqual(res.status_code, 302)  # Moved
        self.assertRegex(res.url, '/lobby/%d' % active_lobby_id)
示例#3
0
    def test_lobby_sequential(self):
        lobby = active_lobby.get()
        self.assertEqual(lobby.started_time, None)
        self.assertEqual(lobby.finished_time, None)
        self.assertEqual(None, lobby.current_state)
        self.assertIsNone(lobby.active_quiz)

        before_start = timezone.now()
        lobby.initialize()
        after_start = timezone.now()
        self.assertTrue(before_start < lobby.started_time < after_start)
        self.assertIsNone(lobby.active_quiz)
        self.assertEqual(lobby.current_state, 'INACTIVE')

        lobby.go_next_quiz()
        self.assertEqual("First quiz", lobby.active_quiz.body.caption)
        self.assertEqual(lobby.current_state, 'QUIZ_OPENED')
        lobby.close_participant_submission()
        self.assertEqual(lobby.current_state, 'MASTER_ANSWERING')
        lobby.close_master_submission()
        self.assertEqual(lobby.current_state, 'SHOWING_ANSWER')
        lobby.show_scores()
        self.assertEqual(lobby.current_state, 'SHOWING_SCORE')

        # 次の問題へ
        lobby.go_next_quiz()
        self.assertEqual(lobby.current_state, 'QUIZ_OPENED')
        self.assertEqual("Second quiz", lobby.active_quiz.body.caption)
示例#4
0
    def test_lobby_sequential(self):
        lobby = active_lobby.get()
        self.assertEqual(lobby.started_time, None)
        self.assertEqual(lobby.finished_time, None)
        self.assertEqual(None, lobby.current_state)
        self.assertIsNone(lobby.active_quiz)

        before_start = timezone.now()
        lobby.initialize()
        after_start = timezone.now()
        self.assertTrue(before_start < lobby.started_time < after_start)
        self.assertIsNone(lobby.active_quiz)
        self.assertEqual(lobby.current_state, 'INACTIVE')

        lobby.go_next_quiz()
        self.assertEqual("First quiz", lobby.active_quiz.body.caption)
        self.assertEqual(lobby.current_state, 'QUIZ_OPENED')
        lobby.close_participant_submission()
        self.assertEqual(lobby.current_state, 'MASTER_ANSWERING')
        lobby.close_master_submission()
        self.assertEqual(lobby.current_state, 'SHOWING_ANSWER')
        lobby.show_scores()
        self.assertEqual(lobby.current_state, 'SHOWING_SCORE')

        # 次の問題へ
        lobby.go_next_quiz()
        self.assertEqual(lobby.current_state, 'QUIZ_OPENED')
        self.assertEqual("Second quiz", lobby.active_quiz.body.caption)
示例#5
0
    def setUp(self):
        c = Client()
        res = decode_json(c.post('/lobby/now', {'id': 'default'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        control_url = '/lobby/control/%d' % lobby.pk
        c = Client()

        # Check initial state
        self.assertEqual(None, lobby.current_state)
        self.assertEqual(lobby.active_quiz, None)
        res = decode_json(c.post(control_url, {'command': 'activate'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('INACTIVE', lobby.current_state)
        self.assertIsNone(lobby.active_quiz)

        res = decode_json(c.post(control_url, {'command': 'next'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertIsNotNone(lobby.active_quiz)
        self.assertEqual(lobby.active_quiz.body.caption, 'First quiz')
        self.assertEqual('QUIZ_OPENED', lobby.current_state)
        self.url = '/lobby/%d' % lobby.pk
示例#6
0
    def setUp(self):
        c = Client()
        res = decode_json(c.post('/lobby/now', {'id': 'default'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        control_url = '/lobby/control/%d' % lobby.pk
        c = Client()

        # Check initial state
        self.assertEqual(None, lobby.current_state)
        self.assertEqual(lobby.active_quiz, None)
        res = decode_json(c.post(control_url, {'command': 'activate'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('INACTIVE', lobby.current_state)
        self.assertIsNone(lobby.active_quiz)

        res = decode_json(c.post(control_url, {'command': 'next'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertIsNotNone(lobby.active_quiz)
        self.assertEqual(lobby.active_quiz.body.caption, 'First quiz')
        self.assertEqual('QUIZ_OPENED', lobby.current_state)
        self.url = '/lobby/%d' % lobby.pk
示例#7
0
    def test_control_lobby(self):
        lobby = active_lobby.get()
        lobby_pk = lobby.pk
        url = '/lobby/control/%d' % lobby.pk
        c = Client()

        # Check initial state
        self.assertEqual(None, lobby.current_state)
        self.assertEqual(lobby.active_quiz, None)

        res = decode_json(c.post(url, {'command': 'activate'}))
        self.assertEqual(res['status'], 'ok')

        res = decode_json(c.post(url, {'command': 'next'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual(lobby.pk, lobby_pk)
        self.assertIsNotNone(lobby.active_quiz)
        self.assertEqual(lobby.active_quiz.body.caption, 'First quiz')
        self.assertEqual('QUIZ_OPENED', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'close_submission'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('MASTER_ANSWERING', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'close_master_submission'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('SHOWING_ANSWER', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'show_scores'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('SHOWING_SCORE', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'next'}))
        self.assertEqual(res['status'], 'ok')

        lobby = active_lobby.get()
        self.assertEqual('QUIZ_OPENED', lobby.current_state)
        self.assertEqual(lobby.pk, lobby_pk)
        self.assertEqual(lobby.active_quiz.body.caption, 'Second quiz')
示例#8
0
    def test_control_lobby(self):
        lobby = active_lobby.get()
        lobby_pk = lobby.pk
        url = '/lobby/control/%d' % lobby.pk
        c = Client()

        # Check initial state
        self.assertEqual(None, lobby.current_state)
        self.assertEqual(lobby.active_quiz, None)

        res = decode_json(c.post(url, {'command': 'activate'}))
        self.assertEqual(res['status'], 'ok')

        res = decode_json(c.post(url, {'command': 'next'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual(lobby.pk, lobby_pk)
        self.assertIsNotNone(lobby.active_quiz)
        self.assertEqual(lobby.active_quiz.body.caption, 'First quiz')
        self.assertEqual('QUIZ_OPENED', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'close_submission'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('MASTER_ANSWERING', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'close_master_submission'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('SHOWING_ANSWER', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'show_scores'}))
        self.assertEqual(res['status'], 'ok')
        lobby = active_lobby.get()
        self.assertEqual('SHOWING_SCORE', lobby.current_state)

        res = decode_json(c.post(url, {'command': 'next'}))
        self.assertEqual(res['status'], 'ok')

        lobby = active_lobby.get()
        self.assertEqual('QUIZ_OPENED', lobby.current_state)
        self.assertEqual(lobby.pk, lobby_pk)
        self.assertEqual(lobby.active_quiz.body.caption, 'Second quiz')