Read about our upcoming Code of Conduct on this issue

Commit 738443bb authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

test_watch_tags: reading token before hand

Will make further refactorings easier
parent 5323e1707acc
......@@ -96,4 +96,11 @@
return sorted(max(versions) for versions in by_series if versions)
def read_token_file(path):
# in recent Python 3 versions, `os.path` functions can take Path objects,
# but we need to run with the ancient 3.5
with open(os.path.expanduser(str(path))) as tokenf:
return tokenf.read().strip()
def create_issues(versions, server, token, project, simulate=True):
......@@ -99,7 +106,4 @@
def create_issues(versions, server, token, project, simulate=True):
with open(os.path.expanduser(token)) as tokenf:
token = tokenf.read().strip()
for version in versions:
print("Creating issue for GitLab " + repr(version))
url = '/'.join((server, 'api', 'v4', 'projects',
......@@ -198,6 +202,8 @@
print("No new releases to consider")
return
token = read_token_file(cl_args.heptapod_token)
if cl_args.create_issues:
return create_issues(versions=new_versions,
server=cl_args.heptapod_server,
......@@ -201,6 +207,6 @@
if cl_args.create_issues:
return create_issues(versions=new_versions,
server=cl_args.heptapod_server,
token=cl_args.heptapod_token,
token=token,
project=cl_args.heptapod_project,
simulate=simulate)
......@@ -8,6 +8,7 @@
from ..fetch_watch_tags import (
create_issues,
read_token_file,
)
from ..version import GitLabVersion
......@@ -22,10 +23,17 @@
return self.data
def test_create_issues(monkeypatch, tmpdir):
def test_read_token_file(tmpdir):
token_path = tmpdir / 'heptapod.token'
token_path.write('siCr3t')
assert read_token_file(token_path) == 'siCr3t'
def test_create_issues(monkeypatch):
records = []
def intercept_post(*a, **kw):
records.append((a, kw))
return FakeResponse(code=200, data=dict(iid=123))
......@@ -26,12 +34,9 @@
records = []
def intercept_post(*a, **kw):
records.append((a, kw))
return FakeResponse(code=200, data=dict(iid=123))
token_path = tmpdir / 'heptapod.token'
token_path.write('siCr3t')
monkeypatch.setattr(requests, 'post', intercept_post)
create_args = ([GitLabVersion(14, 1, 5)],
'https://heptapod.example',
......@@ -35,7 +40,7 @@
monkeypatch.setattr(requests, 'post', intercept_post)
create_args = ([GitLabVersion(14, 1, 5)],
'https://heptapod.example',
str(token_path),
'siCr3t',
'heptapod/heptapod')
create_issues(*create_args, simulate=False)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment