Created
December 20, 2018 09:36
-
-
Save MaggieChege/18c445d468762562fe19b50cf748388c 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 unittest | |
import pytest | |
from app import app | |
class CommentTestCase(unittest.TestCase): | |
def setUp(self): | |
self.app=app("testing") | |
self.client=self.app.test_client() | |
self.context=self.app.app_context() | |
with self.context: | |
self.comment={ | |
"id": 1, | |
"createdAt": "2016-02-18T03:22:56.637Z", | |
"updatedAt": "2016-02-18T03:22:56.637Z", | |
"body": "It takes a Jacobian", | |
"author": { | |
"username": "jake", | |
"bio": "I work at statefarm", | |
"image": "https://i.stack.imgur.com/xHWG8.jpg", | |
"following": false | |
} | |
} | |
self.empty_comment={} | |
def test_add_comment(self): | |
respose = self.client.post('/api/comments), | |
data = json.dumps(dict(self.comment)), | |
response_data = json.loads(response.data) | |
self.assertEqual(response_data["message"], "Comment added") | |
self.assertEqual(response.status_code,200) | |
def test_empty_comment(self): | |
respose = self.client.post('/api/comments), | |
data = json.dumps(dict(self.empty_comment)), | |
response_data = json.loads(response.data) | |
self.assertEqual(response_data["message"], "Comment Cannot be empty") | |
self.assertEqual(response.status_code,400) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment