53 lines
2.9 KiB
Python
53 lines
2.9 KiB
Python
"""Called by the Go synthetic HTTP fixture; no production credentials."""
|
|
import contextlib
|
|
import io
|
|
import json
|
|
from pathlib import Path
|
|
import runpy
|
|
import sys
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
def run():
|
|
m=runpy.run_path(str(Path(__file__).with_name('pages')))
|
|
fixture=json.load(sys.stdin)
|
|
client=m['Client'](fixture['origin'],fixture['token'])
|
|
profile=m['Profile']('test',fixture['root'])
|
|
def task(*words):
|
|
output=io.StringIO()
|
|
with contextlib.redirect_stdout(output):m['tasks'](client,profile,list(words))
|
|
return json.loads(output.getvalue())
|
|
with profile.locked():
|
|
prefs=task('preferences','--due-days','2','--estimate','60','--complexity','3')
|
|
assert prefs['preferences']['due_days']==2
|
|
item=task('add','CLI task')['item'];ident=item['uuid']
|
|
assert item['estimate_minutes']==60 and item['due_on']
|
|
task('start',ident);assert task('status')['item']['task_uuid']==ident
|
|
task('stop');assert task('status')['item'] is None
|
|
item=task('update',ident,'--title','Updated CLI task')['item'];assert item['title']=='Updated CLI task'
|
|
task('done',ident)
|
|
report=task('report','--json');assert sum(d['points'] for d in report['days'])==7
|
|
assert any(i['uuid']==ident for i in report['tasks'])
|
|
task('preferences','--wiki-prefix','/private/mail')
|
|
mail=b'Subject: CLI mail\r\nMessage-ID: <integration@example.invalid>\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nPrivate mail body {{children}}'
|
|
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(mail))):
|
|
captured=task('from-mail')
|
|
assert captured['item']['page_uuid'] and captured['page_path'].startswith('/private/mail/CLI mail--')
|
|
assert 'Private mail body' not in captured['item']['notes']
|
|
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(mail))):
|
|
assert task('from-mail')['item']['page_uuid']==captured['item']['page_uuid']
|
|
note=client.json(m['TASK_API']+'items/'+captured['item']['uuid']+'/note')
|
|
assert note['linked'] and note['path']==captured['page_path']
|
|
path=Path(fixture['root'])/'person.vcf'
|
|
path.write_text('BEGIN:VCARD\r\nVERSION:4.0\r\nUID:urn:test:cli\r\nFN:CLI Person\r\nEMAIL:cli@example.invalid\r\nEND:VCARD\r\n')
|
|
output=io.StringIO()
|
|
with contextlib.redirect_stdout(output):m['contacts'](client,['import',str(path)])
|
|
contact=json.loads(output.getvalue())['item'];output=io.StringIO()
|
|
with contextlib.redirect_stdout(output):m['contacts'](client,['query','CLI','--neomutt'])
|
|
assert 'cli@example.invalid\tCLI Person\t' in output.getvalue()
|
|
output=io.StringIO()
|
|
with contextlib.redirect_stdout(output):m['contacts'](client,['export',contact['uuid']])
|
|
assert 'UID:urn:test:cli' in output.getvalue()
|
|
|
|
if __name__=='__main__':run()
|