Skip to content

Commit

Permalink
Merge e3d678b into 01cb3f0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sispheor committed Nov 10, 2019
2 parents 01cb3f0 + e3d678b commit 86752a5
Show file tree
Hide file tree
Showing 53 changed files with 2,995 additions and 2,342 deletions.
80 changes: 52 additions & 28 deletions .travis.yml
@@ -1,37 +1,61 @@
language: python

services:
- docker

python:
- "2.7"
- "3.6"
- "3.7"

# command to install dependencies
before_install:
- docker build --force-rm=true --build-arg TRAVIS_BRANCH=${TRAVIS_BRANCH} --build-arg TRAVIS_EVENT_TYPE=${TRAVIS_EVENT_TYPE} --build-arg TRAVIS_PULL_REQUEST_SLUG=${TRAVIS_PULL_REQUEST_SLUG} --build-arg TRAVIS_PULL_REQUEST_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH} -t kalliope-ubuntu1604 -f docker/ubuntu_16_04.dockerfile .
- docker build --force-rm=true --build-arg TRAVIS_BRANCH=${TRAVIS_BRANCH} --build-arg TRAVIS_EVENT_TYPE=${TRAVIS_EVENT_TYPE} --build-arg TRAVIS_PULL_REQUEST_SLUG=${TRAVIS_PULL_REQUEST_SLUG} --build-arg TRAVIS_PULL_REQUEST_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH} -t kalliope-debian8 -f docker/debian8.dockerfile .
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse"
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse"
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse"
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update -q
- sudo apt-get install $(cat install/files/deb-packages_requirements.txt)
- sudo apt-get install gcc-4.9 libstdc++6 libpython3.4-dev
- wget https://bootstrap.pypa.io/get-pip.py
- sudo python get-pip.py
env:
global:
- INSTALL_TYPE=setup

install:
- pip install -r install/files/python_requirements.txt
- pip install coverage python-coveralls
matrix:
include:
- name: Test in Docker Ubuntu 18.04
env:
- INSTALL_TYPE=docker
services:
- docker
before_install:
- docker build --force-rm=true -t kalliope-ubuntu1804 -f docker/testing_ubuntu_18_04.dockerfile .
script:
- docker run -it --rm -e TRAVIS_BRANCH=${TRAVIS_BRANCH} -e TRAVIS_EVENT_TYPE=${TRAVIS_EVENT_TYPE} -e TRAVIS_PULL_REQUEST_SLUG=${TRAVIS_PULL_REQUEST_SLUG} -e TRAVIS_PULL_REQUEST_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH} kalliope-ubuntu1804

# command to run tests
script:
# - pytest
- docker run -it --rm kalliope-ubuntu1604
- docker run -it --rm kalliope-debian8
- coverage run --source=kalliope -m unittest discover
- coverage report -m
- name: Test in Docker Debian 10
env:
- INSTALL_TYPE=docker
services:
- docker
before_install:
- docker build --force-rm=true -t kalliope-debian10 -f docker/testing_debian10.dockerfile .
script:
- docker run -it --rm -e TRAVIS_BRANCH=${TRAVIS_BRANCH} -e TRAVIS_EVENT_TYPE=${TRAVIS_EVENT_TYPE} -e TRAVIS_PULL_REQUEST_SLUG=${TRAVIS_PULL_REQUEST_SLUG} -e TRAVIS_PULL_REQUEST_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH} kalliope-debian10


before_install:
- |
if [ "${INSTALL_TYPE}" == "setup" ]; then
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse"
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse"
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse"
sudo add-apt-repository -y ppa:deadsnakes/ppa # contains libpython3.6-dev
sudo apt-get update -q
sudo apt-get install $(cat install/files/deb-packages_requirements.txt)
sudo apt-get install gcc-5 python3-dev libpython3.6-dev
fi
install:
- |
if [ "${INSTALL_TYPE}" == "setup" ]; then
pip install -r install/files/python_requirements.txt;
pip install coverage python-coveralls;
fi
script:
- |
if [ "${INSTALL_TYPE}" == "setup" ]; then
coverage run --source=kalliope -m unittest discover;
coverage report -m;
fi
after_success:
- coveralls
- |
if [ "${INSTALL_TYPE}" == "setup" ]; then
coveralls
fi
4 changes: 3 additions & 1 deletion Tests/__init__.py
Expand Up @@ -2,7 +2,9 @@
from .test_configuration_checker import TestConfigurationChecker
from .test_dynamic_loading import TestDynamicLoading
from .test_file_manager import TestFileManager
from .test_rest_api import TestRestAPI
from Tests.test_api.test_main_view import TestMainView
from Tests.test_api.test_settings_view import TestSettingsView
from Tests.test_api.test_synapse_view import TestSynapseView
from .test_settings_loader import TestSettingLoader
from .test_singleton import TestSingleton
from .test_tts_module import TestTTSModule
Expand Down
4 changes: 2 additions & 2 deletions Tests/brains/brain_test_api.yml
Expand Up @@ -9,10 +9,10 @@

- name: "test2"
signals:
- order: "bonjour"
- order: "test_order_miss_configured_neuron"
neurons:
- say:
message:
not_valid_parameter:
- "test message"

- includes:
Expand Down
Empty file added Tests/test_api/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions Tests/test_api/base.py
@@ -0,0 +1,53 @@
import os

from flask import Flask
from flask_testing import LiveServerTestCase

from kalliope.core import LifoManager
from kalliope.core.ConfigurationManager import BrainLoader
from kalliope.core.ConfigurationManager import SettingLoader
from kalliope.core.Models import Singleton
from kalliope.core.RestAPI.FlaskAPI import FlaskAPI


class RestAPITestBase(LiveServerTestCase):

def tearDown(self):
Singleton._instances = {}
# clean the lifo
LifoManager.clean_saved_lifo()

def create_app(self):
"""
executed once at the beginning of the test
"""
# be sure that the singleton haven't been loaded before
Singleton._instances = {}
current_path = os.getcwd()
if "/Tests" in current_path:
full_path_brain_to_test = current_path + os.sep + os.pardir + os.sep + "brains/brain_test_api.yml"
self.audio_file = "files/bonjour.wav"
else:
full_path_brain_to_test = current_path + os.sep + "Tests/brains/brain_test_api.yml"
self.audio_file = "Tests/files/bonjour.wav"

# rest api config
self.sl = SettingLoader()
self.settings = self.sl.settings
self.settings.rest_api.password_protected = False
self.settings.active = True
self.settings.port = 5000
self.settings.allowed_cors_origin = "*"
self.settings.default_synapse = None
self.settings.hooks["on_order_not_found"] = "order-not-found-synapse"

# prepare a test brain
brain_to_test = full_path_brain_to_test
brain_loader = BrainLoader(file_path=brain_to_test)
brain = brain_loader.brain

self.app = Flask(__name__)
self.app.config['TESTING'] = True
self.flask_api = FlaskAPI(self.app, port=5000, brain=brain)
self.client = self.app.test_client()
return self.flask_api.app
26 changes: 26 additions & 0 deletions Tests/test_api/test_main_view.py
@@ -0,0 +1,26 @@
import json
import unittest

from Tests.test_api.base import RestAPITestBase
from kalliope._version import version_str


class TestMainView(RestAPITestBase):

def test_server_is_up_and_running(self):
# response = urllib2.urlopen(self.get_server_url())
response = self.client.get(self.get_server_url())
self.assertEqual(response.status_code, 200)

def test_get_main_page(self):
url = self.get_server_url() + "/"
response = self.client.get(url)
expected_content = {
"Kalliope version": "%s" % version_str
}
self.assertEqual(json.dumps(expected_content, sort_keys=True),
json.dumps(json.loads(response.get_data().decode('utf-8')), sort_keys=True))


if __name__ == '__main__':
unittest.main()

0 comments on commit 86752a5

Please sign in to comment.