<s> """<STR_LIT>""" <EOL> from io import BytesIO <EOL> import warnings <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . sites . models import Site <EOL> from django . core . files . uploadedfile import SimpleUploadedFile <EOL> from django . utils . timezone import now <EOL> from hashlib import md5 <EOL> try : <EOL> from PIL import Image <EOL> except ImportError : <EOL> pass <EOL> import factory <EOL> class HvadFactoryMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , ** kwargs ) : <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return super ( HvadFactoryMixin , cls ) . __new__ ( ** kwargs ) <EOL> @ classmethod <EOL> def _create ( cls , target_class , * args , ** kwargs ) : <EOL> obj = target_class ( * args , ** kwargs ) <EOL> cached_values = { } <EOL> for field in obj . _translated_field_names : <EOL> if field in [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> continue <EOL> cached_values [ field ] = getattr ( obj , field ) <EOL> obj . translate ( obj . language_code ) <EOL> for field in obj . _translated_field_names : <EOL> if field in [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> continue <EOL> setattr ( obj , field , cached_values [ field ] ) <EOL> obj . save ( ) <EOL> return obj <EOL> class UploadedImageFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , ** kwargs ) : <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return cls . _create_image ( ** kwargs ) <EOL> @ classmethod <EOL> def _create_image ( self , image_format = '<STR_LIT>' , filename = '<STR_LIT>' ) : <EOL> thumb = Image . new ( '<STR_LIT>' , ( <NUM_LIT:100> , <NUM_LIT:100> ) , '<STR_LIT>' ) <EOL> thumb_io = BytesIO ( ) <EOL> thumb . save ( thumb_io , format = image_format ) <EOL> self . _image = SimpleUploadedFile ( filename , thumb_io . getvalue ( ) ) <EOL> return self . _image <EOL> class UserFactory ( factory . DjangoModelFactory ) : <EOL> """<STR_LIT>""" <EOL> username = factory . Sequence ( <EOL> lambda n : md5 ( str ( n ) . encode ( '<STR_LIT:utf-8>' ) ) . hexdigest ( ) [ <NUM_LIT:0> : <NUM_LIT:30> ] <EOL> ) <EOL> email = factory . Sequence ( lambda n : '<STR_LIT>' . format ( n ) ) <EOL> class Meta : <EOL> model = User <EOL> def __new__ ( cls , ** kwargs ) : <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return super ( UserFactory , cls ) . __new__ ( ** kwargs ) <EOL> @ classmethod <EOL> def _prepare ( cls , create , ** kwargs ) : <EOL> password = '<STR_LIT>' <EOL> if '<STR_LIT:password>' in kwargs : <EOL> password = kwargs . pop ( '<STR_LIT:password>' ) <EOL> user = super ( UserFactory , cls ) . _prepare ( create , ** kwargs ) <EOL> user . set_password ( password ) <EOL> if create : <EOL> user . save ( ) <EOL> return user <EOL> class SiteFactory ( factory . DjangoModelFactory ) : <EOL> """<STR_LIT>""" <EOL> name = factory . Sequence ( lambda n : '<STR_LIT>' . format ( n ) ) <EOL> domain = factory . Sequence ( lambda n : '<STR_LIT>' . format ( n ) ) <EOL> class Meta : <EOL> model = Site <EOL> def __new__ ( cls , ** kwargs ) : <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return super ( SiteFactory , cls ) . __new__ ( ** kwargs ) <EOL> try : <EOL> from mailer . models import MessageLog <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> class MessageLogFactory ( factory . DjangoModelFactory ) : <EOL> """<STR_LIT>""" <EOL> message_data = '<STR_LIT:foo>' <EOL> when_added = factory . Sequence ( lambda n : now ( ) ) <EOL> priority = '<STR_LIT:3>' <EOL> result = '<STR_LIT:1>' <EOL> log_message = '<STR_LIT:foo>' <EOL> class Meta : <EOL> model = MessageLog <EOL> def __new__ ( cls , ** kwargs ) : <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> return super ( MessageLogFactory , cls ) . __new__ ( ** kwargs ) </s>
