-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
39 lines (30 loc) · 1.18 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
import os
import unittest
from app import create_app
from models.models import create_db
from dotenv import load_dotenv
from flask_sqlalchemy import SQLAlchemy
import json
load_dotenv()
class YITestCase(unittest.TestCase):
def setUp(self):
self.app = create_app()
self.client = self.app.test_client
self.database_name = "yi_test"
self.database_path = "postgresql://{}:{}@{}/{}".format(
os.getenv('USER'), os.getenv('PASSWORD'), 'localhost:5432', self.database_name)
create_db(self.app, self.database_path)
with self.app.app_context():
self.db = SQLAlchemy()
self.db.init_app(self.app)
# barcha jadvallarni yaratish
self.db.create_all()
def tearDown(self):
"""Men test uchun alohida database ochdim (yi_test).
Agar test uchun ham production uchun ishlatilinadigan database dan foydalanmoqchi bo'lsangiz (yi),
testdan so'ng database ma'lumotlarini asil holiga qaytaruvchi code shu yerda yoziladi.
"""
pass
def test_a_get_course_by_id(self):
res = self.client().get('/categories/9999')
data = json.loads(res.data)