Skip to content

Instantly share code, notes, and snippets.

@MaggieChege
Created December 20, 2018 09:36
Show Gist options
  • Save MaggieChege/18c445d468762562fe19b50cf748388c to your computer and use it in GitHub Desktop.
Save MaggieChege/18c445d468762562fe19b50cf748388c to your computer and use it in GitHub Desktop.
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