Last active
December 19, 2018 11:36
-
-
Save Paulvitalis200/53b5748afe905b8d5977bebd64aba9ea to your computer and use it in GitHub Desktop.
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
import os | |
from django.test import TestCase | |
from app import create_app | |
GET_ALL_ARTICLES = '/api/v1/articles' | |
config = os.getenv('APP_SETTINGS') | |
class ArticleTestCase(TestCase): | |
def setUp(self): | |
"""Define setup configurations""" | |
self.app = create_app(config) | |
self.client = self.app.test_client() | |
def test_get_null_articles(self): | |
"""TEST whether the API can get null articles(GET)""" | |
res = self.client.get(GET_ALL_ARTICLES, | |
headers=dict(Authorization="Bearer " + self.login()), | |
content_type='application/json') | |
resp_data = json.loads(res.data.decode()) | |
self.assertEqual(res.status_code, 404) | |
self.assertEqual(resp_data['message'], "No articles yet") | |
def test_get_all_articles(self): | |
"""TEST whether the API can get all articles(POST)""" | |
res = self.client.get(GET_ALL_ARTICLES, | |
headers=dict(Authorization="Bearer " + self.login()), | |
content_type='application/json') | |
resp_data = json.loads(res.data.decode()) | |
self.assertEqual(res.status_code, 200) | |
self.assertEqual(resp_data['message'], "Articles retrieved") | |
Besides, ensure all the tests have a doctoring comment.. login
did not have it
Hi Paul,
Beautiful code, you may enrich it by incorporating docstrings on the methods.
Regards
Steven Ennis
Thank you SharkDevs and Teatoller. I will implement that
You haven't imported the os module, kindly correct that.
Thank you John Wayodi. I have imported it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ensure there is a separation between the local imports and library imports by a blank line