Skip to content
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

Adds flask unittests #53

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ python:
install: "pip install -r requirements.txt"
# command to run tests
script:
- python -m tests.test_linter
- python -m unittest tests/test_linter.py tests/test_flask.py
63 changes: 63 additions & 0 deletions tests/test_flask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
import unittest
import tempfile
from PythonBuddy.app import app

class FlaskrTestCase(unittest.TestCase):

def setUp(self):
self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
app.testing = True
self.app = app.test_client()
with app.app_context():
pass

def tearDown(self):
os.close(self.db_fd)
os.unlink(app.config['DATABASE'])


def test_index(self):
""" Tests a request to index returns a 200 status code.
"""
result = self.app.get('/')
self.assertEqual(result.status_code, 200)


def test_check_code(self):
"""
Tests the /check_code endpoint can handle an empty payload.
"""
response = self.app.post("/check_code")
self.assertEqual(result.status_code, 200)


def test_check_code(self):
""" Tests the response json object
from /check_code returns the documented JSON object.
"""
response = self.app.post("/check_code", data={"text": "TEST_INPUT"})
self.assertIsInstance(response.json, dict)

def test_run_code_index_setup_no_check_code(self):
""" Tests making a request
directly to /run_code after hitting
/ but not /check_code does not raise Index errors
due to session keys not being set.
"""
response = self.app.get("/")
response = self.app.post("/run_code")
self.assertIsInstance(response.json,dict)

def test_run_code_no_index_setup(self):
""" Tests making a request
directly to /run_code before hitting
/index does not raise Index errors
due to session keys not being set.
"""
response = self.app.post("/run_code")
self.assertIsInstance(response.json,dict)


if __name__ == '__main__':
unittest.main()