Skip to content
Snippets Groups Projects
test_internal_controller.py 4.77 KiB
Newer Older
  • Learn to ignore specific revisions
  • David Trattnig's avatar
    David Trattnig committed
    #
    # Aura Engine API (https://gitlab.servus.at/aura/engine-api)
    #
    # Copyright (C) 2020 - The Aura Engine Team.
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as published by
    # the Free Software Foundation, either version 3 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 Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    
    David Trattnig's avatar
    David Trattnig committed
    
    from __future__ import absolute_import
    
    from flask import json
    
    
    from aura_engine_api.rest.models.clock_info import ClockInfo  # noqa: E501
    
    Chris Pastl's avatar
    Chris Pastl committed
    
    from . import BaseTestCase
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    class TestInternalController(BaseTestCase):
        """InternalController integration test stubs"""
    
    
    David Trattnig's avatar
    David Trattnig committed
        def test_add_playlog(self):
            """Test case for add_playlog
    
            Adds an entry to the playlog
            """
    
            body = {"trackStart": "2018-08-12 16:41+01:00"}
    
    David Trattnig's avatar
    David Trattnig committed
            response = self.client.open(
    
                "/api/v1/playlog",
                method="POST",
    
    David Trattnig's avatar
    David Trattnig committed
                data=json.dumps(body),
    
                content_type="application/json",
            )
    
    Chris Pastl's avatar
    Chris Pastl committed
            self.assert204(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
        def test_clock_info(self):
            """Test case for clock_info
    
            Get all information to display the studio clock
            """
    
            response = self.client.open("/api/v1/clock", method="GET")
            self.assert200(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    David Trattnig's avatar
    David Trattnig committed
        def test_get_active_source(self):
            """Test case for get_active_source
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    David Trattnig's avatar
    David Trattnig committed
            Get active play-out source (engine1, engine2)
    
    David Trattnig's avatar
    David Trattnig committed
            """
    
            response = self.client.open("/api/v1/source/active", method="GET")
    
    Chris Pastl's avatar
    Chris Pastl committed
            # TEMP FIX: we need some data to succeed with assert200
            self.assert204(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
        def test_get_report(self):
            """Test case for get_report
    
    David Trattnig's avatar
    David Trattnig committed
            Report for one month
    
            """
            response = self.client.open(
    
                "/api/v1/playlog/report/{year_month}".format(year_month="2020_02"), method="GET"
            )
            self.assert200(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    David Trattnig's avatar
    David Trattnig committed
        def test_get_source_health(self):
            """Test case for get_source_health
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    David Trattnig's avatar
    David Trattnig committed
            Get most recent health info
    
    David Trattnig's avatar
    David Trattnig committed
            """
            response = self.client.open(
    
                "/api/v1/source/health/{number}".format(number=2), method="GET"
            )
            self.assert200(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    David Trattnig's avatar
    David Trattnig committed
        def test_list_playlog(self):
            """Test case for list_playlog
    
            List tracks in the play-log since the given timestamp
            """
    
            query_string = [
                ("fromDate", "2013-10-20T19:20:30+01:00"),
                ("toDate", "2013-10-20T19:20:30+01:00"),
                ("page", 56),
                ("limit", 200),
                ("skipSynced", True),
            ]
    
    Chris Pastl's avatar
    Chris Pastl committed
            response = self.client.open("/api/v1/playlog", method="GET", query_string=query_string)
    
            self.assert200(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
        def test_log_source_health(self):
            """Test case for log_source_health
    
    Chris Pastl's avatar
    Chris Pastl committed
                "details": "",
    
                "isHealthy": True,
                "logTime": "2014-11-21T17:16:23+01:00",
    
            response = self.client.open(
    
                "api/v1/source/health/{number}".format(number=2),
                method="POST",
    
    David Trattnig's avatar
    David Trattnig committed
                data=json.dumps(body),
    
                content_type="application/json",
            )
    
    Chris Pastl's avatar
    Chris Pastl committed
            self.assert204(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
        def test_set_active_source(self):
            """Test case for set_active_source
    
            Set active play-out source (engine1, engine2)
            """
            response = self.client.open(
    
                "/api/v1/source/active/{number}".format(number=2), method="PUT"
            )
    
    Chris Pastl's avatar
    Chris Pastl committed
            self.assert204(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
    
        def test_set_clock_info(self):
            """Test case for set_clock_info
    
    
    Lars Kruse's avatar
    Lars Kruse committed
            Set current studio clock information such as timeslot info and track-list for engine 1 or 2
            within the Engine API database.
    
    David Trattnig's avatar
    David Trattnig committed
            """
    
    Chris Pastl's avatar
    Chris Pastl committed
            body = ClockInfo(engine_source=1)
    
    David Trattnig's avatar
    David Trattnig committed
            response = self.client.open(
    
                "/api/v1/clock", method="PUT", data=json.dumps(body), content_type="application/json"
            )
    
    Chris Pastl's avatar
    Chris Pastl committed
            self.assert204(response, "Response body is : " + response.data.decode("utf-8"))
    
    David Trattnig's avatar
    David Trattnig committed
    
    
    if __name__ == "__main__":
    
    David Trattnig's avatar
    David Trattnig committed
        import unittest
    
    Lars Kruse's avatar
    Lars Kruse committed
        unittest.main()