GeezerVison is showing github.com — Merge pull request #1418 from python-gitlab/fix/urlencode-file-paths · kkopper/python-gitlab@37af229
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: gitlab/__version__.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | | 4 | 4 | __license__ = "LGPL3" | 5 | 5 | __title__ = "python-gitlab" | 6 | | -__version__ = "2.7.0" | | 6 | +__version__ = "2.7.1" |
Collapse file Copy file name to clipboard +49Lines changed: 49 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +""" | | 2 | +GitLab API: | | 3 | +https://docs.gitlab.com/ee/api/repositories.html | | 4 | +https://docs.gitlab.com/ee/api/repository_files.html | | 5 | +""" | | 6 | +from urllib.parse import quote | | 7 | + | | 8 | +import pytest | | 9 | +import responses | | 10 | + | | 11 | +from gitlab.v4.objects import ProjectFile | | 12 | + | | 13 | +file_path = "app/models/key.rb" | | 14 | +ref = "main" | | 15 | + | | 16 | + | | 17 | +@pytest.fixture | | 18 | +def resp_get_repository_file(): | | 19 | + file_response = { | | 20 | + "file_name": "key.rb", | | 21 | + "file_path": file_path, | | 22 | + "size": 1476, | | 23 | + "encoding": "base64", | | 24 | + "content": "IyA9PSBTY2hlbWEgSW5mb3...", | | 25 | + "content_sha256": "4c294617b60715c1d218e61164a3abd4808a4284cbc30e6728a01ad9aada4481", | | 26 | + "ref": ref, | | 27 | + "blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83", | | 28 | + "commit_id": "d5a3ff139356ce33e37e73add446f16869741b50", | | 29 | + "last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d", | | 30 | + } | | 31 | + | | 32 | + # requests also encodes `.` | | 33 | + encoded_path = quote(file_path, safe="").replace(".", "%2E") | | 34 | + | | 35 | + with responses.RequestsMock() as rsps: | | 36 | + rsps.add( | | 37 | + method=responses.GET, | | 38 | + url=f"http://localhost/api/v4/projects/1/repository/files/{encoded_path}", | | 39 | + json=file_response, | | 40 | + content_type="application/json", | | 41 | + status=200, | | 42 | + ) | | 43 | + yield rsps | | 44 | + | | 45 | + | | 46 | +def test_get_repository_file(project, resp_get_repository_file): | | 47 | + file = project.files.get(file_path, ref=ref) | | 48 | + assert isinstance(file, ProjectFile) | | 49 | + assert file.file_path == file_path |
Collapse file Copy file name to clipboardExpand all lines: gitlab/v4/objects/files.py -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -94,7 +94,6 @@ def get(self, file_path, ref, **kwargs): | 94 | 94 | Returns: | 95 | 95 | object: The generated RESTObject | 96 | 96 | """ | 97 | | - file_path = file_path.replace("/", "%2F") | 98 | 97 | return GetMixin.get(self, file_path, ref=ref, **kwargs) | 99 | 98 |
| 100 | 99 | @cli.register_custom_action( | |
|