forked from deepakbhimavarapu/WP_Mentor_training_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api_book.py
39 lines (32 loc) · 1.23 KB
/
test_api_book.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import json
import unittest
from book_details import *
from application import app
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy import create_engine, or_
from models import Base, User, Book
class BasicTests(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
app.config['DEBUG'] = False
# Check for environment variable
if not os.getenv("DATABASE_URL"):
raise RuntimeError("DATABASE_URL is not set")
Base.query = db_session.query_property()
self.app = app.test_client()
# Disable sending emails during unit testing
self.assertEqual(app.debug, False)
# executed after each test
def tearDown(self):
pass
def test_api_details_get(self):
response = self.app.get('/api/book/?isbn=0399153942')
self.assertEqual(response.status_code, 200)
def test_api_details_post(self):
response = self.app.post('/api/search/', data=json.dumps(dict(type="ISBN", query="0399153942")), content_type='application/json')
print(response)
self.assertEqual(response.status_code, 200)
if __name__ == "__main__":
unittest.main()