Exemplo n.º 1
0
 def test_github_loads(self):
     """
     Checks that the GitHub page loads by checking if the title is
     in the response data
     """
     tester = app.test_client()
     response = tester.get('/github')
     self.assertTrue(b'GitHub Repos' in response.data)
Exemplo n.º 2
0
 def test_folder_is_created(self):
     """
     Checks that the session creation creates a folder
     """
     with app.test_client() as test_client:
         test_client.get('/')
         self.assertTrue(
             os.path.exists('uploads/' + flask.session['public_user']))
Exemplo n.º 3
0
 def test_generate_new_session(self):
     """
     Asserts a session with the key 'public_user' is created
     Test adapted from https://flask.palletsprojects.com/en/1.1.x/testing/]
     """
     with app.test_client() as test_client:
         test_client.get('/')
         self.assertIsNot(flask.session['public_user'], None)
Exemplo n.º 4
0
 def test_false_route(self):
     """
     Checks for response 404 on route that does not exist
     """
     tester = app.test_client()
     response = tester.get('/test')
     status_code = response.status_code
     self.assertEqual(status_code, 404)
Exemplo n.º 5
0
 def test_github_route(self):
     """
     Check for response 200 on the GitHub page
     """
     tester = app.test_client()
     response = tester.get('/github')
     status_code = response.status_code
     self.assertEqual(status_code, 200)
Exemplo n.º 6
0
 def test_about_loads(self):
     """
     Checks that the about page loads by checking if the title
     is in the response data
     """
     tester = app.test_client()
     response = tester.get('/about')
     self.assertTrue(b'Under the Hood' in response.data)
Exemplo n.º 7
0
 def test_about_route(self):
     """
     Check for response 200 on the about page
     """
     tester = app.test_client()
     response = tester.get('/about')
     status_code = response.status_code
     self.assertEqual(status_code, 200)
Exemplo n.º 8
0
 def test_index_loads(self):
     """
     Checks that the page loads properly by checking for the title
     in response data
     """
     tester = app.test_client()
     response = tester.get('/')
     self.assertTrue(b'Citation Extractor' in response.data)
Exemplo n.º 9
0
 def test_index_route_post(self):
     """
     Check for response 200 on the index page
     """
     tester = app.test_client()
     response = tester.post('/')
     status_code = response.status_code
     self.assertEqual(status_code, 200)
Exemplo n.º 10
0
 def test_clean_up_of_session_folder(self):
     """
     Asserts that the session clean up functionality works as expected
     with regard to folder deletion
     """
     active_sessions = {}
     with app.test_client() as test_client:
         test_client.get('/')
         active_sessions[flask.session['public_user']] = datetime.now()
         session_management.clean_up_sessions(flask.session['public_user'],
                                              'uploads/', active_sessions)
         self.assertFalse(
             os.path.exists('uploads/' + flask.session['public_user']))
Exemplo n.º 11
0
 def test_removal_from_active_session(self):
     """
     Asserts that the session clean up functionality works as expected
     with regard to removing k,v pairs from the active_session dict
     """
     active_sessions = {}
     with app.test_client() as test_client:
         test_client.get('/')
         active_sessions[flask.session['public_user']] = datetime.now()
         session_management.clean_up_sessions(flask.session['public_user'],
                                              'uploads/', active_sessions)
         self.assertTrue(
             flask.session['public_user'] not in active_sessions)
Exemplo n.º 12
0
 def test_check_existing_file_name_true(self):
     """
     Asserts True - showing that the file name would be renamed as the
     original file already existed within the directory
     """
     with app.test_client() as test_client:
         test_client.get('/')
         shutil.copyfile(
             '../test_documents/sample_citations_second.docx', 'uploads/' +
             flask.session['public_user'] + '/sample_citations_second.docx')
         test_file_name = "sample_citations_second.docx"
         new_file_name = file_uploader.check_existing_file_name(
             test_file_name, FlaskTest.upload_folder)
         self.assertTrue(new_file_name is not test_file_name)
Exemplo n.º 13
0
 def test_update_existing_session(self):
     """
     Asserts that the value in active sessions gets updated
     Example dict is created with test data.txt, function is called to
     update the value
     Assert checks that the updated timestamp != the initial
     """
     with app.test_client() as test_client:
         test_client.get('/')
         time_stamp = datetime.now()
         active_sessions = {flask.session['public_user']: time_stamp}
         session_management.update_existing_session(active_sessions)
         self.assertTrue(
             active_sessions.get(flask.session['public_user'])
             is not time_stamp)