Added basic tests for the subtitle plugin
[mediagoblin.git] / mediagoblin / tests / test_subtitles.py
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
17 from mediagoblin.tests import tools
18 from mediagoblin import mg_globals
19 from mediagoblin.db.models import User, MediaEntry
20 from mediagoblin.db.base import Session
21 from mediagoblin.tools.testing import _activate_testing
22 from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry
23 from mediagoblin.plugins.subtitles.tools import open_subtitle, save_subtitle
24
25 # Checking if the subtitle entry is working
26
27 def 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
43 def test_read_write_file(test_app):
44 test_filepath = ['test']
45
46 save_subtitle(test_filepath,"Testing!!!")
47 text = open_subtitle(test_filepath)
48
49 assert text == "Testing!!!"
50
51 mg_globals.public_store.delete_file(test_filepath)