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/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.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" 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/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/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 = ( 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"}], )