def test_repo_build_list_mine_without_match(client, default_login, default_repo, default_repo_access): revision = factories.RevisionFactory(repository=default_repo) source = factories.SourceFactory(revision=revision) factories.BuildFactory(source=source) resp = client.get("/api/repos/{}/builds?show=mine".format( default_repo.get_full_name())) assert resp.status_code == 200 data = resp.json() assert len(data) == 0
def test_user_build_list(client, default_login, default_repo, default_build, default_repo_access, default_revision): author = factories.AuthorFactory( repository=default_repo, email=default_login.email, ) source = factories.SourceFactory( revision=default_revision, author=author, ) build = factories.BuildFactory( repository=default_repo, source=source, ) resp = client.get('/api/users/me/builds'.format(default_repo.name)) assert resp.status_code == 200 data = resp.json() # default_build should not be present due to author email assert len(data) == 1 assert data[0]['id'] == str(build.id)
def test_simple( client, db_session, default_login, default_repo, default_repo_access, default_revision, ): source = factories.SourceFactory(revision=default_revision) # finished build build = factories.BuildFactory(source=source, passed=True) db_session.add(build) # an unfinished build which shouldn't be used factories.BuildFactory(source=source, status=Status.in_progress) db_session.add(build) # a couple of needed jobs that split the tests job1 = factories.JobFactory(build=build, status=Status.finished, result=Result.passed) db_session.add(job1) job2 = factories.JobFactory(build=build, status=Status.finished, result=Result.passed) db_session.add(job2) # and finally our testcases test1 = factories.TestCaseFactory(job=job1, name="foo.bar", duration=50) db_session.add(test1) test2 = factories.TestCaseFactory(job=job1, name="foo.baz", duration=70) db_session.add(test2) test3 = factories.TestCaseFactory(job=job2, name="blah.blah", duration=10) db_session.add(test3) db_session.commit() path = "/api/repos/{}/test-tree".format(default_repo.get_full_name()) resp = client.get(path) assert resp.status_code == 200 data = resp.json() assert len(data["entries"]) == 2 assert data["entries"][0]["name"] == "foo" assert data["entries"][0]["path"] == "foo" assert data["entries"][0]["numTests"] == 2 assert data["entries"][0]["totalDuration"] == 120 assert data["entries"][1]["name"] == "blah.blah" assert data["entries"][1]["path"] == "blah.blah" assert data["entries"][1]["numTests"] == 1 assert data["entries"][1]["totalDuration"] == 10 assert len(data["trail"]) == 0 resp = client.get("{}?parent=foo".format(path)) assert resp.status_code == 200 data = resp.json() assert len(data["entries"]) == 2 assert data["entries"][0]["name"] == "baz" assert data["entries"][0]["path"] == "foo.baz" assert data["entries"][0]["numTests"] == 1 assert data["entries"][0]["totalDuration"] == 70 assert data["entries"][1]["name"] == "bar" assert data["entries"][1]["path"] == "foo.bar" assert data["entries"][1]["numTests"] == 1 assert data["entries"][1]["totalDuration"] == 50 assert len(data["trail"]) == 1 assert data["trail"][0] == {"name": "foo", "path": "foo"}
def default_source(default_revision, default_patch): return factories.SourceFactory( revision=default_revision, patch=default_patch, )
def test_simple( client, db_session, default_login, default_repo, default_repo_access, default_revision, ): source = factories.SourceFactory(revision=default_revision) # finished build build = factories.BuildFactory(source=source, passed=True) db_session.add(build) # an unfinished build which shouldn't be used factories.BuildFactory(source=source) db_session.add(build) coverage1 = factories.FileCoverageFactory( build=build, filename="foo/bar.py", lines_covered=50, lines_uncovered=100 ) db_session.add(coverage1) coverage2 = factories.FileCoverageFactory( build=build, filename="foo/baz.py", lines_covered=20, lines_uncovered=20 ) db_session.add(coverage2) coverage3 = factories.FileCoverageFactory( build=build, filename="blah/blah.py", lines_covered=5, lines_uncovered=0 ) db_session.add(coverage3) db_session.commit() path = "/api/repos/{}/builds/{}/file-coverage-tree".format( default_repo.get_full_name(), build.number ) resp = client.get(path) assert resp.status_code == 200 data = resp.json() assert len(data["entries"]) == 2 assert data["entries"][0]["name"] == "blah/blah.py" assert data["entries"][0]["path"] == "blah/blah.py" assert data["entries"][0]["lines_covered"] == 5 assert data["entries"][0]["lines_uncovered"] == 0 assert data["entries"][1]["name"] == "foo" assert data["entries"][1]["path"] == "foo" assert data["entries"][1]["lines_covered"] == 70 assert data["entries"][1]["lines_uncovered"] == 120 assert len(data["trail"]) == 0 resp = client.get("{}?parent=foo".format(path)) assert resp.status_code == 200 data = resp.json() assert len(data["entries"]) == 2 assert data["entries"][0]["name"] == "bar.py" assert data["entries"][0]["path"] == "foo/bar.py" assert data["entries"][0]["lines_covered"] == 50 assert data["entries"][0]["lines_uncovered"] == 100 assert data["entries"][1]["name"] == "baz.py" assert data["entries"][1]["path"] == "foo/baz.py" assert data["entries"][1]["lines_covered"] == 20 assert data["entries"][1]["lines_uncovered"] == 20 assert len(data["trail"]) == 1 assert data["trail"][0] == {"name": "foo", "path": "foo"}
def test_simple( client, db_session, default_login, default_repo, default_repo_access, default_revision ): source = factories.SourceFactory( revision=default_revision, ) # finished build build = factories.BuildFactory( source=source, passed=True, ) db_session.add(build) # an unfinished build which shouldn't be used factories.BuildFactory( source=source, status=Status.in_progress, ) db_session.add(build) # a couple of needed jobs that split the tests job1 = factories.JobFactory( build=build, status=Status.finished, result=Result.passed, ) db_session.add(job1) job2 = factories.JobFactory( build=build, status=Status.finished, result=Result.passed, ) db_session.add(job2) # and finally our testcases test1 = factories.TestCaseFactory( job=job1, name='foo.bar', duration=50, ) db_session.add(test1) test2 = factories.TestCaseFactory( job=job1, name='foo.baz', duration=70, ) db_session.add(test2) test3 = factories.TestCaseFactory( job=job2, name='blah.blah', duration=10, ) db_session.add(test3) db_session.commit() path = '/api/repos/{}/{}/test-tree'.format(default_repo.owner_name, default_repo.name) resp = client.get(path) assert resp.status_code == 200 data = resp.json() assert len(data['entries']) == 2 assert data['entries'][0]['name'] == 'foo' assert data['entries'][0]['path'] == 'foo' assert data['entries'][0]['numTests'] == 2 assert data['entries'][0]['totalDuration'] == 120 assert data['entries'][1]['name'] == 'blah.blah' assert data['entries'][1]['path'] == 'blah.blah' assert data['entries'][1]['numTests'] == 1 assert data['entries'][1]['totalDuration'] == 10 assert len(data['trail']) == 0 resp = client.get('{}?parent=foo'.format(path)) assert resp.status_code == 200 data = resp.json() assert len(data['entries']) == 2 assert data['entries'][0]['name'] == 'baz' assert data['entries'][0]['path'] == 'foo.baz' assert data['entries'][0]['numTests'] == 1 assert data['entries'][0]['totalDuration'] == 70 assert data['entries'][1]['name'] == 'bar' assert data['entries'][1]['path'] == 'foo.bar' assert data['entries'][1]['numTests'] == 1 assert data['entries'][1]['totalDuration'] == 50 assert len(data['trail']) == 1 assert data['trail'][0] == { 'name': 'foo', 'path': 'foo', }
def test_simple(client, db_session, default_login, default_repo, default_repo_access, default_revision): source = factories.SourceFactory(revision=default_revision, ) # finished build build = factories.BuildFactory( source=source, passed=True, ) db_session.add(build) # an unfinished build which shouldn't be used factories.BuildFactory(source=source, ) db_session.add(build) coverage1 = factories.FileCoverageFactory( build=build, filename='foo/bar.py', lines_covered=50, lines_uncovered=100, ) db_session.add(coverage1) coverage2 = factories.FileCoverageFactory( build=build, filename='foo/baz.py', lines_covered=20, lines_uncovered=20, ) db_session.add(coverage2) coverage3 = factories.FileCoverageFactory( build=build, filename='blah/blah.py', lines_covered=5, lines_uncovered=0, ) db_session.add(coverage3) db_session.commit() path = '/api/repos/{}/builds/{}/file-coverage-tree'.format( default_repo.get_full_name(), build.number, ) resp = client.get(path) assert resp.status_code == 200 data = resp.json() assert len(data['entries']) == 2 assert data['entries'][0]['name'] == 'blah/blah.py' assert data['entries'][0]['path'] == 'blah/blah.py' assert data['entries'][0]['lines_covered'] == 5 assert data['entries'][0]['lines_uncovered'] == 0 assert data['entries'][1]['name'] == 'foo' assert data['entries'][1]['path'] == 'foo' assert data['entries'][1]['lines_covered'] == 70 assert data['entries'][1]['lines_uncovered'] == 120 assert len(data['trail']) == 0 resp = client.get('{}?parent=foo'.format(path)) assert resp.status_code == 200 data = resp.json() assert len(data['entries']) == 2 assert data['entries'][0]['name'] == 'bar.py' assert data['entries'][0]['path'] == 'foo/bar.py' assert data['entries'][0]['lines_covered'] == 50 assert data['entries'][0]['lines_uncovered'] == 100 assert data['entries'][1]['name'] == 'baz.py' assert data['entries'][1]['path'] == 'foo/baz.py' assert data['entries'][1]['lines_covered'] == 20 assert data['entries'][1]['lines_uncovered'] == 20 assert len(data['trail']) == 1 assert data['trail'][0] == { 'name': 'foo', 'path': 'foo', }
def test_failure_origin(default_repo): auth.set_current_tenant( auth.Tenant(access={default_repo.id: Permission.read})) new_revision = factories.RevisionFactory(repository=default_repo) new_source = factories.SourceFactory(revision=new_revision) new_build = factories.BuildFactory(source=new_source, failed=True) new_job = factories.JobFactory(build=new_build, failed=True) new_testcase = factories.TestCaseFactory(job=new_job, failed=True) new_testcase2 = factories.TestCaseFactory(job=new_job, passed=True) old_revision = factories.RevisionFactory( repository=default_repo, date_created=new_revision.date_created - timedelta(hours=1), ) old_source = factories.SourceFactory(revision=old_revision, date_created=new_source.date_created - timedelta(hours=1)) old_build = factories.BuildFactory( source=old_source, failed=True, date_created=new_build.date_created - timedelta(hours=1), ) old_job = factories.JobFactory( build=old_build, failed=True, date_created=new_job.date_created - timedelta(hours=1), ) factories.TestCaseFactory(job=old_job, failed=True, name=new_testcase.name) oldold_revision = factories.RevisionFactory( repository=default_repo, date_created=old_revision.date_created - timedelta(hours=1), ) oldold_source = factories.SourceFactory( revision=oldold_revision, date_created=old_source.date_created - timedelta(hours=1), ) factories.BuildFactory( source=oldold_source, passed=True, date_created=old_build.date_created - timedelta(hours=1), ) schema = AggregateTestCaseSummarySchema(many=True, strict=True, context={"build": new_build}) result = schema.dump([ AggregateTestCase( hash=new_testcase.hash, name=new_testcase.name, runs=[[ str(new_testcase.id), str(new_testcase.job_id), new_testcase.duration, int(new_testcase.result), ]], ), AggregateTestCase( hash=new_testcase2.hash, name=new_testcase2.name, runs=[[ str(new_testcase2.id), str(new_testcase2.job_id), new_testcase2.duration, int(new_testcase2.result), ]], ), ]).data assert len(result) == 2 assert result[0]["hash"] == new_testcase.hash assert result[0]["name"] == new_testcase.name assert result[0]["origin_build"]["id"] == str(old_build.id) assert result[1]["hash"] == new_testcase2.hash assert result[1]["name"] == new_testcase2.name assert result[1]["origin_build"] is None
def default_source(default_revision): return factories.SourceFactory(revision=default_revision)