Add tests for api/server.py

some of the new tests require that we first build the documentation
This commit is contained in:
Alexander Todorov 2018-02-12 16:56:24 +02:00 committed by Brian C. Lane
parent 32db249538
commit 1c977b79ef
2 changed files with 20 additions and 1 deletions

View File

@ -25,7 +25,8 @@ check:
@echo "*** Running pylint ***"
PYTHONPATH=$(PYTHONPATH):./src/ ./tests/pylint/runpylint.py
test:
# /api/docs/ tests require we have the documentation already built
test: docs
@echo "*** Running tests ***"
PYTHONPATH=$(PYTHONPATH):./src/ $(PYTHON) -m nose -v --with-coverage --cover-erase --cover-branches \
--cover-package=pylorax --cover-inclusive \

View File

@ -14,6 +14,7 @@
# 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 os
import shutil
import tempfile
from threading import Lock
@ -53,6 +54,11 @@ class ServerTestCase(unittest.TestCase):
def tearDownClass(self):
shutil.rmtree(server.config["REPO_DIR"])
def test_00_hello(self):
"""Test /"""
resp = self.server.get("/")
self.assertEqual(resp.data, 'Hello, World!')
def test_01_status(self):
"""Test the /api/v0/status route"""
status_dict = {"build":"devel", "api":"0", "db_version":"0", "schema_version":"0", "db_supported":False}
@ -484,3 +490,15 @@ class ServerTestCase(unittest.TestCase):
recipes = data.get("recipes")
self.assertEqual(len(recipes), 1)
self.assertEqual(recipes[0], test_recipe)
def test_api_docs(self):
"""Test the /api/docs/"""
resp = self.server.get("/api/docs/")
doc_str = open(os.path.abspath(joinpaths(os.path.dirname(__file__), "../../docs/html/index.html"))).read()
self.assertEqual(doc_str, resp.data)
def test_api_docs_with_existing_path(self):
"""Test the /api/docs/modules.html"""
resp = self.server.get("/api/docs/modules.html")
doc_str = open(os.path.abspath(joinpaths(os.path.dirname(__file__), "../../docs/html/modules.html"))).read()
self.assertEqual(doc_str, resp.data)