[FIX] conftest: ensure we always have a reason in get_ref

Apparently the "reason phrase" has been removed from HTTP/2 and github
has enabled HTTP/2, meaning responses may or may not contain a reason
phrase depending whether they're HTTP/1.1 or HTTP/2. Now I don't
understand how this triggers because requests isn't supposed to
support HTTP/2, and in a shell I do get a reason, but w/e.

Anyway the reason is used by a few tests to check more specifically
for the response they're getting, as that's used as the assertion
message by `get_ref`.

I guess I could replace the AssertionError by an HTTPError
but... w/e. Seems simpler to just fallback to the generic reason based
on the status code. It fixes both failing
tests (test_straightforward_flow and test_delete_normal) with very
little change.
This commit is contained in:
Xavier Morel 2021-02-24 09:32:58 +01:00
parent c538bd17f8
commit ab919c00db

View File

@ -43,6 +43,7 @@ import base64
import collections
import configparser
import copy
import http.client
import itertools
import logging
import os
@ -493,7 +494,7 @@ class Repo:
if re.match(r'[0-9a-f]{40}', ref):
# just check that the commit exists
r = self._session.get('https://api.github.com/repos/{}/git/commits/{}'.format(self.name, ref))
assert 200 <= r.status_code < 300, r.reason
assert 200 <= r.status_code < 300, r.reason or http.client.responses[r.status_code]
return r.json()['sha']
if ref.startswith('refs/'):
@ -502,7 +503,7 @@ class Repo:
ref = 'heads/' + ref
r = self._session.get('https://api.github.com/repos/{}/git/ref/{}'.format(self.name, ref))
assert 200 <= r.status_code < 300, r.reason
assert 200 <= r.status_code < 300, r.reason or http.client.responses[r.status_code]
res = r.json()
assert res['object']['type'] == 'commit'
return res['object']['sha']