Skip to content

Commit

Permalink
Merge pull request #160 from Tastyep/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Tastyep authored Mar 31, 2021
2 parents 7c51bba + c8739c8 commit f427d22
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
run: ./setup.sh --ci
#
- name: Test
env:
OPENCAST_LOG__LEVEL: DEBUG
run: ./OpenCast.sh test all --coverage
#
- name: Coverage upload
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ coverage.xml
/.coverage
/library
/config.yml
.vim/
tags
4 changes: 3 additions & 1 deletion OpenCast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

def run_server(logger, infra_facade):
try:
infra_facade.server.start(settings["server.host"], settings["server.port"])
infra_facade.server.start(
settings["server.host"], settings["server.port"], settings["log.api_trafic"]
)
except Exception as e:
logger.error(
"Server exception caught", error=e, traceback=traceback.format_exc()
Expand Down
2 changes: 1 addition & 1 deletion OpenCast/app/workflow/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def on_enter_QUEUEING(self):
self._app_facade,
self._data_facade,
self.video,
queue_front=False,
queue_front=True,
)
self._observe_start(workflow)

Expand Down
1 change: 1 addition & 0 deletions OpenCast/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
default="INFO",
is_in=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"],
),
Validator("LOG.API_TRAFIC", default=False, is_in=[True, False]),
Validator("SERVER.HOST", default="0.0.0.0"),
Validator("SERVER.PORT", default=2020),
Validator("DATABASE.FILE", default="opencast.db"),
Expand Down
7 changes: 5 additions & 2 deletions OpenCast/infra/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ def __init__(self, app):
def route(self, method, route, handle):
route = self.app.router.add_route(method, route, handle)

def start(self, host, port):
def start(self, host, port, log_trafic: bool):
self._logger.info("Started", host=host, port=port)

web.run_app(self.app, host=host, port=port, access_log_class=AccessLogger)
options = {}
if log_trafic is True:
options["access_log_class"] = AccessLogger
web.run_app(self.app, host=host, port=port, **options)

def make_web_socket(self):
ws = web.WebSocketResponse()
Expand Down
4 changes: 4 additions & 0 deletions template/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
default:
log:
# The level of the module's logger
# One of [CRITICAL, ERROR, WARNING, INFO, DEBUG]
level: DEBUG
# Log requests/responses from the API
api_trafic: False

server:
# The IP from where the service is accessible
Expand Down Expand Up @@ -33,3 +36,4 @@ default:
testing:
log:
level: CRITICAL
api_trafic: False
9 changes: 5 additions & 4 deletions test/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
from test.util import TestCase
from unittest.mock import Mock

import structlog

from OpenCast import run_init_workflow, run_server
from OpenCast.app.workflow.factory import WorkflowFactory
from OpenCast.domain.event.dispatcher import EventDispatcher


class MainTest(TestCase):
def test_run_server(self):
logger = Mock()
logger = structlog.get_logger("OpenCast")
infra_facade = InfraFacadeMock()
self.assertTrue(run_server(logger, infra_facade))

def test_run_server_with_exception(self):
logger = Mock()
logger = structlog.get_logger("OpenCast")
infra_facade = InfraFacadeMock()

def start_server():
def start_server(*args, **kwargs):
raise Exception("")

infra_facade.server.start.side_effect = start_server
self.assertFalse(run_server(logger, infra_facade))
logger.error.assert_called_once()

def test_run_init_workflow_success(self):
app_facade = AppFacadeMock()
Expand Down

0 comments on commit f427d22

Please sign in to comment.