Skip to content

Instantly share code, notes, and snippets.

@Paulvitalis200
Last active December 19, 2018 11:36
Show Gist options
  • Save Paulvitalis200/53b5748afe905b8d5977bebd64aba9ea to your computer and use it in GitHub Desktop.
Save Paulvitalis200/53b5748afe905b8d5977bebd64aba9ea to your computer and use it in GitHub Desktop.
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")
@sharkdevs
Copy link

Besides, ensure all the tests have a doctoring comment.. login did not have it

@Teatoller
Copy link

Hi Paul,

Beautiful code, you may enrich it by incorporating docstrings on the methods.

Regards
Steven Ennis

@Paulvitalis200
Copy link
Author

Thank you SharkDevs and Teatoller. I will implement that

@johnwayodi
Copy link

You haven't imported the os module, kindly correct that.

@Paulvitalis200
Copy link
Author

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