Test and update the media-types docs with Debian 10 and CentOS.
[mediagoblin.git] / mediagoblin / tests / test_subtitles.py
CommitLineData
464d7972 1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from mediagoblin.tests import tools
18from mediagoblin import mg_globals
19from mediagoblin.db.models import User, MediaEntry
20from mediagoblin.db.base import Session
21from mediagoblin.tools.testing import _activate_testing
22from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry
23from mediagoblin.plugins.subtitles.tools import open_subtitle, save_subtitle
24
25# Checking if the subtitle entry is working
26
27def test_add_subtitle_entry(test_app):
28 user_a = fixture_add_user(u"test_user")
29
30 media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
31 media.subtitle_files.append(dict(
32 name=u"some name",
33 filepath=[u"does", u"not", u"exist"],
34 ))
35 Session.add(media)
36 Session.flush()
37
38 MediaEntry.query.get(media.id).delete()
39 User.query.get(user_a.id).delete()
40
41# Checking the tools written for subtitles
42
43def test_read_write_file(test_app):
44 test_filepath = ['test']
45
6dce7184 46 status = save_subtitle(test_filepath,"Testing!!!")
47 text = open_subtitle(test_filepath)[0]
464d7972 48
6dce7184 49 assert status == True
464d7972 50 assert text == "Testing!!!"
51
52 mg_globals.public_store.delete_file(test_filepath)
6dce7184 53
54# Checking the customize exceptions
55
56def test_customize_subtitle(test_app):
57 user_a = fixture_add_user(u"test_user")
58
59 media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False)
60 media.subtitle_files.append(dict(
61 name=u"some name",
62 filepath=[u"does", u"not", u"exist"],
63 ))
64 Session.add(media)
65 Session.flush()
66
67 for subtitle in media.subtitle_files:
68 assert '' == open_subtitle(subtitle['filepath'])[0]