def mock_revision( repo: models.Repository, parent_revision: models.Revision = None, author: models.Author = None, ) -> Tuple[models.Revision, models.Source]: revision = factories.RevisionFactory.create( repository=repo, parents=[parent_revision.sha] if parent_revision else None, **{"author": author} if author else {}) source = factories.SourceFactory.create( revision=revision, patch=factories.PatchFactory(parent_revision=parent_revision) if parent_revision and random() > 0.8 else None, ) return revision, source
def mock_build(repo: models.Repository, parent_revision: models.Revision=None, user_ids=(), file_list=()): if user_ids and randint(0, 1) == 0: chosen_user_id = choice(user_ids) author = mock_author(repo, chosen_user_id) else: author = None revision = factories.RevisionFactory.create( repository=repo, parents=[parent_revision.sha] if parent_revision else None, **{'author': author} if author else {} ) source = factories.SourceFactory.create( revision=revision, patch=factories.PatchFactory( parent_revision=parent_revision, ) if parent_revision and random() > 0.8 else None, ) parent_revision = revision build = factories.BuildFactory.create(source=source, travis=True) result = build_schema.dump(build) publish('builds', 'build.create', result.data) click.echo('Created {!r}'.format(build)) # we need to find some filenames for the repo if file_list is None: file_list = find_files_in_repo(repo) for n in range(randint(0, 50)): try: with db.session.begin_nested(): factories.FileCoverageFactory.create( filename=choice(file_list), build=build, in_diff=randint(0, 5) == 0) except IntegrityError: continue for n in range(1, 4): has_failure = randint(0, 2) == 0 job = factories.JobFactory.create( build=build, failed=has_failure, passed=not has_failure, travis=True, allow_failure=n == 3, ) for n in range(randint(0, 50)): test_failed = has_failure and randint(0, 5) == 0 factories.TestCaseFactory.create( job=job, failed=test_failed, passed=not test_failed, ) if has_failure and randint(0, 2) == 0: for n in range(1, 5): factories.StyleViolationFactory.create( job=job, ) for n in range(randint(0, 2)): bundle = factories.BundleFactory.create( job=job, ) for n in range(randint(0, 4)): factories.BundleAssetFactory.create( bundle=bundle, job=job, ) artifact_count = randrange(3) \ if job.status == Status.finished and job.result == Result.passed \ else 0 for n in range(0, artifact_count): factories.ArtifactFactory.create(job=job, repository=repo) db.session.commit() aggregate_build_stats_for_job(job_id=job.id) result = build_schema.dump(build) publish('builds', 'build.create', result.data) click.echo('Created {!r}'.format(build)) db.session.commit() return build
def default_patch(default_parent_revision): return factories.PatchFactory(parent_revision=default_parent_revision, )