Changeset View
Changeset View
Standalone View
Standalone View
contrib/buildbot/test/test_endpoint_status.py
Show All 19 Lines | |||||
import test.mocks.phabricator | import test.mocks.phabricator | ||||
import test.mocks.teamcity | import test.mocks.teamcity | ||||
from test.mocks.teamcity import DEFAULT_BUILD_ID, TEAMCITY_CI_USER | from test.mocks.teamcity import DEFAULT_BUILD_ID, TEAMCITY_CI_USER | ||||
class statusRequestData(test.mocks.fixture.MockData): | class statusRequestData(test.mocks.fixture.MockData): | ||||
def __init__(self): | def __init__(self): | ||||
self.buildName = 'build-name' | self.buildName = 'build-name' | ||||
self.project = 'bitcoin-abc-test' | self.projectName = 'bitcoin-abc-test' | ||||
self.buildId = DEFAULT_BUILD_ID | self.buildId = DEFAULT_BUILD_ID | ||||
self.buildTypeId = 'build-type-id' | self.buildTypeId = 'build-type-id' | ||||
self.buildResult = 'success' | self.buildResult = 'success' | ||||
self.revision = 'commitHash' | self.revision = 'commitHash' | ||||
self.branch = 'refs/heads/master' | self.branch = 'refs/heads/master' | ||||
self.buildTargetPHID = 'buildTargetPHID' | self.buildTargetPHID = 'buildTargetPHID' | ||||
def __setattr__(self, name, value): | def __setattr__(self, name, value): | ||||
▲ Show 20 Lines • Show All 1,458 Lines • ▼ Show 20 Lines | def test_update_build_status_panel(self): | ||||
build_line('show_me21', status=BuildStatus.Failure) + | build_line('show_me21', status=BuildStatus.Failure) + | ||||
build_line('show_me22') + | build_line('show_me22') + | ||||
build_line('show_me23', status=BuildStatus.Unknown) + | build_line('show_me23', status=BuildStatus.Unknown) + | ||||
'\n' | '\n' | ||||
) | ) | ||||
def test_update_coverage_panel(self): | def test_update_coverage_panel(self): | ||||
panel_id = 21 | panel_id = 21 | ||||
buildTypeId = 'DummyBuildType' | |||||
projectName = 'Dummy Project' | |||||
self.phab.set_text_panel_content = mock.Mock() | self.phab.set_text_panel_content = mock.Mock() | ||||
self.teamcity.get_coverage_summary.return_value = "Dummy" | self.teamcity.get_coverage_summary.return_value = "Dummy" | ||||
def call_status(status, expected_status_code=None): | def call_status(status, expected_status_code=None): | ||||
data = statusRequestData() | data = statusRequestData() | ||||
data.buildResult = status.value | data.buildResult = status.value | ||||
data.buildTypeId = buildTypeId | |||||
data.projectName = projectName | |||||
response = self.app.post( | response = self.app.post( | ||||
'/status', headers=self.headers, json=data) | '/status', headers=self.headers, json=data) | ||||
self.assertEqual( | self.assertEqual( | ||||
response.status_code, | response.status_code, | ||||
200 if not expected_status_code else expected_status_code) | 200 if not expected_status_code else expected_status_code) | ||||
def assert_panel_content(content): | def assert_panel_content(content): | ||||
Show All 19 Lines | def test_update_coverage_panel(self): | ||||
panel_id=panel_id) | panel_id=panel_id) | ||||
# No coverage report artifact: ignore | # No coverage report artifact: ignore | ||||
self.teamcity.get_coverage_summary.return_value = None | self.teamcity.get_coverage_summary.return_value = None | ||||
call_status(BuildStatus.Success, expected_status_code=500) | call_status(BuildStatus.Success, expected_status_code=500) | ||||
self.phab.set_text_panel_content.assert_not_called_with( | self.phab.set_text_panel_content.assert_not_called_with( | ||||
panel_id=panel_id) | panel_id=panel_id) | ||||
# Generate coverage report for one project | |||||
self.teamcity.get_coverage_summary.return_value = \ | self.teamcity.get_coverage_summary.return_value = \ | ||||
""" | """ | ||||
Reading tracefile check-extended_combined.info | Reading tracefile check-extended_combined.info | ||||
Summary coverage rate: | Summary coverage rate: | ||||
lines......: 82.3% (91410 of 111040 lines) | lines......: 82.3% (91410 of 111040 lines) | ||||
functions..: 74.1% (6686 of 9020 functions) | functions..: 74.1% (6686 of 9020 functions) | ||||
branches...: 45.0% (188886 of 420030 branches) | branches...: 45.0% (188886 of 420030 branches) | ||||
""" | """ | ||||
call_status(BuildStatus.Success, expected_status_code=500) | call_status(BuildStatus.Success, expected_status_code=500) | ||||
assert_panel_content( | assert_panel_content( | ||||
"""**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=BitcoinABC_Master_BitcoinAbcMasterCoverage&tab=report__Root_Code_Coverage&guest=1 | HTML coverage report ]]** | """**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=DummyBuildType&tab=report__Root_Code_Coverage&guest=1 | Dummy Project coverage report ]]** | ||||
| Granularity | % hit | # hit | # total | | | Granularity | % hit | # hit | # total | | ||||
| ----------- | ----- | ----- | ------- | | | ----------- | ----- | ----- | ------- | | ||||
| Lines | 82.3% | 91410 | 111040 | | | Lines | 82.3% | 91410 | 111040 | | ||||
| Functions | 74.1% | 6686 | 9020 | | | Functions | 74.1% | 6686 | 9020 | | ||||
| Branches | 45.0% | 188886 | 420030 | | | Branches | 45.0% | 188886 | 420030 | | ||||
""" | """ | ||||
) | ) | ||||
# Generate coverage report for another project | |||||
buildTypeId = 'AnotherBuildType' | |||||
projectName = 'Another Project' | |||||
self.teamcity.get_coverage_summary.return_value = \ | |||||
""" | |||||
Reading tracefile coverage/lcov.info | |||||
Summary coverage rate: | |||||
lines......: 20.0% (261 of 1305 lines) | |||||
functions..: 16.9% (41 of 242 functions) | |||||
branches...: 18.2% (123 of 676 branches) | |||||
""" | |||||
call_status(BuildStatus.Success, expected_status_code=500) | |||||
assert_panel_content( | |||||
"""**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=DummyBuildType&tab=report__Root_Code_Coverage&guest=1 | Dummy Project coverage report ]]** | |||||
| Granularity | % hit | # hit | # total | | |||||
| ----------- | ----- | ----- | ------- | | |||||
| Lines | 82.3% | 91410 | 111040 | | |||||
| Functions | 74.1% | 6686 | 9020 | | |||||
| Branches | 45.0% | 188886 | 420030 | | |||||
**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=AnotherBuildType&tab=report__Root_Code_Coverage&guest=1 | Another Project coverage report ]]** | |||||
| Granularity | % hit | # hit | # total | | |||||
| ----------- | ----- | ----- | ------- | | |||||
| Lines | 20.0% | 261 | 1305 | | |||||
| Functions | 16.9% | 41 | 242 | | |||||
| Branches | 18.2% | 123 | 676 | | |||||
""" | |||||
) | |||||
# Update one of the existing coverage reports | |||||
buildTypeId = 'DummyBuildType' | |||||
projectName = 'Renamed Dummy Project' | |||||
self.teamcity.get_coverage_summary.return_value = \ | |||||
""" | |||||
Reading tracefile check-extended_combined.info | |||||
Summary coverage rate: | |||||
lines......: 82.4% (91411 of 111030 lines) | |||||
functions..: 74.2% (6687 of 9010 functions) | |||||
branches...: 45.1% (188887 of 420020 branches) | |||||
""" | |||||
call_status(BuildStatus.Success, expected_status_code=500) | |||||
assert_panel_content( | |||||
"""**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=DummyBuildType&tab=report__Root_Code_Coverage&guest=1 | Renamed Dummy Project coverage report ]]** | |||||
| Granularity | % hit | # hit | # total | | |||||
| ----------- | ----- | ----- | ------- | | |||||
| Lines | 82.4% | 91411 | 111030 | | |||||
| Functions | 74.2% | 6687 | 9010 | | |||||
| Branches | 45.1% | 188887 | 420020 | | |||||
**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=AnotherBuildType&tab=report__Root_Code_Coverage&guest=1 | Another Project coverage report ]]** | |||||
| Granularity | % hit | # hit | # total | | |||||
| ----------- | ----- | ----- | ------- | | |||||
| Lines | 20.0% | 261 | 1305 | | |||||
| Functions | 16.9% | 41 | 242 | | |||||
| Branches | 18.2% | 123 | 676 | | |||||
""" | |||||
) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
unittest.main() | unittest.main() |