-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
105 lines (81 loc) · 3.26 KB
/
test_app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import unittest
import json
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
from app import create_app
from models import setup_db, Movie, Actor
from flask_cors import CORS, cross_origin
class CastingAgency(unittest.TestCase):
"""This class represents the casting agency test case"""
def setUp(self):
"""Define test variables and initialize app."""
self.app = create_app()
self.client = self.app.test_client
# self.database_name = "casting_test"
# self.database_path = 'postgres://ubuntu:ubuntu@localhost:5432/' + self.database_name
self.database_path = "postgresql://postgres:Thinker1997@localhost:5432/meow001"
setup_db(self.app, self.database_path)
self.new_movie = {
'movie_title': 'Godzilla',
'release_date': str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
}
self.new_actor = {
'name': 'Test Name',
'age': 34,
'gender': 'M'
}
# binds the app to the current context
with self.app.app_context():
self.db = SQLAlchemy()
self.db.init_app(self.app)
self.db.create_all()
def tearDown(self):
"""Executed after reach test"""
pass
def test_post_movie(self):
res = self.client().post('/movie', json=self.new_movie)
data = json.loads(res.data)
self.assertEqual(data['success'], False)
self.assertEqual(res.status_code, 404)
def test_post_actor(self):
res = self.client().post('/actor', json=self.new_actor)
data = json.loads(res.data)
self.assertEqual(data['success'], False)
self.assertEqual(res.status_code, 404)
def test_get_movies(self):
res = self.client().get('/movies')
data = json.loads(res.data)
self.assertEqual(data['success'], False)
self.assertEqual(res.status_code, 404)
def test_get_actors(self):
res = self.client().get('/actors')
data = json.loads(res.data)
self.assertEqual(data['success'], False)
self.assertEqual(res.status_code, 404)
def test_delete_movie(self):
res = self.client().delete('/movie/1')
data = json.loads(res.data)
movie = Movie.query.filter(Movie.movie_id == 1).one_or_none()
self.assertEqual(data['success'], False)
self.assertEqual(data['message'], "resource not found")
self.assertEqual(res.status_code, 404)
def test_delete_actor(self):
res = self.client().delete('/actor/1')
data = json.loads(res.data)
actor = Actor.query.filter(Actor.actor_id == 1).one_or_none()
self.assertEqual(data['success'], False)
self.assertEqual(data['message'], "resource not found")
self.assertEqual(res.status_code, 404)
def test_404_no_movies(self):
res = self.client().get('/movies')
data = json.loads(res.data)
self.assertEqual(res.status_code, 404)
self.assertEqual(data['success'], False)
def test_404_no_actors(self):
res = self.client().get('/actors')
data = json.loads(res.data)
self.assertEqual(res.status_code, 404)
self.assertEqual(data['success'], False)
if __name__ == "__main__":
unittest.main()