Esempio n. 1
0
 def test_getBuildChanges(self):
     self.teamcity.session.send.side_effect = [
         test.mocks.teamcity.Response(json.dumps({
             'change': [{
                 'id': '1234',
             }],
         })),
         test.mocks.teamcity.Response(json.dumps({
             'username': '******',
             'user': {
                 'name': 'Author Name',
             },
         })),
     ]
     output = self.teamcity.getBuildChanges('2345')
     self.assertEqual(output[0]['username'], '*****@*****.**')
     self.assertEqual(output[0]['user']['name'], 'Author Name')
     calls = [mock.call(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/changes",
             {
                 "locator": "build:(id:2345)",
                 "fields": "change(id)",
             }
         )
     })), mock.call(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url("app/rest/changes/1234")
     }))]
     self.teamcity.session.send.assert_has_calls(calls, any_order=False)
Esempio n. 2
0
    def test_getLatestBuildAndTestFailures(self):
        self.teamcity.session.send.side_effect = [
            test.mocks.teamcity.Response(json.dumps({
                'problemOccurrence': [{
                    'id': 'id:2500,build:(id:1000)',
                    'details': 'build-details',
                    'build': {
                        'buildTypeId': 'build1',
                    },
                }, {
                    'id': 'id:2501,build:(id:1001)',
                    'details': 'build-details',
                    'build': {
                        'buildTypeId': 'build2',
                    },
                }],
            })),
            test.mocks.teamcity.Response(json.dumps({
                'testOccurrence': [{
                    'id': 'id:2501,build:(id:1001)',
                    'details': 'test-details',
                    'build': {
                        'buildTypeId': 'build2',
                    },
                }, {
                    'id': 'id:2502,build:(id:1002)',
                    'details': 'test-details',
                    'build': {
                        'buildTypeId': 'build3',
                    },
                }],
            })),
        ]

        (buildFailures, testFailures) = self.teamcity.getLatestBuildAndTestFailures(
            'BitcoinABC_Master')
        self.assertEqual(len(buildFailures), 2)
        self.assertEqual(len(testFailures), 2)

        teamcityCalls = [mock.call(AnyWith(requests.PreparedRequest, {
            'url': self.teamcity.build_url(
                "app/rest/problemOccurrences",
                {
                    "locator": "currentlyFailing:true,affectedProject:(id:BitcoinABC_Master)",
                    "fields": "problemOccurrence(*)",
                }
            )
        })), mock.call(AnyWith(requests.PreparedRequest, {
            'url': self.teamcity.build_url(
                "app/rest/testOccurrences",
                {
                    "locator": "currentlyFailing:true,affectedProject:(id:BitcoinABC_Master)",
                    "fields": "testOccurrence(*)",
                }
            )
        }))]
        self.teamcity.session.send.assert_has_calls(
            teamcityCalls, any_order=False)
Esempio n. 3
0
 def test_getBuildInfo(self):
     self.teamcity.session.send.return_value = test.mocks.teamcity.buildInfo(
         properties=test.mocks.teamcity.buildInfo_properties([{
             'name': 'env.ABC_BUILD_NAME',
             'value': 'build-diff',
         }]),
         changes=test.mocks.teamcity.buildInfo_changes(
             ['101298f9325ddbac7e5a8f405e5e2f24a64e5171']),
     )
     buildInfo = self.teamcity.getBuildInfo('1234')
     self.assertEqual(buildInfo['triggered']['type'], 'vcs')
     self.assertEqual(buildInfo.getProperties().get(
         'env.ABC_BUILD_NAME'), 'build-diff')
     self.assertEqual(
         buildInfo.getCommits()[0],
         '101298f9325ddbac7e5a8f405e5e2f24a64e5171')
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/builds",
             {
                 "locator": "id:1234",
                 "fields": "build(*,changes(*),properties(*),triggered(*))",
             }
         )
     }))
Esempio n. 4
0
 def test_triggerBuild(self):
     triggerBuildResponse = test.mocks.teamcity.buildInfo(
         test.mocks.teamcity.buildInfo_changes(['test-change']))
     self.teamcity.session.send.return_value = triggerBuildResponse
     output = self.teamcity.trigger_build('1234', 'branch-name', 'test-phid', [{
         'name': 'another-property',
         'value': 'some value',
     }])
     self.assertEqual(output, json.loads(triggerBuildResponse.content))
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url("app/rest/buildQueue"),
         'body': json.dumps({
             'branchName': 'branch-name',
             'buildType': {
                 'id': '1234',
             },
             'properties': {
                 'property': [{
                     'name': 'another-property',
                     'value': 'some value',
                 }, {
                     'name': 'env.harborMasterTargetPHID',
                     'value': 'test-phid',
                 }],
             },
         }),
     }))
Esempio n. 5
0
 def test_getFailedTests_hasTestFailures(self):
     failures = [{
         'id': 'id:2500,build:(id:12345)',
         'details': 'stacktrace',
         'name': 'test name',
     }]
     self.teamcity.session.send.return_value.content = json.dumps({
         'testOccurrence': failures,
     })
     output = self.teamcity.getFailedTests('1234')
     self.assertEqual(output[0]['id'], failures[0]['id'])
     self.assertEqual(output[0]['details'], failures[0]['details'])
     self.assertEqual(output[0]['name'], failures[0]['name'])
     self.assertEqual(output[0]['logUrl'], self.teamcity.build_url(
         "viewLog.html",
         {
             "tab": "buildLog",
             "logTab": "tree",
             "filter": "debug",
             "expand": "all",
             "buildId": 1234,
             "_focus": 2500,
         }
     ))
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/testOccurrences",
             {
                 "locator": "build:(id:1234),status:FAILURE",
                 "fields": "testOccurrence(id,details,name)",
             }
         )
     }))
Esempio n. 6
0
 def test_getBuildProblems_hasProblems(self):
     problems = [{
         'id': 'id:2500,build:(id:12345)',
         'details': 'test-details',
     }]
     self.teamcity.session.send.return_value.content = json.dumps({
         'problemOccurrence': problems,
     })
     output = self.teamcity.getBuildProblems('1234')
     self.assertEqual(output[0]['id'], problems[0]['id'])
     self.assertEqual(output[0]['details'], problems[0]['details'])
     self.assertEqual(output[0]['logUrl'], self.teamcity.build_url(
         "viewLog.html",
         {
             "tab": "buildLog",
             "logTab": "tree",
             "filter": "debug",
             "expand": "all",
             "buildId": 1234,
         },
         "footer"
     ))
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/problemOccurrences",
             {
                 "locator": "build:(id:1234)",
                 "fields": "problemOccurrence(id,details)",
             }
         )
     }))
Esempio n. 7
0
 def test_build_withAbcBuildName(self):
     data = buildRequestQuery()
     data.abcBuildName = 'build-diff'
     triggerBuildResponse = test.mocks.teamcity.buildInfo(
         test.mocks.teamcity.buildInfo_changes(
             ['test-change']), buildqueue=True)
     self.teamcity.session.send.return_value = triggerBuildResponse
     response = self.app.post('/build{}'.format(data), headers=self.headers)
     assert response.status_code == 200
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': 'https://teamcity.test/app/rest/buildQueue',
         'body': json.dumps({
             'branchName': 'refs/heads/master',
             'buildType': {
                 'id': 'test-build-type-id',
             },
             'properties': {
                 'property': [{
                     'name': 'env.ABC_BUILD_NAME',
                     'value': 'build-diff',
                 }, {
                     'name': 'env.harborMasterTargetPHID',
                     'value': 'buildPHID',
                 }],
             },
         }),
     }))
Esempio n. 8
0
 def test_compareWrongType(self):
     # dict is not a TestObject
     self.assertRaisesRegex(
         AssertionError,
         "Argument class type did not match",
         AnyWith(
             TestObject,
             None).__eq__,
         {})
        def call_buildDiff(expectedBuilds):
            self.teamcity.session.send.side_effect = [
                test.mocks.teamcity.buildInfo(build_id=build.build_id,
                                              buildqueue=True)
                for build in expectedBuilds
            ]

            self.phab.differential.getcommitpaths = mock.Mock()
            self.phab.differential.getcommitpaths.return_value = [
                "dir/subdir/file.h",
                "dir/subdir/file.cpp",
                "someotherdir/file2.txt",
            ]

            response = self.app.post('/buildDiff{}'.format(data),
                                     headers=self.headers)
            self.assertEqual(response.status_code, 200)

            self.phab.differential.getcommitpaths.assert_called()
            self.phab.get_file_content_from_master.assert_called()

            expected_calls = [
                call(
                    AnyWith(
                        requests.PreparedRequest, {
                            "url":
                            "https://teamcity.test/app/rest/buildQueue",
                            "body":
                            json.dumps({
                                "branchName": data.stagingRef,
                                "buildType": {
                                    "id": "BitcoinABC_BitcoinAbcStaging",
                                },
                                'properties': {
                                    'property': [
                                        {
                                            'name': 'env.ABC_BUILD_NAME',
                                            'value': build.name,
                                        },
                                        {
                                            'name': 'env.ABC_REVISION',
                                            'value': data.revisionId,
                                        },
                                        {
                                            'name':
                                            'env.harborMasterTargetPHID',
                                            'value': data.targetPHID,
                                        },
                                    ],
                                },
                            }),
                        })) for build in expectedBuilds
            ]
            self.teamcity.session.send.assert_has_calls(expected_calls,
                                                        any_order=True)
            self.teamcity.session.send.reset_mock()
Esempio n. 10
0
 def call_getLastCompletedBuild():
     output = self.teamcity.getLatestCompletedBuild('1234')
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/builds",
             {
                 "locator": "buildType:1234",
                 "fields": "build(id)",
                 "count": 1,
             }
         )
     }))
     return output
Esempio n. 11
0
 def test_getFailedTests_noTestFailures(self):
     self.teamcity.session.send.return_value.content = json.dumps({})
     output = self.teamcity.getFailedTests('1234')
     self.assertListEqual(output, [])
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/testOccurrences",
             {
                 "locator": "build:(id:1234),status:FAILURE",
                 "fields": "testOccurrence(id,details,name)",
             }
         )
     }))
Esempio n. 12
0
 def test_getBuildProblems_noProblems(self):
     self.teamcity.session.send.return_value.content = json.dumps({})
     output = self.teamcity.getBuildProblems('1234')
     self.assertListEqual(output, [])
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/problemOccurrences",
             {
                 "locator": "build:(id:1234)",
                 "fields": "problemOccurrence(id,details)",
             }
         )
     }))
Esempio n. 13
0
 def test_getBuildChangeDetails(self):
     expectedOutput = {
         'username': '******',
         'user': {
             'name': 'Author Name',
         },
     }
     self.teamcity.session.send.return_value.content = json.dumps(
         expectedOutput)
     output = self.teamcity.getBuildChangeDetails('1234')
     self.assertEqual(output, expectedOutput)
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url("app/rest/changes/1234")
     }))
Esempio n. 14
0
 def test_getBuildInfo_noInfo(self):
     self.teamcity.session.send.return_value = test.mocks.teamcity.Response(
         json.dumps({}))
     buildInfo = self.teamcity.getBuildInfo('1234')
     self.assertIsNone(buildInfo.get('triggered', None))
     self.assertIsNone(buildInfo.getProperties())
     self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
         'url': self.teamcity.build_url(
             "app/rest/builds",
             {
                 "locator": "id:1234",
                 "fields": "build(*,changes(*),properties(*),triggered(*))",
             }
         )
     }))
Esempio n. 15
0
 def test_land_diff(self):
     data = landDiffRequestData()
     triggerBuildResponse = test.mocks.teamcity.buildInfo(
         test.mocks.teamcity.buildInfo_changes(['test-change']))
     self.teamcity.session.send.return_value = triggerBuildResponse
     response = self.app.post('/land', headers=self.headers, json=data)
     self.teamcity.session.send.assert_called_with(
         AnyWith(
             requests.PreparedRequest, {
                 'url':
                 'https://teamcity.test/app/rest/buildQueue',
                 'body':
                 json.dumps({
                     'branchName': 'master',
                     'buildType': {
                         'id': 'BitcoinAbcLandBot',
                     },
                     'properties': {
                         'property': [{
                             'name':
                             'env.ABC_CONDUIT_TOKEN',
                             'value':
                             'U2FsdGVkX1/RI0AAAAAAAF46wjo3lSAxj1d1iqqkxks=',
                         }, {
                             'name': 'env.ABC_COMMITTER_NAME',
                             'value': 'User Name',
                         }, {
                             'name': 'env.ABC_COMMITTER_EMAIL',
                             'value': '*****@*****.**',
                         }, {
                             'name': 'env.ABC_DIFF',
                             'value': '12345',
                         }, {
                             'name': 'env.ABC_COMMIT_MESSAGE',
                             'value': '[Test] Commit message',
                         }, {
                             'name': 'env.harborMasterTargetPHID',
                             'value': 'UNRESOLVED',
                         }],
                     },
                 }),
             }))
     assert response.status_code == 200
     assert response.get_json() == json.loads(triggerBuildResponse.content)
        def call_buildDiff(builds):
            self.teamcity.session.send.side_effect = [
                test.mocks.teamcity.buildInfo(build_id=build.build_id, buildqueue=True) for build in builds
            ]

            response = self.app.post(
                '/buildDiff{}'.format(data),
                headers=self.headers)
            assert response.status_code == 200

            self.phab.get_file_content_from_master.assert_called()

            expected_calls = [
                call(AnyWith(requests.PreparedRequest, {
                    "url": "https://teamcity.test/app/rest/buildQueue",
                    "body": json.dumps({
                        "branchName": data.stagingRef,
                        "buildType": {
                            "id": "BitcoinABC_BitcoinAbcStaging",
                        },
                        'properties': {
                            'property': [
                                {
                                    'name': 'env.ABC_BUILD_NAME',
                                    'value': build.name,
                                },
                                {
                                    'name': 'env.harborMasterTargetPHID',
                                    'value': data.targetPHID,
                                },
                            ],
                        },
                    }),
                }))
                for build in builds
            ]
            self.teamcity.session.send.assert_has_calls(
                expected_calls, any_order=True)
            self.teamcity.session.send.reset_mock()
Esempio n. 17
0
def TestAnyWith(expected):
    aw = AnyWith(TestObject, expected)
    return aw.__eq__(TestObject())
Esempio n. 18
0
    def test_getNumAggregateFailuresSince(self):
        self.teamcity.setMockTime(1590000000)

        self.teamcity.session.send.return_value.content = json.dumps({
            'build': [],
        })
        self.assertEqual(
            self.teamcity.getNumAggregateFailuresSince(
                'buildType', 0), 0)

        self.teamcity.session.send.return_value.content = json.dumps({
            'build': [
                {'status': 'SUCCESS'},
                {'status': 'SUCCESS'},
                {'status': 'SUCCESS'},
            ],
        })
        self.assertEqual(
            self.teamcity.getNumAggregateFailuresSince(
                'buildType', 0), 0)

        self.teamcity.session.send.return_value.content = json.dumps({
            'build': [{'status': 'FAILURE'}],
        })
        self.assertEqual(
            self.teamcity.getNumAggregateFailuresSince(
                'buildType', 0), 1)

        self.teamcity.session.send.return_value.content = json.dumps({
            'build': [
                {'status': 'FAILURE'},
                {'status': 'FAILURE'},
                {'status': 'FAILURE'},
            ]
        })
        self.assertEqual(
            self.teamcity.getNumAggregateFailuresSince(
                'buildType', 0), 1)

        self.teamcity.session.send.return_value.content = json.dumps({
            'build': [
                {'status': 'FAILURE'},
                {'status': 'FAILURE'},
                {'status': 'SUCCESS'},
                {'status': 'FAILURE'},
            ]
        })
        self.assertEqual(
            self.teamcity.getNumAggregateFailuresSince(
                'buildType', 0), 2)

        self.teamcity.session.send.return_value.content = json.dumps({
            'build': [
                {'status': 'SUCCESS'},
                {'status': 'FAILURE'},
                {'status': 'FAILURE'},
                {'status': 'SUCCESS'},
                {'status': 'FAILURE'},
                {'status': 'FAILURE'},
                {'status': 'FAILURE'},
                {'status': 'SUCCESS'},
                {'status': 'FAILURE'},
                {'status': 'SUCCESS'},
            ]
        })
        self.assertEqual(
            self.teamcity.getNumAggregateFailuresSince(
                'buildType', 10000000), 3)

        self.teamcity.session.send.assert_called_with(AnyWith(requests.PreparedRequest, {
            'url': self.teamcity.build_url(
                "app/rest/builds",
                {
                    "locator": "buildType:{},sinceDate:{}".format('buildType',
                                                                  self.teamcity.formatTime(1580000000)),
                    "fields": "build",
                }
            )
        }))