lorax/tests/pylorax/test_server.py

59 lines
2.1 KiB
Python
Raw Normal View History

2017-11-07 20:00:35 +00:00
#
# Copyright (C) 2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import tempfile
from threading import Lock
2017-11-07 20:00:35 +00:00
import unittest
from flask import json
from pylorax.api.recipes import open_or_create_repo, commit_recipe_directory
from pylorax.api.server import server, GitLock
2017-11-07 20:00:35 +00:00
class ServerTestCase(unittest.TestCase):
@classmethod
def setUpClass(self):
repo_dir = tempfile.mkdtemp(prefix="lorax.test.repo.")
server.config["REPO_DIR"] = repo_dir
repo = open_or_create_repo(server.config["REPO_DIR"])
server.config["GITLOCK"] = GitLock(repo=repo, lock=Lock(), dir=repo_dir)
2017-11-07 20:00:35 +00:00
server.config['TESTING'] = True
self.server = server.test_client()
# Import the example recipes
commit_recipe_directory(server.config["GITLOCK"].repo, "master", "tests/pylorax/recipes/")
2017-11-07 20:00:35 +00:00
@classmethod
def tearDownClass(self):
pass
def test_status(self):
"""Test the /api/v0/status route"""
status_dict = {"build":"devel", "api":"0", "db_version":"0", "schema_version":"0", "db_supported":False}
resp = self.server.get("/api/v0/status")
data = json.loads(resp.data)
self.assertEqual(data, status_dict)
def test_recipes_list(self):
"""Test the /api/v0/recipes/list route"""
list_dict = {"recipes":["atlas", "development", "glusterfs", "http-server", "jboss", "kubernetes"],
"limit":20, "offset":0, "total":6}
resp = self.server.get("/api/v0/recipes/list")
data = json.loads(resp.data)
self.assertEqual(data, list_dict)