-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run more tests, formatted a bit differently please review #51
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dca1042
Added pytest for test runner, changed documentation
dgmouris cc2cbb8
Added index template test, is_os_linux test
dgmouris 2772056
Simplified session test to see if it has keys
dgmouris 1d942d9
Add reStructuredText to existing tests
dgmouris 015a7f4
Add coverage to the project, some gitignore as well
dgmouris 1aed201
Add Tests for file checking, evaluate_pylint, and slow down, minor ch…
dgmouris 186fbe4
Merge branch 'master' into run_more_tests
ethanchewy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ venv | |
.DS_STORE | ||
*.pyc | ||
.vscode | ||
assets/ | ||
htmlcov/ | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ six==1.11.0 | |
typed-ast==1.1.0 | ||
Werkzeug==0.15.3 | ||
wrapt==1.10.11 | ||
pytest==5.2.1 | ||
pytest-cov==2.8.1 | ||
pytest-html==2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
from datetime import datetime | ||
import flask | ||
import unittest | ||
from unittest.mock import patch | ||
from PythonBuddy.app import * | ||
from os import path | ||
|
||
|
||
class TestIndexPage(unittest.TestCase): | ||
def test_index(self): | ||
"""Test the index page that it is displayed | ||
:param self: instance of the current test. | ||
""" | ||
test_client = app.test_client() | ||
index_page = test_client.get('/') | ||
self.assertEqual(index_page.status, '200 OK') | ||
self.assertTrue(b'Python Linter Online' in index_page.data) | ||
|
||
def test_index_session(self): | ||
"""Test the flask session on the index page. | ||
:param self: instance of the current test. | ||
""" | ||
with app.test_client() as test_client: | ||
index_page = test_client.get('/') | ||
|
||
self.assertTrue('count' in flask.session) | ||
self.assertTrue('time_now' in flask.session) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comments above this test |
||
class TestUtilities(unittest.TestCase): | ||
@patch('PythonBuddy.app.os') | ||
def test_is_os_linux(self, os_name_patch): | ||
"""Test the linux check in the PythonBuddy app | ||
:param self: instance of the current test. | ||
:param os_name_patch: patch of the os in the pybuddy app | ||
""" | ||
os_name_patch.name = "nt" | ||
self.assertFalse(is_os_linux()) | ||
|
||
os_name_patch.name = "ubuntu :)" | ||
self.assertTrue(is_os_linux()) | ||
|
||
|
||
class TestCodeRunning(unittest.TestCase): | ||
def setUp(self): | ||
self.code_example = "for i in range(5):\n print(i)\n" | ||
self.code_example_modified = "print(\"Oh hai Mark\")" | ||
self.error_message = [ | ||
{ | ||
"code": self.code_example, | ||
"error": "", | ||
"message": "", | ||
"line": "", | ||
"error_info": "", | ||
} | ||
] | ||
|
||
@patch('PythonBuddy.app.evaluate_pylint') | ||
def test_check_code_endpoint_no_evaluate_pylint(self, evaluate_pytlint_patch): | ||
"""Test the check code endpoint | ||
:param self: instance of the current test. | ||
:param evaluate_pytlint_patch: patch of the os in the evaluate_pytlint | ||
testing this separately. | ||
""" | ||
evaluate_pytlint_patch.return_value = self.error_message | ||
with app.test_client() as test_client: | ||
check_code_page = test_client.post('/check_code', data={ | ||
"text": self.code_example | ||
}) | ||
self.assertEqual(check_code_page.status, '200 OK') | ||
self.assertTrue('code' in flask.session) | ||
self.assertEqual(flask.session['code'], self.code_example) | ||
|
||
@patch('PythonBuddy.app.slow') | ||
def test_run_code_slow(self, slow_patch): | ||
"""Test that when code is running too much | ||
:param self: instance of current test | ||
:param slow_patch: path the slow method, test separately | ||
""" | ||
slow_patch.return_value = True | ||
test_client = app.test_client() | ||
check_run_code = test_client.post('/run_code', data={}) | ||
self.assertEqual(check_run_code.status, '200 OK') | ||
self.assertTrue(b"Running code too much" in check_run_code.data) | ||
|
||
def test_evaluate_pylint_test_file_creation_deletion_and_contents(self): | ||
"""Test the evaluate pylint method in depth. | ||
:param self: instance of the current test. | ||
first check if the file will get created (keyerror thrown) | ||
second check if code in file will get modified | ||
""" | ||
with app.test_client() as test_client: | ||
test_client.get('/') # this will set the count | ||
test_client.post('/check_code', data={ | ||
"text": self.code_example | ||
}) | ||
|
||
# first test | ||
# this will check that the exception is raised and | ||
# a new file is created | ||
test_client.post('/run_code') | ||
self.assertTrue('file_name' in flask.session) | ||
|
||
# this will check that the exception is raised and | ||
# a new file is created | ||
test_client.post('/check_code', data={ | ||
"text": self.code_example_modified | ||
}) | ||
# check the code is modified | ||
temp_code_file = open(flask.session['file_name'], "r") | ||
self.assertEqual(temp_code_file.read(), self.code_example_modified) | ||
|
||
def test_if_file_created_and_deleted(self): | ||
"""Test if the file will get created and deleted. | ||
:param self: instance of the current test. | ||
""" | ||
with app.test_client() as test_client: | ||
|
||
test_client.post('/check_code', data={ | ||
"text": self.code_example | ||
}) | ||
# check if the file still exists | ||
self.assertTrue(path.exists(flask.session['file_name'])) | ||
remove_temp_code_file() | ||
|
||
# ensure file is deleted | ||
self.assertFalse(path.exists(flask.session['file_name'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comments above this test