-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_events.py
129 lines (110 loc) · 4.1 KB
/
test_events.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import os
import json
from app import create_app, sqlalchemy as db
from sqlalchemy import create_engine, text
from flask_sqlalchemy import SQLAlchemy
from app.config import TestingConfig
from models import initialize_db
import unittest
class EventsTestCase(unittest.TestCase):
"""This class represents the Event App test case"""
def setUp(self):
"""Executed before each test.
Define test variables and initialize app."""
self.app = create_app(TestingConfig)
self.client = self.app.test_client
self.event = {
"title": "Markup Start",
"description": "This is an event I am creating fo\
r meeting with friends",
"start_datetime": "2020-05-30 15:45",
"location": "Douala Bonamoussadi",
"event_type_id": 1,
"image_url": "https://img.nen/j.png",
"organizer_id": 1
}
with self.app.app_context():
db.create_all()
initialize_db()
def tearDown(self):
with self.app.app_context():
db.session.remove()
db.drop_all()
"""
===========================================
Events Tests
===========================================
"""
def test_create_new_events(self):
"""
Test create new events endpoint
"""
res = self.client().post("/api/v1/events", json=self.event)
self.assertEqual(res.status_code, 200)
def test_get_event(self):
"""
Test to get single event with given event ID
"""
res = self.client().get("/api/v1/events/3")
self.assertEqual(res.status_code, 200)
def test_update_event(self):
"""
Test update event with given event_id
"""
res = self.client().patch("/api/v1/events/1",
json=self.event)
self.assertEqual(res.status_code, 200)
def test_delete_event(self):
"""
Test for delete event failure with not found id
"""
res = self.client().delete("/api/v1/events/2")
self.assertEqual(res.status_code, 200)
def test_get_all_events(self):
"""
Test get all events
"""
res = self.client().get("/api/v1/events")
self.assertEqual(res.status_code, 200)
self.assertIsInstance(res.json["data"], list)
self.assertGreater(len(res.json["data"]), 0)
self.assertEqual(res.json['success'], True)
def test_failed_create_new_event(self):
"""
Test for failure during creation of new event
"""
res = self.client().post("/api/v1/events",
json={"empty": "body"})
self.assertEqual(res.status_code, 400)
def test_get_event_not_found(self):
"""
Test of non-existent event with given id
"""
res = self.client().get("/api/v1/events/100",
json=self.event)
self.assertEqual(res.status_code, 404)
def test_update_event_not_found(self):
"""
Test for update event failure with not found id
"""
res = self.client().patch("/api/v1/events/100",
json=self.event)
self.assertEqual(res.status_code, 404)
def test_delete_event_not_found(self):
"""
Test for update event failure with not found id
"""
res = self.client().delete("/api/v1/events/150")
self.assertEqual(res.status_code, 404)
"""
def test_delete_event_unauthorized(self):
res = self.client().delete("/api/v1/events/3")
self.assertEqual(res.status_code, 401)
# Failing"""
"""def test_create_new_events_unauthorized(self):
# Test create new events endpoint
res = self.client().post("/api/v1/events", json=self.event)
self.assertEqual(res.status_code, 401)"""
# Make the tests conveniently executable
if __name__ == "__main__":
unittest.main()