def test_statuses_returns_failed_travis_build(self): statuses = [{ "state": "error", "description": "The Travis CI build failed" }] pr = "/repos/test/blah" class Mocked(API): def __call__(m, method, path, **kwargs): self.assertEqual(pr, path) return statuses api = Mocked("user", "pat") url = "{}{}".format(api.BASE_URL, pr) self.assertFalse(prs.has_build_passed(api, url)) statuses = [{ "state": "pending", "description": "The Travis CI build is in progress" }] pr = "/repos/test/blah" class Mocked(API): def __call__(m, method, path, **kwargs): self.assertEqual(pr, path) return statuses api = Mocked("user", "pat") url = "{}{}".format(api.BASE_URL, pr) self.assertFalse(prs.has_build_passed(api, url))
def test_statuses_returns_failed_travis_build_in_wrong_context(self): test_data = [ [{ "state": "pending", "context": "some_other_context" }], [{ "state": "success", "context": "some_other_context" }], [{ "state": "error", "context": "some_other_other_context" }], ] pr = "/repos/test/blah" for statuses in test_data: class Mocked(API): def __call__(m, method, path, **kwargs): self.assertEqual(pr, path) return statuses api = Mocked("user", "pat") url = "{}{}".format(api.BASE_URL, pr) self.assertFalse(prs.has_build_passed(api, url))
def test_statuses_returns_passed_travis_build(self): test_data = [ [{ "state": "success", "context": "continuous-integration/travis-ci/pr" }], [{ "state": "success", "context": "continuous-integration/travis-ci/pr" }, { "state": "failure", "context": "chaosbot" }], ] pr = "/repos/test/blah" for statuses in test_data: class Mocked(API): def __call__(m, method, path, **kwargs): self.assertEqual(pr, path) return statuses api = Mocked("user", "pat") url = "{}{}".format(api.BASE_URL, pr) self.assertTrue(prs.has_build_passed(api, url))
def test_statuses_returns_failed_travis_build(self): test_data = [ # Travis failed [{ "state": "failure", "context": "continuous-integration/travis-ci/pr" }], # Travis pending [{ "state": "pending", "context": "continuous-integration/travis-ci/pr" }] ] for statuses in test_data: self.api.return_value = {"statuses": statuses} # Status returned failure or pending for travis - we know for sure it haven't suceeded self.assertFalse(prs.has_build_passed(self.api, "urn", "ref")) self.api.assert_called_once_with("get", "/repos/urn/commits/ref/status") self.api.reset_mock() # Status returned failure or pending for travis - we know for sure it failed self.assertTrue(prs.has_build_failed(self.api, "urn", "ref")) self.api.assert_called_once_with("get", "/repos/urn/commits/ref/status") self.api.reset_mock()
def test_statuses_returns_passed_travis_build(self): test_data = [ # single successfull run [{ "state": "success", "context": "continuous-integration/travis-ci/pr" }], # other contexts don't change result [{ "state": "success", "context": "continuous-integration/travis-ci/pr" }, { "state": "failure", "context": "chaosbot" }] ] for statuses in test_data: self.api.return_value = {"statuses": statuses} # Status returned success for travis - we know for sure it passed self.assertTrue(prs.has_build_passed(self.api, "urn", "ref")) self.api.assert_called_once_with("get", "/repos/urn/commits/ref/status") self.api.reset_mock() # Status returned success for travis - we know for sure it haven't failed self.assertFalse(prs.has_build_failed(self.api, "urn", "ref")) self.api.assert_called_once_with("get", "/repos/urn/commits/ref/status") self.api.reset_mock()
def test_statuses_returns_no_travis_build(self): # No travis statuses test_data = [ [{"state": "failure", "context": "chaos"}], [{"state": "pending", "context": "chaos"}], [{"state": "success", "context": "chaos"}] ] for statuses in test_data: self.api.return_value = {"statuses": statuses} # Status didn't return travis data - we can't say for sure if failed or succeeded self.assertFalse(prs.has_build_passed(self.api, "urn", "ref")) self.api.assert_called_once_with("get", "/repos/urn/commits/ref/status") self.api.reset_mock() self.assertFalse(prs.has_build_failed(self.api, "urn", "ref")) self.api.assert_called_once_with("get", "/repos/urn/commits/ref/status") self.api.reset_mock()