51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from alembic import command
|
|
import unittest
|
|
|
|
from app import app, db, migrate
|
|
from ki.actions import seed
|
|
|
|
|
|
class TestSkillsEndpoint(unittest.TestCase):
|
|
def setUp(self):
|
|
app.debug = True
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
|
|
self.client = app.test_client()
|
|
|
|
with app.app_context():
|
|
config = migrate.get_config()
|
|
command.upgrade(config, "head")
|
|
|
|
seed(True)
|
|
|
|
def tearDown(self):
|
|
db.drop_all()
|
|
db.engine.dispose()
|
|
|
|
def test_skills_options(self):
|
|
response = self.client.options("/skills")
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
|
|
|
def test_get_skills1(self):
|
|
response = self.client.get("/skills?search=p")
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(
|
|
{
|
|
"skills": [{
|
|
"id": 1,
|
|
"name": "PHP",
|
|
"icon_url": "/skills/1/icon"
|
|
}, {
|
|
"id": 3,
|
|
"name": "Python",
|
|
"icon_url": "/skills/3/icon"
|
|
}]
|
|
}, response.json)
|
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
|
|
|
|
|
if __name__ == "main":
|
|
unittest.main()
|