Esempio n. 1
0
    def test_event_text(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["text"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["text"] = "Just some text"
        pl.parse(err_playlist)
    def test_event_text(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["text"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["text"] = "Just some text"
        pl.parse(err_playlist)
Esempio n. 3
0
    def test_event_type(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["type"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        err_playlist["events"][0]["type"] = "not_a_composition"
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["type"] = "composition"
        pl.parse(err_playlist)
    def test_event_cpl_uuid(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["cpl_id"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        err_playlist["events"][0]["cpl_id"] = "A string but not a valid uuid"
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["cpl_id"] = "00000000-0000-0000-0000-100000000001"
        pl.parse(err_playlist)
    def test_event_type(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["type"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        err_playlist["events"][0]["type"] = "not_a_composition"
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["type"] = "composition"
        pl.parse(err_playlist)
    def test_no_title(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        del(err_playlist["title"])

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Not a string
        err_playlist["title"] = 100
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["title"] = "Testing"
        pl.parse(err_playlist)
    def test_event_duration_in_seconds(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["duration_in_seconds"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Only allow integer values.
        err_playlist["events"][0]["duration_in_seconds"] = 100.1
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["duration_in_seconds"] = 100
        pl.parse(err_playlist)
Esempio n. 8
0
    def test_event_cpl_uuid(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["cpl_id"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        err_playlist["events"][0]["cpl_id"] = "A string but not a valid uuid"
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0][
            "cpl_id"] = "00000000-0000-0000-0000-100000000001"
        pl.parse(err_playlist)
Esempio n. 9
0
    def test_event_duration_in_seconds(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["duration_in_seconds"] = None

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Only allow integer values.
        err_playlist["events"][0]["duration_in_seconds"] = 100.1
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["duration_in_seconds"] = 100
        pl.parse(err_playlist)
Esempio n. 10
0
    def test_no_title(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        del (err_playlist["title"])

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Not a string
        err_playlist["title"] = 100
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["title"] = "Testing"
        pl.parse(err_playlist)
Esempio n. 11
0
    def test_success(self):
        pl = Playlist()
        pl.parse(success_playlist)

        self.assertEqual(pl.title, "Test playlist")
        self.assertEqual(pl.duration, 3600)
        self.assertEqual(len(pl.events), 2)

        event0 = pl.events[0]
        self.assertEqual(event0.cpl_id, "00000000-0000-0000-0000-100000000001")
        self.assertEqual(event0.type, "composition")
        self.assertEqual(event0.text, "Test CPL")
        self.assertEqual(event0.duration_in_frames, 43200)
        self.assertEqual(event0.duration_in_seconds, 1800.0)
        self.assertEqual(event0.edit_rate[0], 24)
        self.assertEqual(event0.edit_rate[1], 1)
Esempio n. 12
0
    def test_success(self):
        pl = Playlist()
        pl.parse(success_playlist)

        self.assertEqual(pl.title, "Test playlist")
        self.assertEqual(pl.duration, 3600)
        self.assertEqual(len(pl.events), 2)

        event0 = pl.events[0]
        self.assertEqual(event0.cpl_id, "00000000-0000-0000-0000-100000000001")
        self.assertEqual(event0.type, "composition")
        self.assertEqual(event0.text, "Test CPL")
        self.assertEqual(event0.duration_in_frames, 43200)
        self.assertEqual(event0.duration_in_seconds, 1800.0)
        self.assertEqual(event0.edit_rate[0], 24)
        self.assertEqual(event0.edit_rate[1], 1)
Esempio n. 13
0
    def update_playlist(self, playlist_uuid, playlist_contents, *args):
        """
        Saves a show playlist into memory for playback.

        Args:
            playlist_uuid (string): UUID of the playlist to update
            playlist_contents (dict): Takes the dict structure used for the internal playlist representation in Screenwriter.

        Returns:
            The return status::

                0 -- Success
                2 -- Playlist not found
                8 -- Invalid playlist supplied
        """

        if playlist_uuid not in self.playlists:
            return rsp_codes[2]

        try:
            playlist = Playlist(playlist_contents)
        except PlaylistValidationError:
            rsp = rsp_codes[8]
            rsp['trace'] = traceback.format_exc()
            return rsp

        self.playlists[playlist_uuid] = playlist

        return rsp_codes[0]
Esempio n. 14
0
    def insert_playlist(self, playlist_contents):
        """
        Saves a show playlist into memory for playback.

        Args:
            playlist_contents (dict): Takes the dict structure used for the internal playlist representation in Screenwriter.

        Returns:
            The return status::

                0 -- Success
                8 -- Invalid playlist supplied

            The playlist_uuid generated for future reference. This should be stored in the client.
        """

        # Just make sure we don't overwrite an existing playlist! Silly python not having do-while..
        while True:
            playlist_uuid = str(uuid4())
            if playlist_uuid not in self.playlists:
                break

        try:
            playlist = Playlist(playlist_contents)
        except PlaylistValidationError as e:
            rsp = rsp_codes[8]
            rsp['trace'] = traceback.format_exc()
            return rsp

        self.playlists[playlist_uuid] = playlist

        rsp = rsp_codes[0]
        rsp['playlist_uuid'] = playlist_uuid
        return rsp
Esempio n. 15
0
    def test_no_duration(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        del (err_playlist["duration"])

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Not an integer
        err_playlist["duration"] = "100"
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        err_playlist["duration"] = 100.1
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["duration"] = 100
        pl.parse(err_playlist)
Esempio n. 16
0
    def test_no_duration(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        del(err_playlist["duration"])

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Not an integer
        err_playlist["duration"] = "100"
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        err_playlist["duration"] = 100.1
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["duration"] = 100
        pl.parse(err_playlist)
Esempio n. 17
0
    def test_no_events(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"] = []

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        del (err_playlist["events"])
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)
Esempio n. 18
0
    def test_event_edit_rate(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["edit_rate"] = []

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Must be exactly 2 integer values
        err_playlist["events"][0]["edit_rate"] = [100]
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)
        err_playlist["events"][0]["edit_rate"] = [100, 100, 100]
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Only allow integer values.
        err_playlist["events"][0]["edit_rate"] = [100.1, 100.1]
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["edit_rate"] = [24, 1]
        pl.parse(err_playlist)
Esempio n. 19
0
    def test_event_edit_rate(self):
        # Set up the data to start off with.
        err_playlist = json.loads(success_playlist)
        err_playlist["events"][0]["edit_rate"] = []

        pl = Playlist()
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Must be exactly 2 integer values
        err_playlist["events"][0]["edit_rate"] = [100]
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)
        err_playlist["events"][0]["edit_rate"] = [100, 100, 100]
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Only allow integer values.
        err_playlist["events"][0]["edit_rate"] = [100.1, 100.1]
        self.assertRaises(PlaylistValidationError, pl.parse, err_playlist)

        # Finally a successful test
        err_playlist["events"][0]["edit_rate"] = [24, 1]
        pl.parse(err_playlist)
Esempio n. 20
0
    def __init__(self, playlists_path=None):
        """
        Initialises the Playlist store, reads in playlists stored on disk if the path is supplied.

        Args:
            playlists_path (string, None): The directory containing the playlist files in json format.
        """
        self.playlists = {}
        self.playlists_path = playlists_path

        # If a playlists path is given we should read them in.
        if self.playlists_path is not None:
            # First ensure we have a directory to work from!
            if not os.path.isdir(self.playlists_path):
                os.mkdir(self.playlists_path)

            # Secondly read in the files themselves.
            for filename in os.listdir(self.playlists_path):
                filepath = os.path.join(self.playlists_path, filename)
                with open(filepath) as pl_file:
                    contents = json.load(pl_file)
                    self.playlists[filename] = Playlist(contents)