From 957bf726d757afab979f20a5010b2d8a0ffec1ea Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 28 Aug 2020 00:04:47 +0100 Subject: [PATCH 1/4] :bug: raise exception --- changelog.yml | 6 ++++++ gease/_version.py | 6 +++--- gease/exceptions.py | 4 ++++ gease/rest.py | 6 ++++-- tests/test_api.py | 9 +++++++++ tests/test_contributors.py | 6 +++--- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/changelog.yml b/changelog.yml index d598f58..c318572 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,6 +1,12 @@ name: gease organisation: moremoban releases: + - changes: + - action: Updated + details: + - "raise UrlNotFound when request a non-existent url" + date: 28.08.2020 + version: 0.0.7 - changes: - action: Updated details: diff --git a/gease/_version.py b/gease/_version.py index 7369950..073faa7 100644 --- a/gease/_version.py +++ b/gease/_version.py @@ -1,3 +1,3 @@ -__version__ = '0.0.6' -__author__ = 'C. W.' -__description__ = 'simply makes a git release using github api v3' +__version__ = "0.0.6" +__author__ = "C. W." +__description__ = "simply makes a git release using github api v3" diff --git a/gease/exceptions.py b/gease/exceptions.py index 1138fc0..cefa30b 100644 --- a/gease/exceptions.py +++ b/gease/exceptions.py @@ -20,3 +20,7 @@ class AbnormalGithubResponse(Exception): class UnhandledException(Exception): pass + + +class UrlNotFound(Exception): + pass diff --git a/gease/rest.py b/gease/rest.py index 27000b2..0be98d8 100644 --- a/gease/rest.py +++ b/gease/rest.py @@ -54,7 +54,10 @@ def create(self, url, data): def get(self, url): r = self.__session.get(url) - return r.json() + if r.status_code == 200: + return r.json() + elif r.status_code == 404: + raise exceptions.UrlNotFound(f"{url} does not exist") @classmethod def get_api(cls): @@ -63,7 +66,6 @@ def get_api(cls): cls.__instance = cls(token) return cls.__instance - @classmethod def get_public_api(cls): cls.__instance = cls(None) diff --git a/tests/test_api.py b/tests/test_api.py index 0ff4389..e720a9d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,6 +3,7 @@ from gease.rest import Api from gease.exceptions import ( + UrlNotFound, RepoNotFoundError, ReleaseExistException, AbnormalGithubResponse, @@ -90,3 +91,11 @@ def test_unknown_error(self): ) api = Api("test") api.create("http://localhost/", "cool") + + @raises(UrlNotFound) + def test_get_unknown_url(self): + self.fake_session.return_value = MagicMock( + get=MagicMock(side_effect=UrlNotFound) + ) + api = Api("test") + api.get("s") diff --git a/tests/test_contributors.py b/tests/test_contributors.py index 0ef812e..0d3ff60 100644 --- a/tests/test_contributors.py +++ b/tests/test_contributors.py @@ -8,7 +8,7 @@ class TestPublish: @patch("gease.contributors.Api.get_public_api") def test_all_contributors(self, fake_api): sample_reply = [ - {"login": "howdy", "url": "https://api.github.com/users/howdy",} + {"login": "howdy", "url": "https://api.github.com/users/howdy"} ] fake_api.return_value = MagicMock( get=MagicMock(side_effect=[sample_reply, {"name": "hello world"}]) @@ -30,7 +30,7 @@ def test_all_contributors(self, fake_api): @patch("gease.contributors.Api.get_public_api") def test_no_names(self, fake_api): sample_reply = [ - {"login": "howdy", "url": "https://api.github.com/users/howdy",} + {"login": "howdy", "url": "https://api.github.com/users/howdy"} ] fake_api.return_value = MagicMock( get=MagicMock(side_effect=[sample_reply, {"name": None}]) @@ -41,5 +41,5 @@ def test_no_names(self, fake_api): eq_( contributors, - [{"name": "howdy", "url": "https://api.github.com/users/howdy",}], + [{"name": "howdy", "url": "https://api.github.com/users/howdy"}], ) From 44dcec3f7aea675c28326f5439ba757b75f747e7 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 27 Aug 2020 23:05:16 +0000 Subject: [PATCH 2/4] This is an auto-commit --- CHANGELOG.rst | 7 +++++++ gease/_version.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bf7e038..c16c6d4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ Change log ================================================================================ +0.0.7 - 28.08.2020 +-------------------------------------------------------------------------------- + +**Updated** + +#. raise UrlNotFound when request a non-existent url + 0.0.6 - 26.08.2020 -------------------------------------------------------------------------------- diff --git a/gease/_version.py b/gease/_version.py index 073faa7..7369950 100644 --- a/gease/_version.py +++ b/gease/_version.py @@ -1,3 +1,3 @@ -__version__ = "0.0.6" -__author__ = "C. W." -__description__ = "simply makes a git release using github api v3" +__version__ = '0.0.6' +__author__ = 'C. W.' +__description__ = 'simply makes a git release using github api v3' From 4611360d82b79e3786bfab67aa43225cfbd3f456 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 28 Aug 2020 00:05:38 +0100 Subject: [PATCH 3/4] :egg: :ferris_wheel: release 0.0.7 --- gease.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gease.yml b/gease.yml index 5f0d5c4..e33a8e3 100644 --- a/gease.yml +++ b/gease.yml @@ -4,9 +4,9 @@ organisation: "moremoban" author: "C. W." contact: "wangc_2011@hotmail.com" company: "Onni Software Ltd." -version: "0.0.6" -current_version: 0.0.6 -release: "0.0.6" +version: "0.0.7" +current_version: 0.0.7 +release: "0.0.7" copyright_year: 2017-2020 command_line_interface: gease entry_point: "gease.main:main" From dbce75fb2a0acd1d0d9f1207d0cda5e9dd25ad2f Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 27 Aug 2020 23:06:06 +0000 Subject: [PATCH 4/4] This is an auto-commit --- gease/_version.py | 2 +- setup.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gease/_version.py b/gease/_version.py index 7369950..fd58ada 100644 --- a/gease/_version.py +++ b/gease/_version.py @@ -1,3 +1,3 @@ -__version__ = '0.0.6' +__version__ = '0.0.7' __author__ = 'C. W.' __description__ = 'simply makes a git release using github api v3' diff --git a/setup.py b/setup.py index 8de2306..4629c90 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ NAME = "gease" AUTHOR = "C. W." -VERSION = "0.0.6" +VERSION = "0.0.7" EMAIL = "wangc_2011@hotmail.com" LICENSE = "MIT" ENTRY_POINTS = { @@ -45,7 +45,7 @@ "simply makes a git release using github api v3" ) URL = "https://github.com/moremoban/gease" -DOWNLOAD_URL = "%s/archive/0.0.6.tar.gz" % URL +DOWNLOAD_URL = "%s/archive/0.0.7.tar.gz" % URL FILES = ["README.rst", "CHANGELOG.rst"] KEYWORDS = [ "python", @@ -78,8 +78,8 @@ } # You do not need to read beyond this line PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable) -GS_COMMAND = ("gs gease v0.0.6 " + - "Find 0.0.6 in changelog for more details") +GS_COMMAND = ("gs gease v0.0.7 " + + "Find 0.0.7 in changelog for more details") NO_GS_MESSAGE = ("Automatic github release is disabled. " + "Please install gease to enable it.") UPLOAD_FAILED_MSG = (