Commit b4b719a1 authored by Daniele Venzano's avatar Daniele Venzano

Use pytest for unit tests

parent b715597d
...@@ -3,3 +3,4 @@ vulture ...@@ -3,3 +3,4 @@ vulture
doc8 doc8
mypy-lang mypy-lang
coverage coverage
pytest
...@@ -3,5 +3,7 @@ ...@@ -3,5 +3,7 @@
set -e set -e
pylint *.py zoe_* tests/*.py pylint *.py zoe_* tests/*.py
pytest --ignore tests pytest --tb=short
doc8 docs/ doc8 docs/
sh ./build_docs.sh sh ./build_docs.sh
...@@ -3,28 +3,36 @@ ...@@ -3,28 +3,36 @@
"size": 512, "size": 512,
"services": [ "services": [
{ {
"docker_image": "nginx:alpine", "image": "nginx:alpine",
"volumes": [],
"environment": [], "environment": [],
"essential_count": 1, "essential_count": 1,
"monitor": true, "monitor": true,
"name": "nginx", "name": "nginx",
"ports": [ "ports": [
{ {
"expose": false,
"is_main_endpoint": true,
"name": "Nginx Webserver", "name": "Nginx Webserver",
"path": "/", "url_template": "http://{ip_port}/",
"port_number": 80, "port_number": 80,
"protocol": "http" "protocol": "tcp"
} }
], ],
"required_resources": { "resources": {
"memory": 536870912 "memory": {
"min": 536870912,
"max": 536870912
},
"cores": {
"min": null,
"max": null
}
}, },
"startup_order": 0, "startup_order": 0,
"total_count": 1 "total_count": 1,
"replicas": 1,
"command": null
} }
], ],
"version": 2, "version": 3,
"will_end": false "will_end": false
} }
#!/usr/bin/env python3
# Copyright (c) 2017, Jordan Kuhn # Copyright (c) 2017, Jordan Kuhn
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
...@@ -17,54 +15,27 @@ ...@@ -17,54 +15,27 @@
"""Unit tests for zoe_lib/applications.py""" """Unit tests for zoe_lib/applications.py"""
import unittest import json
from unittest.mock import patch, MagicMock import pytest
from zoe_lib import applications from zoe_lib import applications
from zoe_lib import version
class TestApplicationsMethods(unittest.TestCase): class TestApplicationsMethods:
"""Application validation tests.""" """Application validation tests."""
app_validate_data = {}
port_check_data = {}
def setUp(self): def test_pass_for_zapp(self):
"""Set up tests.""" """Test zapp validation code."""
current_version = version.ZOE_APPLICATION_FORMAT_VERSION zapp_fp = json.load(open('tests/zapp.json', 'r'))
self.app_validate_data = { applications.app_validate(zapp_fp)
"name": "test name",
"will_end": True,
"size": 3,
"version": current_version,
"services": []
}
self.port_check_data = {
"name": "test name",
"protocol": "http",
"port_number": 3,
"is_main_endpoint": True
}
def test_pass_for_valid_port(self): def test_pass_for_complex_zapp(self):
"""Test port validation code.""" """Test zapp validation code."""
try: zapp_fp = json.load(open('contrib/zoeapps/eurecom_aml_lab.json', 'r'))
applications._port_check(self.port_check_data) # pylint: disable=protected-access applications.app_validate(zapp_fp)
except Exception:
self.fail("_port_check threw an exception for valid data")
def test_fails_for_bad_port_number(self): def test_fails_for_zapp(self):
"""Test validation of port number.""" """Test validation of port number."""
self.port_check_data["port_number"] = "not_a_number" bad_fp = open('/dev/random', 'r')
self.assertRaises(applications.InvalidApplicationDescription, applications._port_check, self.port_check_data) # pylint: disable=protected-access with pytest.raises(applications.InvalidApplicationDescription):
applications.app_validate(bad_fp)
def test_fails_for_missing_key(self):
"""Test missing name key from the port definition."""
del self.port_check_data["name"]
self.assertRaises(applications.InvalidApplicationDescription, applications._port_check, self.port_check_data) # pylint: disable=protected-access
@patch("zoe_lib.applications._validate_all_services", MagicMock())
@patch("zoe_lib.applications._port_check", MagicMock())
def test_pass_for_valid_app(self):
"""Test validation of entire app."""
applications.app_validate(self.app_validate_data)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment