Permalink
Browse files

Fixes for videos tests

Adding info for missing youtube URLs

In test_subtitles_saving() made the youtube type return some subtitled
languages.

Changed the cleanup code to reset our mock objects __dict__ attributes
rather than simple calling reset_mock().

Moved utils to videotestutils so that the name doesn't conflict with
the utils package.

I'm not sure where along the lines these broke.
  • Loading branch information...
1 parent 63b2b5d commit fc261a4b41db1568bbead9a997d4be76b4bbff20 @bendk bendk committed Dec 4, 2012
@@ -393,7 +393,7 @@ def test_team_video_delete(self):
tv = test_factories.create_team_video(team, self.user, video)
# create a few languages with subs
- from videos.tests.utils import create_langs_and_versions
+ from videos.tests.videotestutils import create_langs_and_versions
video.is_public = False
video.moderated_by = team
video.save()
@@ -36,8 +36,6 @@
from apps.subtitles import pipeline
from apps.videos.tasks import video_changed_tasks, send_change_title_email, send_new_version_notification
-from apps.videos.tests import utils
-
class TestCeleryTasks(TestCase):
fixtures = ['test.json', 'subtitle_fixtures.json']
@@ -22,8 +22,7 @@
get_user, get_video, get_team, get_team_member, get_team_video,
make_subtitle_language, make_subtitle_version
)
-from apps.videos.tests.utils import WebUseTest
-
+from apps.videos.tests.videotestutils import WebUseTest
class TestFollowingVideos(WebUseTest):
def _assertFollowers(self, item, users):
@@ -30,7 +30,9 @@
from apps.videos.tests.data import (
get_video, get_user, make_subtitle_language
)
-from apps.videos.tests.utils import WebUseTest, refresh_obj, _create_trans
+from apps.videos.tests.videotestutils import (
+ WebUseTest, refresh_obj, _create_trans
+)
from apps.widget.rpc import Rpc
from apps.widget.tests import (
create_two_sub_dependent_session, create_two_sub_session, RequestMockup,
@@ -34,6 +34,7 @@
YoutubeVideoType, save_subtitles_for_lang,
_prepare_subtitle_data_for_version
)
+from utils import test_utils
class YoutubeVideoTypeTest(TestCase):
fixtures = ['test.json']
@@ -92,6 +93,9 @@ def test_shorter_format(self):
def test_subtitles_saving(self):
youtube_url = 'http://www.youtube.com/watch?v=L4XpSM87VUk'
+ test_utils.youtube_get_subtitled_languages.return_value = [
+ {'lang_code': 'en', 'name': 'My Subtitles'}
+ ]
vt = self.vt(youtube_url)
video, created = Video.get_or_create_for_url(youtube_url)
File renamed without changes.
@@ -31,7 +31,9 @@
from apps.auth.models import CustomUser as User
from apps.videos.share_utils import _make_email_url
from apps.videos.tasks import video_changed_tasks
-from apps.videos.tests.utils import WebUseTest, create_langs_and_versions
+from apps.videos.tests.videotestutils import (
+ WebUseTest, create_langs_and_versions
+)
from apps.videos.models import (
Video, VideoUrl, Action, VIDEO_TYPE_YOUTUBE, SubtitleVersion,
SubtitleLanguage, Subtitle, UserTestResult
View
@@ -138,6 +138,16 @@ def mock_youtube_get_entry(video_id):
'sWgyQjh5k7s': ('Status', 'Fernando Takai', '20'),
'MJRF8xGzvj4': ('David Bowie/Pat Metheny - This Is Not America '
'(Promo Clip)', 'skytrax1', '214'),
+ 'po0jY4WvCIc': ('Michael Jackson Pepsi Generation', 'GiraldiMedia',
+ '92'),
+ 'UOtJUmiUZ08': ('The YouTube Interview with Katy Perry',
+ 'KatyPerryMusic', '1892'),
+ 'HaAVZ2yXDBo': ("Breakfast at Ginger's- golden retriever dog eats "
+ "with hands", 'sawith65', '83'),
+ 'woobL2yAxD4': ('Goat yelling like a man', 'latestvideoss', '25'),
+ 'tKTZoB2Vjuk': ('Google Python Class Day 1 Part 1',
+ 'GoogleDevelopers', '3097'),
+ 'osexbB_hX4g': ('DO YOU SEE THAT??!!', 'otherijustine', '90'),
}
try:
title, author, duration = video_id_map[video_id]
@@ -202,10 +212,10 @@ def begin(self):
# Ugh have to patch the function twice since some modules use app and
# some don't
self.patches.append(mock.patch('apps.' + func_name, mock_obj))
- self.mock_objects = []
+ self.mock_object_initial_data = {}
for patch in self.patches:
mock_obj = patch.start()
- self.mock_objects.append(mock_obj)
+ self.mock_object_initial_data[mock_obj] = mock_obj.__dict__.copy()
mock_obj.original_func = patch.temp_original
mock_obj.run_original = functools.partial(self.run_original_func,
mock_obj)
@@ -219,5 +229,8 @@ def finalize(self, result):
patch.stop()
def afterTest(self, test):
- for mock_obj in self.mock_objects:
- mock_obj.reset_mock()
+ for mock_obj, initial_data in self.mock_object_initial_data.items():
+ # we used to call reset_mock() here, but this works better. It
+ # also resets the things like return_value and side_effect to
+ # their initial value.
+ mock_obj.__dict__ = initial_data.copy()

0 comments on commit fc261a4

Please sign in to comment.