示例#1
0
 def test_question_200_response(self):
     with app.test_client() as client:
         with client.session_transaction() as sess:
             setup_user(sess)
     # Test the request in this context block.
     result = client.get("/questions/1")
     self.assertEqual(result.status_code, 200)
示例#2
0
 def test_questions_qunum_added_to_visitedcheck(self):
     with app.test_request_context():
         with app.test_client() as client:
             with client.session_transaction() as sess:
                 setup_user(sess)
             response = client.get("/questions/1")
             self.assertEqual(flask.session['visited_check'], [1])
示例#3
0
 def test_questions_new_game_200_response(self):
     with app.test_client() as client:
         with client.session_transaction() as sess:
             sess["username"] = "******"
         # Test the request in this context block.
         result = client.get("/questions/new-game")
         self.assertEqual(result.status_code, 200)
示例#4
0
 def test_questions_redirect_not_completed_quix(self):
     with app.test_request_context():
         with app.test_client() as client:
             with client.session_transaction() as sess:
                 setup_user(sess)
         result = client.get("/questions/end")
         self.assertEqual(result.status_code, 302)
         self.assertEqual(result.location, url_for('index', _external=True))
示例#5
0
 def test_question_end_200_response(self):
     with app.test_client() as client:
         with client.session_transaction() as sess:
             setup_user(sess)
             sess["username"] = "******"
             sess["current_qu_num"] = 6
     # Test the request in this context block.
     result = client.get("/questions/end")
     self.assertEqual(result.status_code, 200)
示例#6
0
    def test_questions_redirect_qunum_not_in_session(self):
        with app.test_request_context():
            with app.test_client() as client:
                with client.session_transaction() as sess:
                    setup_user(sess)
                    sess.pop("current_qu_num")
            result = client.get("/questions/1")
            self.assertEqual(result.status_code, 302)
            self.assertEqual(result.location, url_for('index', _external=True))

        with app.test_request_context():
            with app.test_client() as client:
                with client.session_transaction() as sess:
                    setup_user(sess)
                    sess.pop("score")
            result = client.get("/questions/1")
            self.assertEqual(result.status_code, 302)
            self.assertEqual(result.location, url_for('index', _external=True))
示例#7
0
    def test_question_timer(self):
        with app.test_client() as client:
            with client.session_transaction() as sess:
                # Modify the session in this context block.
                setup_user(sess)

            client.get("/questions/1")
            # Saves time page loads for testing
            testing_start_time = datetime.now()
            # Waits 1-4 seconds
            time.sleep(random.randint(1, 4))
            # Submits POST request (simulate answering question)
            client.post("/questions/1")
            # Saves time POST request is made
            test_end_time = datetime.now()
            # Equates time between start and end
            testing_total_time = (test_end_time -
                                  testing_start_time).total_seconds()
            """
                Checks simulated testing total time equals total time saved to session in app
                Check is within 1 second to account for any differences when datetime.now() is run
                """
            self.assertAlmostEqual(testing_total_time,
                                   flask.session["total_time"], None, None, 1)
示例#8
0
 def test_index_200_response(self):
     with app.test_client() as client:
         # Test the request in this context block.
         result = client.get("/")
         self.assertEqual(result.status_code, 200)
示例#9
0
 def setUp(self):
     # creates a test client
     self.app = app.test_client()
     # propagate the exceptions to the test client
     self.app.testing = True