mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] conftest: repo setup error checking
Before the repo setup calls would be checked using `raise_for_status` but that turns out to be less than great as github mostly returns information via the body (as JSON), even if that information is often useless. Add a `check` utility which checks if the response is invalid and prints the body.
This commit is contained in:
parent
1e296a4713
commit
462d1699f6
31
conftest.py
31
conftest.py
@ -46,7 +46,6 @@ import contextlib
|
|||||||
import copy
|
import copy
|
||||||
import http.client
|
import http.client
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
@ -358,6 +357,9 @@ def server(request, db, port, module):
|
|||||||
def env(port, server, db, default_crons):
|
def env(port, server, db, default_crons):
|
||||||
yield Environment(port, db, default_crons)
|
yield Environment(port, db, default_crons)
|
||||||
|
|
||||||
|
def check(response):
|
||||||
|
assert response.ok, response.text or response.reason
|
||||||
|
return response
|
||||||
# users is just so I can avoid autouse on toplevel users fixture b/c it (seems
|
# users is just so I can avoid autouse on toplevel users fixture b/c it (seems
|
||||||
# to) break the existing local tests
|
# to) break the existing local tests
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -375,8 +377,7 @@ def make_repo(capsys, request, config, tunnel, users):
|
|||||||
endpoint = 'https://api.github.com/orgs/{}/repos'.format(owner)
|
endpoint = 'https://api.github.com/orgs/{}/repos'.format(owner)
|
||||||
else:
|
else:
|
||||||
endpoint = 'https://api.github.com/user/repos'
|
endpoint = 'https://api.github.com/user/repos'
|
||||||
r = github.get('https://api.github.com/user')
|
r = check(github.get('https://api.github.com/user'))
|
||||||
r.raise_for_status()
|
|
||||||
assert r.json()['login'] == owner
|
assert r.json()['login'] == owner
|
||||||
|
|
||||||
repos = []
|
repos = []
|
||||||
@ -386,7 +387,7 @@ def make_repo(capsys, request, config, tunnel, users):
|
|||||||
repo_url = 'https://api.github.com/repos/{}'.format(fullname)
|
repo_url = 'https://api.github.com/repos/{}'.format(fullname)
|
||||||
|
|
||||||
# create repo
|
# create repo
|
||||||
r = github.post(endpoint, json={
|
r = check(github.post(endpoint, json={
|
||||||
'name': name,
|
'name': name,
|
||||||
'has_issues': False,
|
'has_issues': False,
|
||||||
'has_projects': False,
|
'has_projects': False,
|
||||||
@ -396,12 +397,11 @@ def make_repo(capsys, request, config, tunnel, users):
|
|||||||
'allow_squash_merge': False,
|
'allow_squash_merge': False,
|
||||||
# 'allow_merge_commit': False,
|
# 'allow_merge_commit': False,
|
||||||
'allow_rebase_merge': False,
|
'allow_rebase_merge': False,
|
||||||
})
|
}))
|
||||||
r.raise_for_status()
|
|
||||||
repo = Repo(github, fullname, repos)
|
repo = Repo(github, fullname, repos)
|
||||||
|
|
||||||
# create webhook
|
# create webhook
|
||||||
github.post('{}/hooks'.format(repo_url), json={
|
check(github.post('{}/hooks'.format(repo_url), json={
|
||||||
'name': 'web',
|
'name': 'web',
|
||||||
'config': {
|
'config': {
|
||||||
'url': '{}/runbot_merge/hooks'.format(tunnel),
|
'url': '{}/runbot_merge/hooks'.format(tunnel),
|
||||||
@ -409,14 +409,14 @@ def make_repo(capsys, request, config, tunnel, users):
|
|||||||
'insecure_ssl': '1',
|
'insecure_ssl': '1',
|
||||||
},
|
},
|
||||||
'events': ['pull_request', 'issue_comment', 'status', 'pull_request_review']
|
'events': ['pull_request', 'issue_comment', 'status', 'pull_request_review']
|
||||||
})
|
}))
|
||||||
|
|
||||||
github.put('{}/contents/{}'.format(repo_url, 'a'), json={
|
check(github.put('{}/contents/{}'.format(repo_url, 'a'), json={
|
||||||
'path': 'a',
|
'path': 'a',
|
||||||
'message': 'github returns a 409 (Git Repository is Empty) if trying to create a tree in a repo with no objects',
|
'message': 'github returns a 409 (Git Repository is Empty) if trying to create a tree in a repo with no objects',
|
||||||
'content': base64.b64encode(b'whee').decode('ascii'),
|
'content': base64.b64encode(b'whee').decode('ascii'),
|
||||||
'branch': 'garbage_%s' % uuid.uuid4()
|
'branch': 'garbage_%s' % uuid.uuid4()
|
||||||
}).raise_for_status()
|
}))
|
||||||
# try to unwatch repo, doesn't actually work
|
# try to unwatch repo, doesn't actually work
|
||||||
repo.unsubscribe()
|
repo.unsubscribe()
|
||||||
return repo
|
return repo
|
||||||
@ -462,16 +462,13 @@ class Repo:
|
|||||||
|
|
||||||
def add_collaborator(self, login, token):
|
def add_collaborator(self, login, token):
|
||||||
# send invitation to user
|
# send invitation to user
|
||||||
r = self._session.put('https://api.github.com/repos/{}/collaborators/{}'.format(self.name, login))
|
r = check(self._session.put('https://api.github.com/repos/{}/collaborators/{}'.format(self.name, login)))
|
||||||
assert r.ok, r.json()
|
|
||||||
# accept invitation on behalf of user
|
# accept invitation on behalf of user
|
||||||
r = requests.patch('https://api.github.com/user/repository_invitations/{}'.format(r.json()['id']), headers={
|
check(requests.patch('https://api.github.com/user/repository_invitations/{}'.format(r.json()['id']), headers={
|
||||||
'Authorization': 'token ' + token
|
'Authorization': 'token ' + token
|
||||||
})
|
}))
|
||||||
assert r.ok, r.json()
|
|
||||||
# sanity check that user is part of collaborators
|
# sanity check that user is part of collaborators
|
||||||
r = self._session.get('https://api.github.com/repos/{}/collaborators'.format(self.name))
|
r = check(self._session.get('https://api.github.com/repos/{}/collaborators'.format(self.name)))
|
||||||
assert r.ok, r.json()
|
|
||||||
assert any(login == c['login'] for c in r.json())
|
assert any(login == c['login'] for c in r.json())
|
||||||
|
|
||||||
def _get_session(self, token):
|
def _get_session(self, token):
|
||||||
|
Loading…
Reference in New Issue
Block a user