Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
3c9ced2e
Unverified
Commit
3c9ced2e
authored
Mar 26, 2021
by
Cere Blanco
Committed by
GitHub
Mar 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repositories: fix 401, 403 handling
Resolves: #3303
parent
931cf120
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
15 deletions
+13
-15
poetry/repositories/legacy_repository.py
+6
-7
tests/repositories/test_legacy_repository.py
+7
-8
No files found.
poetry/repositories/legacy_repository.py
View file @
3c9ced2e
...
...
@@ -423,19 +423,18 @@ class LegacyRepository(PyPiRepository):
url
=
self
.
_url
+
endpoint
try
:
response
=
self
.
session
.
get
(
url
)
if
response
.
status_code
in
(
401
,
403
):
self
.
_log
(
"Authorization error accessing {url}"
.
format
(
url
=
url
),
level
=
"warning"
,
)
return
if
response
.
status_code
==
404
:
return
response
.
raise_for_status
()
except
requests
.
HTTPError
as
e
:
raise
RepositoryError
(
e
)
if
response
.
status_code
in
(
401
,
403
):
self
.
_log
(
"Authorization error accessing {url}"
.
format
(
url
=
response
.
url
),
level
=
"warn"
,
)
return
if
response
.
url
!=
url
:
self
.
_log
(
"Response URL {response_url} differs from request URL {url}"
.
format
(
...
...
tests/repositories/test_legacy_repository.py
View file @
3c9ced2e
...
...
@@ -338,19 +338,18 @@ def test_get_200_returns_page(http):
assert
repo
.
_get
(
"/foo"
)
def
test_get_404_returns_none
(
http
):
repo
=
MockHttpRepository
({
"/foo"
:
404
},
http
)
@pytest.mark.parametrize
(
"status_code"
,
[
401
,
403
,
404
])
def
test_get_40x_and_returns_none
(
http
,
status_code
):
repo
=
MockHttpRepository
({
"/foo"
:
status_code
},
http
)
assert
repo
.
_get
(
"/foo"
)
is
None
def
test_get_4xx_and_5xx_raises
(
http
):
endpoints
=
{
"/{}"
.
format
(
code
):
code
for
code
in
{
401
,
403
,
500
}}
repo
=
MockHttpRepository
(
endpoints
,
http
)
def
test_get_5xx_raises
(
http
):
repo
=
MockHttpRepository
({
"/foo"
:
500
},
http
)
for
endpoint
in
endpoints
:
with
pytest
.
raises
(
RepositoryError
):
repo
.
_get
(
endpoint
)
with
pytest
.
raises
(
RepositoryError
):
repo
.
_get
(
"/foo"
)
def
test_get_redirected_response_url
(
http
,
monkeypatch
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment