<s> import os <EOL> from urllib2 import urlparse <EOL> try : <EOL> import Image <EOL> except ImportError : <EOL> from PIL import Image <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> from django . conf import settings <EOL> from django . core . files import storage <EOL> from django . core . files . base import ContentFile <EOL> from django . core . urlresolvers import reverse , NoReverseMatch <EOL> from django . test import TestCase <EOL> from django . utils import simplejson <EOL> import oembed <EOL> from oembed . providers import BaseProvider <EOL> from oembed . resources import OEmbedResource <EOL> from oembed . tests . settings import MEDIA_ROOT , MEDIA_URL , DEFAULT_FILE_STORAGE <EOL> from oembed . tests . storage import DummyMemoryStorage <EOL> class BaseOEmbedTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> urls = '<STR_LIT>' <EOL> flickr_url = '<STR_LIT>' <EOL> youtube_url = '<STR_LIT>' <EOL> category_url = '<STR_LIT>' <EOL> blog_url = '<STR_LIT>' <EOL> rich_url = '<STR_LIT>' <EOL> category_embed = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> "<STR_LIT>" <EOL> oembed . autodiscover ( ) <EOL> oembed . site . _db_updated = None <EOL> self . storage = DummyMemoryStorage ( ) <EOL> self . orig_default_storage = storage . default_storage <EOL> storage . default_storage = self . storage <EOL> self . media_root , self . media_url = settings . MEDIA_ROOT , settings . MEDIA_URL <EOL> settings . MEDIA_ROOT = MEDIA_ROOT <EOL> settings . MEDIA_URL = MEDIA_URL <EOL> self . template_dirs = settings . TEMPLATE_DIRS <EOL> cur_dir = os . path . dirname ( __file__ ) <EOL> settings . TEMPLATE_DIRS = [ os . path . join ( os . path . dirname ( cur_dir ) , '<STR_LIT>' ) ] <EOL> self . orig_file_storage = settings . DEFAULT_FILE_STORAGE <EOL> settings . DEFAULT_FILE_STORAGE = DEFAULT_FILE_STORAGE <EOL> test_image = Image . new ( '<STR_LIT>' , ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> , <NUM_LIT:255> ) ) <EOL> self . test_img_buffer = StringIO ( ) <EOL> test_image . save ( self . test_img_buffer , '<STR_LIT>' ) <EOL> self . test_img_file = ContentFile ( self . test_img_buffer . getvalue ( ) ) <EOL> self . test_img_location = '<STR_LIT>' <EOL> storage . default_storage . save ( self . test_img_location , self . test_img_file ) <EOL> def tearDown ( self ) : <EOL> settings . MEDIA_ROOT = self . media_root <EOL> settings . MEDIA_URL = self . media_url <EOL> settings . TEMPLATE_DIRS = self . template_dirs <EOL> settings . DEFAULT_FILE_STORAGE = self . orig_file_storage <EOL> storage . default_storage = self . orig_default_storage <EOL> def _sort_by_pk ( self , list_or_qs ) : <EOL> annotated = [ ( item . pk , item ) for item in list_or_qs ] <EOL> annotated . sort ( ) <EOL> return map ( lambda item_tuple : item_tuple [ <NUM_LIT:1> ] , annotated ) <EOL> def assertQuerysetEqual ( self , a , b ) : <EOL> return self . assertEqual ( self . _sort_by_pk ( a ) , self . _sort_by_pk ( b ) ) </s>
