<s> from __future__ import absolute_import <EOL> from changes . models . latest_green_build import LatestGreenBuild <EOL> from base64 import b64encode <EOL> from loremipsum import get_paragraphs , get_sentences <EOL> from uuid import uuid4 <EOL> from changes . config import db <EOL> from changes . models . build import Build <EOL> from changes . models import ( <EOL> Repository , Job , JobPlan , Project , Revision , Change , Author , <EOL> Patch , Plan , Step , Source , Node , JobPhase , JobStep , Task , <EOL> Artifact , TestCase , LogChunk , LogSource , Cluster , ClusterNode , <EOL> RepositoryStatus , User , ItemOption , ItemStat , Command , Snapshot , SnapshotImage , <EOL> CachedSnapshotImage , PlanStatus , AdminMessage , PhabricatorDiff , ProjectOption <EOL> ) <EOL> from changes . utils . slugs import slugify <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> SAMPLE_COVERAGE = """<STR_LIT>""" <EOL> with open ( '<STR_LIT>' , '<STR_LIT:rb>' ) as f : <EOL> SAMPLE_DIFF_BYTES = f . read ( ) <EOL> SAMPLE_DIFF = SAMPLE_DIFF_BYTES . decode ( '<STR_LIT:utf-8>' ) <EOL> SAMPLE_XUNIT = """<STR_LIT>""" <EOL> SAMPLE_XUNIT_DOUBLE_CASES = """<STR_LIT>""" <EOL> SAMPLE_XUNIT_TESTARTIFACTS = """<STR_LIT>""" % b64encode ( '<STR_LIT>' ) <EOL> class Fixtures ( object ) : <EOL> def create_repo ( self , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:url>' , '<STR_LIT>' . format ( uuid4 ( ) . hex ) ) <EOL> kwargs . setdefault ( '<STR_LIT:status>' , RepositoryStatus . active ) <EOL> repo = Repository ( ** kwargs ) <EOL> db . session . add ( repo ) <EOL> db . session . commit ( ) <EOL> return repo <EOL> def create_node ( self , cluster = None , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:label>' , uuid4 ( ) . hex ) <EOL> node = Node ( ** kwargs ) <EOL> db . session . add ( node ) <EOL> if cluster : <EOL> db . session . add ( ClusterNode ( cluster = cluster , node = node ) ) <EOL> db . session . commit ( ) <EOL> return node <EOL> def create_cluster ( self , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:label>' , uuid4 ( ) . hex ) <EOL> cluster = Cluster ( ** kwargs ) <EOL> db . session . add ( cluster ) <EOL> db . session . commit ( ) <EOL> return cluster <EOL> def create_project ( self , ** kwargs ) : <EOL> if not kwargs . get ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = self . create_repo ( ) <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] . id <EOL> kwargs . setdefault ( '<STR_LIT:name>' , uuid4 ( ) . hex ) <EOL> kwargs . setdefault ( '<STR_LIT>' , kwargs [ '<STR_LIT:name>' ] ) <EOL> project = Project ( ** kwargs ) <EOL> db . session . add ( project ) <EOL> db . session . commit ( ) <EOL> return project <EOL> def create_change ( self , project , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:label>' , '<STR_LIT>' ) <EOL> change = Change ( <EOL> hash = uuid4 ( ) . hex , <EOL> repository = project . repository , <EOL> project = project , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( change ) <EOL> db . session . commit ( ) <EOL> return change <EOL> def create_test ( self , job , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:name>' , uuid4 ( ) . hex ) <EOL> case = TestCase ( <EOL> job = job , <EOL> project = job . project , <EOL> project_id = job . project_id , <EOL> job_id = job . id , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( case ) <EOL> db . session . commit ( ) <EOL> return case <EOL> def create_job ( self , build , ** kwargs ) : <EOL> project = build . project <EOL> kwargs . setdefault ( '<STR_LIT:label>' , build . label ) <EOL> kwargs . setdefault ( '<STR_LIT:status>' , build . status ) <EOL> kwargs . setdefault ( '<STR_LIT:result>' , build . result ) <EOL> kwargs . setdefault ( '<STR_LIT>' , build . duration ) <EOL> kwargs . setdefault ( '<STR_LIT>' , build . date_started ) <EOL> kwargs . setdefault ( '<STR_LIT>' , build . date_finished ) <EOL> kwargs . setdefault ( '<STR_LIT:source>' , build . source ) <EOL> if kwargs . get ( '<STR_LIT>' , False ) is False : <EOL> kwargs [ '<STR_LIT>' ] = self . create_change ( project ) <EOL> job = Job ( <EOL> build = build , <EOL> build_id = build . id , <EOL> project = project , <EOL> project_id = project . id , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( job ) <EOL> db . session . commit ( ) <EOL> return job <EOL> def create_job_plan ( self , job , plan , snapshot_id = None ) : <EOL> jobplan = JobPlan . build_jobplan ( plan , job , snapshot_id = snapshot_id ) <EOL> db . session . add ( jobplan ) <EOL> db . session . commit ( ) <EOL> return jobplan <EOL> def create_source ( self , project , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs : <EOL> revision = self . create_revision ( repository = project . repository ) <EOL> kwargs [ '<STR_LIT>' ] = revision . sha <EOL> if '<STR_LIT:data>' not in kwargs : <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> kwargs [ '<STR_LIT:data>' ] = data <EOL> source = Source ( <EOL> repository_id = project . repository_id , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( source ) <EOL> db . session . commit ( ) <EOL> return source <EOL> def create_diff ( self , diff_id , ** kwargs ) : <EOL> diff = PhabricatorDiff ( <EOL> diff_id = diff_id , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( diff ) <EOL> db . session . commit ( ) <EOL> return diff <EOL> def create_build ( self , project , ** kwargs ) : <EOL> if '<STR_LIT:source>' not in kwargs : <EOL> kwargs [ '<STR_LIT:source>' ] = self . create_source ( project ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = uuid4 ( ) <EOL> if '<STR_LIT:message>' not in kwargs : <EOL> kwargs [ '<STR_LIT:message>' ] = '<STR_LIT>' <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT:source>' ] . id <EOL> kwargs . setdefault ( '<STR_LIT:label>' , '<STR_LIT>' ) <EOL> build = Build ( <EOL> project_id = project . id , <EOL> project = project , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( build ) <EOL> db . session . commit ( ) <EOL> return build <EOL> def create_patch ( self , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , SAMPLE_DIFF ) <EOL> kwargs . setdefault ( '<STR_LIT>' , uuid4 ( ) . hex ) <EOL> if not kwargs . get ( '<STR_LIT>' ) : <EOL> if not kwargs . get ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = self . create_repo ( ) <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] . id <EOL> patch = Patch ( <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( patch ) <EOL> db . session . commit ( ) <EOL> return patch <EOL> def create_revision ( self , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , uuid4 ( ) . hex ) <EOL> if not kwargs . get ( '<STR_LIT>' ) : <EOL> if not kwargs . get ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = self . create_repo ( ) <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] . id <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = self . create_author ( ) <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] . id <EOL> if not kwargs . get ( '<STR_LIT:message>' ) : <EOL> message = get_sentences ( <NUM_LIT:1> ) [ <NUM_LIT:0> ] [ : <NUM_LIT> ] + '<STR_LIT:\n>' <EOL> message += '<STR_LIT>' . join ( get_paragraphs ( <NUM_LIT:2> ) ) <EOL> kwargs [ '<STR_LIT:message>' ] = message <EOL> revision = Revision ( ** kwargs ) <EOL> db . session . add ( revision ) <EOL> db . session . commit ( ) <EOL> return revision <EOL> def create_author ( self , email = None , ** kwargs ) : <EOL> if not kwargs . get ( '<STR_LIT:name>' ) : <EOL> kwargs [ '<STR_LIT:name>' ] = '<STR_LIT:U+0020>' . join ( get_sentences ( <NUM_LIT:1> ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> : <NUM_LIT:2> ] ) <EOL> if not email : <EOL> email = '<STR_LIT>' . format ( <EOL> slugify ( kwargs [ '<STR_LIT:name>' ] ) , uuid4 ( ) . hex ) <EOL> kwargs . setdefault ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> author = Author ( email = email , ** kwargs ) <EOL> db . session . add ( author ) <EOL> db . session . commit ( ) <EOL> return author <EOL> def create_plan ( self , project , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:label>' , '<STR_LIT:test>' ) <EOL> kwargs . setdefault ( '<STR_LIT:status>' , PlanStatus . active ) <EOL> plan = Plan ( project = project , ** kwargs ) <EOL> db . session . add ( plan ) <EOL> db . session . commit ( ) <EOL> return plan <EOL> def create_step ( self , plan , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> step = Step ( plan = plan , ** kwargs ) <EOL> db . session . add ( step ) <EOL> db . session . commit ( ) <EOL> return step <EOL> def create_jobphase ( self , job , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:label>' , '<STR_LIT:test>' ) <EOL> kwargs . setdefault ( '<STR_LIT:result>' , job . result ) <EOL> kwargs . setdefault ( '<STR_LIT:status>' , job . status ) <EOL> phase = JobPhase ( <EOL> job = job , <EOL> project = job . project , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( phase ) <EOL> db . session . commit ( ) <EOL> return phase <EOL> def create_jobstep ( self , phase , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:label>' , phase . label ) <EOL> kwargs . setdefault ( '<STR_LIT:result>' , phase . result ) <EOL> kwargs . setdefault ( '<STR_LIT:status>' , phase . status ) <EOL> step = JobStep ( <EOL> job = phase . job , <EOL> project = phase . project , <EOL> phase = phase , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( step ) <EOL> db . session . commit ( ) <EOL> return step <EOL> def create_command ( self , jobstep , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT:label>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> command = Command ( <EOL> jobstep = jobstep , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( command ) <EOL> db . session . commit ( ) <EOL> return command <EOL> def create_task ( self , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , uuid4 ( ) ) <EOL> task = Task ( ** kwargs ) <EOL> db . session . add ( task ) <EOL> db . session . commit ( ) <EOL> return task <EOL> def create_artifact ( self , step , name , ** kwargs ) : <EOL> artifact = Artifact ( <EOL> step = step , <EOL> project = step . project , <EOL> job = step . job , <EOL> name = name , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( artifact ) <EOL> db . session . commit ( ) <EOL> return artifact <EOL> def create_logsource ( self , step = None , ** kwargs ) : <EOL> if step : <EOL> kwargs [ '<STR_LIT>' ] = step . job <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] . project <EOL> logsource = LogSource ( <EOL> step = step , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( logsource ) <EOL> db . session . commit ( ) <EOL> return logsource <EOL> def create_logchunk ( self , source , text = None , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> kwargs [ '<STR_LIT>' ] = source . job <EOL> kwargs [ '<STR_LIT>' ] = source . project <EOL> if text is None : <EOL> text = '<STR_LIT:\n>' . join ( get_sentences ( <NUM_LIT:4> ) ) <EOL> logchunk = LogChunk ( <EOL> source = source , <EOL> text = text , <EOL> size = len ( text ) , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( logchunk ) <EOL> db . session . commit ( ) <EOL> return logchunk <EOL> def create_user ( self , email , ** kwargs ) : <EOL> user = User ( email = email , ** kwargs ) <EOL> db . session . add ( user ) <EOL> db . session . commit ( ) <EOL> return user <EOL> def create_option ( self , ** kwargs ) : <EOL> option = ItemOption ( ** kwargs ) <EOL> db . session . add ( option ) <EOL> db . session . commit ( ) <EOL> return option <EOL> def create_itemstat ( self , item_id , name , value , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> stat = ItemStat ( item_id = item_id , name = name , value = value , ** kwargs ) <EOL> db . session . add ( stat ) <EOL> db . session . commit ( ) <EOL> return stat <EOL> def create_project_option ( self , project , name , value , ** kwargs ) : <EOL> option = ProjectOption ( project = project , name = name , value = value , ** kwargs ) <EOL> db . session . add ( option ) <EOL> db . session . commit ( ) <EOL> return option <EOL> def create_latest_green_build ( self , ** kwargs ) : <EOL> if not kwargs . get ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = self . create_repo ( ) <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] . id <EOL> latest_green_build = LatestGreenBuild ( ** kwargs ) <EOL> db . session . add ( latest_green_build ) <EOL> db . session . commit ( ) <EOL> return latest_green_build <EOL> def create_snapshot ( self , project , ** kwargs ) : <EOL> snapshot = Snapshot ( <EOL> project_id = project . id , <EOL> project = project , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( snapshot ) <EOL> db . session . commit ( ) <EOL> return snapshot <EOL> def create_snapshot_image ( self , snapshot , plan , ** kwargs ) : <EOL> image = SnapshotImage ( <EOL> snapshot = snapshot , <EOL> plan = plan , <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( image ) <EOL> db . session . commit ( ) <EOL> return image <EOL> def create_cached_snapshot_image ( self , snapshot_image , ** kwargs ) : <EOL> cached_snapshot_image = CachedSnapshotImage ( <EOL> id = snapshot_image . id , <EOL> ** kwargs ) <EOL> db . session . add ( cached_snapshot_image ) <EOL> db . session . commit ( ) <EOL> return cached_snapshot_image <EOL> def create_adminmessage ( self , ** kwargs ) : <EOL> message = AdminMessage ( <EOL> ** kwargs <EOL> ) <EOL> db . session . add ( message ) <EOL> db . session . commit ( ) <EOL> return message </s>
