generated from Code-Institute-Org/gitpod-full-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_app.py
65 lines (48 loc) · 2.04 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
import unittest
from app import app, change_date_format
from datetime import datetime
class TestDateFormat(unittest.TestCase):
def test_correctly_converts_data_to_string(self):
# Test whether the datetime values are being converted into strings
# Test data
testDates = [
{"date_created": datetime(2021, 10, 26)},
{"date_created": datetime(2020, 5, 17)}]
# Test function
modified_testDates = change_date_format(testDates)
# Test data type equals string
self.assertEqual(
type(modified_testDates[0]["date_created"]), type("string"))
self.assertEqual(
type(modified_testDates[1]["date_created"]), type("string"))
def test_string_displays_correct_date(self):
# Test if the datetime values are being converted into the correct date
# Test data
testDates = [
{"date_created": datetime(2021, 10, 26)},
{"date_created": datetime(2020, 5, 17)}]
# Test function
modified_testDates = change_date_format(testDates)
# Test data type equals string
self.assertEqual(modified_testDates[0]["date_created"], "Oct 26 2021")
self.assertEqual(modified_testDates[1]["date_created"], "May 17 2020")
class TestFlaskRouting(unittest.TestCase):
# executed before each test
def setUp(self):
app.config['TESTING'] = True
app.config['DEBUG'] = False
self.app = app.test_client()
# executed after each test
def tearDown(self):
pass
# test the status code 200 when rendering routes
def test_status_code_is_200(self):
response = self.app.get('/home', follow_redirects=True)
self.assertEqual(response.status_code, 200)
# test the correct template is being rendered
def test_correct_template_is_rendered(self):
response = self.app.get('/home', follow_redirects=True)
self.assertIn(
b"FIND THE BEST RECIPES TO FUEL YOUR PERFORMANCE", response.data)
if __name__ == "__main__":
unittest.main()