Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
increase test coverage
- Loading branch information
Showing
10 changed files
with
196 additions
and
150 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# tests/test_basic.py | ||
|
||
import unittest | ||
|
||
from base import BaseTestCase | ||
|
||
|
||
class FlaskTestCase(BaseTestCase): | ||
|
||
# Ensure that Flask was set up correctly | ||
def test_index(self): | ||
response = self.client.get('/login', content_type='html/text') | ||
self.assertEqual(response.status_code, 200) | ||
|
||
# Ensure that main page requires user login | ||
def test_main_route_requires_login(self): | ||
response = self.client.get('/', follow_redirects=True) | ||
self.assertIn(b'Please log in to access this page', response.data) | ||
|
||
# Ensure that welcome page loads | ||
def test_welcome_route_works_as_expected(self): | ||
response = self.client.get('/welcome', follow_redirects=True) | ||
self.assertIn(b'Welcome to Flask!', response.data) | ||
|
||
# Ensure that posts show up on the main page | ||
def test_posts_show_up_on_main_page(self): | ||
response = self.client.post( | ||
'/login', | ||
data=dict(username="admin", password="admin"), | ||
follow_redirects=True | ||
) | ||
self.assertIn(b'This is a test. Only a test.', response.data) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,29 @@ | ||
# tests/test_blog.py | ||
|
||
import unittest | ||
|
||
from base import BaseTestCase | ||
|
||
|
||
class BlogPostTests(BaseTestCase): | ||
|
||
# Ensure a logged in user can add a new post | ||
def test_user_can_post(self): | ||
with self.client: | ||
self.client.post( | ||
'/login', | ||
data=dict(username="admin", password="admin"), | ||
follow_redirects=True | ||
) | ||
response = self.client.post( | ||
'/', | ||
data=dict(title="test", description="test"), | ||
follow_redirects=True | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(b'New entry was successfully posted. Thanks.', | ||
response.data) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.