def get_runs_by_branch(request, project): """ Return the testruns for a project broken down by branches. days_ago: required. Number of days ago for the "start" of the range. numdays: optional. Number of days since days_ago. Will default to "all since days ago" """ if not request.GET.get("days_ago"): return HttpResponse(REQUIRE_DAYS_AGO, status=400) range = get_range(request) show_tr = request.GET.get("show_test_runs") if show_tr and show_tr.lower() == "true": stats = perftest_refdata.get_runs_by_branch( project, range["start"], range["stop"], ) else: stats = perftest_refdata.get_run_counts_by_branch( project, range["start"], range["stop"], ) return HttpResponse(json.dumps(stats), content_type=API_CONTENT_TYPE)
def test_get_runs_by_branch(ptm, plm, monkeypatch): """ Test get_runs_by_branch method. """ def mock_plm(): return plm monkeypatch.setattr(factory, 'get_plm', mock_plm) # don't need to monkeypatch the ptrdm, because we pass the project # name in for use in its construction. blobs = [ perftest_json( testrun={"date": 1330454755}, test_build={"name": "one"}, ), perftest_json( testrun={"date": 1330454756}, test_build={"name": "two"}, ), perftest_json( testrun={"date": 1330454758}, test_build={"name": "three"}, ), ] for blob in blobs: ptm.store_test_data(blob) ptm.process_objects(3) exp_run = { "status": 1, "date_run": 1330454756, "product": "two", "version": "14.0a2", "branch": "Mozilla-Aurora", "revision": "785345035a3b" } runs = perftest_refdata.get_runs_by_branch(ptm.project, 1330454756, 1330454756) assert runs["Mozilla-Aurora"]["count"] == 1 assert runs["Mozilla-Aurora"]["test_runs"][0] == exp_run
def test_get_runs_by_branch_past_limit(ptm, plm, monkeypatch): """ Test get_runs_by_branch method exceeding the 80 count limit. Since the limit per branch is 80, create more than 80 items to test that. """ def mock_plm(): return plm monkeypatch.setattr(factory, 'get_plm', mock_plm) for i in range(81): blob = perftest_json( testrun={"date": 1330454756}, test_build={"name": "testname{0}".format(i)} ) ptm.store_test_data(blob) ptm.process_objects(81) runs = perftest_refdata.get_runs_by_branch(ptm.project, 1330454756, 1330454756) assert runs["Mozilla-Aurora"]["limit"] == 80 assert runs["Mozilla-Aurora"]["count"] == 80 assert runs["Mozilla-Aurora"]["total_count"] == 81