Skip to content

Instantly share code, notes, and snippets.

@oampo
Created December 16, 2013 15:08
Show Gist options
  • Save oampo/7988528 to your computer and use it in GitHub Desktop.
Save oampo/7988528 to your computer and use it in GitHub Desktop.
Flask API Testing
import unittest
import json
import uppr
class ApiTests(unittest.TestCase):
def setUp(self):
uppr.app.config.from_object("uppr.config.TestingConfig")
self.app = uppr.app.test_client()
uppr.db.create_all()
def tearDown(self):
uppr.db.session.close()
uppr.db.drop_all()
def testAddImage(self):
self.app.get("/api/image")
def testGetImagesEmpty(self):
response = self.app.get("/api/image/")
self.assertEqual(response.headers["Content-Type"], "application/json")
self.assertEqual(response.status_code, 200)
data = json.loads(response.data)
self.assertEqual(data, [])
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment