8000 Merge pull request #673 from dprothero/fix-issue-672 · hwine/github3.py@b0b27c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0b27c4

Browse files
authored
Merge pull request sigmavirus24#673 from dprothero/fix-issue-672
Ensure query string is included when building _api URL. Fixes sigmavirus24#672
2 parents 5544e97 + fe4388c commit b0b27c4

File tree

8 files changed

+42
-10
lines changed

8 files changed

+42
-10
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,4 @@ Contributors
145145

146146
- Björn Kautler (@Vampire)
147147

148+
- David Prothero (@dprothero)

github3/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ def _build_url(self, *args, **kwargs):
276276

277277
@property
278278
def _api(self):
279-
return "{0.scheme}://{0.netloc}{0.path}".format(self._uri)
279+
value = "{0.scheme}://{0.netloc}{0.path}".format(self._uri)
280+
if self._uri.query:
281+
value += '?{}'.format(self._uri.query)
282+
return value
280283

281284
@_api.setter
282285
def _api(self, uri):

tests/cassettes/Contents_delete.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/cassettes/Contents_update.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/integration/test_repos_repo.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,9 @@ def test_delete(self):
11351135
cassette_name = self.cassette_name('delete')
11361136
with self.recorder.use_cassette(cassette_name):
11371137
repository = self.gh.repository('github3py', 'delete_contents')
1138-
content = repository.readme()
1139-
deleted = content.delete('Deleting readme from repository')
1138+
repository.create_file('test.txt', 'Create test.txt', b'testing')
1139+
content = repository.file_contents('test.txt')
1140+
deleted = content.delete('Deleting test.txt from repository')
11401141

11411142
assert deleted
11421143

@@ -1146,13 +1147,17 @@ def test_update(self):
11461147
cassette_name = self.cassette_name('update')
11471148
with self.recorder.use_cassette(cassette_name):
11481149
repository = self.gh.repository('github3py', 'delete_contents')
1149-
content = repository.readme()
1150-
update = content.update(message='Updating README.md',
1150+
repository.create_file('test.txt', 'Create test.txt', b'testing')
1151+
content = repository.file_contents('test.txt')
1152+
update = content.update(message='Updating test.txt',
11511153
content=b'HELLO')
1154+
assert isinstance(update, dict)
1155+
assert isinstance(update['content'],
1156+
github3.repos.contents.Contents)
1157+
assert isinstance(update['commit'], github3.git.Commit)
11521158

1153-
assert isinstance(update, dict)
1154-
assert isinstance(update['content'], github3.repos.contents.Contents)
1155-
assert isinstance(update['commit'], github3.git.Commit)
1159+
# Clean-up
1160+
update['content'].delete('Deleting test.txt from repository')
11561161

11571162

11581163
class TestHook(helper.IntegrationHelper):

tests/unit/test_models.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,24 @@ def test_strptime(self):
216216
def test_strptime_time_str_required(self):
217217
"""Verify that method converts ISO 8601 formatted string."""
218218
assert self.instance._strptime('') is None
219+
220+
221+
class TestGitHubCoreIssue672(helper.UnitHelper):
222+
223+
described_class = MyTestRefreshClass
224+
last_modified = datetime.now().strftime(
225+
'%a, %d %b %Y %H:%M:%S GMT'
226+
)
227+
url = 'https://api.github.com/foo?bar=1'
228+
etag = '644b5b0155e6404a9cc4bd9d8b1ae730'
229+
example_data = {
230+
'url': url,
231+
'last_modified': last_modified,
232+
'etag': etag,
233+
'fake_attr': 'foo',
234+
}
235+
236+
def test_issue_672(self):
237+
"""Verify that _api property contains URL query"""
238+
assert '?' in self.instance._api
239+
assert self.instance._api == self.url

tests/unit/test_repos_repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
contents_url_for = helper.create_url_helper(
2626
'https://api.github.com/repos/github3py/github3.py/contents/README.rst'
27+
'?ref=master'
2728
)
2829
hook_url_for = helper.create_url_helper(
2930
'https://api.github.com/repos/octocat/Hello-World/hooks/1'

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line chan 60C1 ge
@@ -3,6 +3,7 @@ envlist = py{27,33,34,35,py},py{27,34}-flake8,docstrings
33
minversion = 2.5.0
44

55
[testenv]
6+
passenv = GH_*
67
pip_pre = False
78
deps =
89
requests{env:REQUESTS_VERSION:>=2.0}

0 commit comments

Comments
 (0)
0