feat(seo): atomic directive fencing and transactional blog publication
Deploy Canina / deploy (push) Successful in 4m45s
Deploy Canina / deploy (push) Successful in 4m45s
This commit is contained in:
1 parent
0a156fd7b4
commit
fb1deadbbc
10 files changed
+353
-187
No files matched your search
@@ -0,0 +1,51 @@
|
||||
"""Disposable-loopback acceptance only; deliberately not AdminTransport HTTPS bypass."""
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
from consumer import Consumer, Blocked
|
||||
from daily_publisher import run_new
|
||||
|
||||
origin = os.environ['PUBLICATION_LOCAL_ORIGIN']
|
||||
if not origin.startswith('http://127.0.0.1:'):
|
||||
raise RuntimeError('Disposable loopback only')
|
||||
token = os.environ['PUBLICATION_LOCAL_TOKEN']
|
||||
def api(method, path, body=None, bearer=token):
|
||||
req = urllib.request.Request(origin + path, method=method,
|
||||
data=None if body is None else json.dumps(body).encode(),
|
||||
headers={'Authorization': 'Bearer ' + bearer, 'Content-Type': 'application/json'})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=10) as r:
|
||||
return json.load(r)
|
||||
except urllib.error.HTTPError as e:
|
||||
raise Blocked('HTTP ' + str(e.code)) from None
|
||||
research = dict(title='publication-http-fixture', hypothesis='disposable',
|
||||
primaryKeyword='fixture', targetKeywords=['fixture'], expectedOutcome='fixture')
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
c = Consumer(tmp + '/journal.db', api)
|
||||
result = run_new(c, 'http-success', research,
|
||||
lambda p: dict(title='fixture', slug='publication-fixture-http', content='<p>reviewed</p>'),
|
||||
lambda *args: None, lambda d: d)
|
||||
assert result and c.reconcile_link('http-success') == result
|
||||
stale = Consumer(tmp + '/stale.db', api)
|
||||
def preflight(d):
|
||||
p = json.loads(stale.row('http-stale')['packet'])
|
||||
api('PATCH', '/api/admin/seo-tracking/' + p['id'] + '/feedback',
|
||||
dict(expectedVersion=p['version'], feedback='changed after draft'))
|
||||
return d
|
||||
try:
|
||||
run_new(stale, 'http-stale', research,
|
||||
lambda p: dict(title='stale', slug='publication-fixture-http-stale', content='stale'),
|
||||
lambda *args: None, preflight)
|
||||
raise AssertionError('stale publication accepted')
|
||||
except Blocked as e:
|
||||
assert str(e) == 'HTTP 409'
|
||||
p = json.loads(stale.row('http-stale')['packet'])
|
||||
assert api('GET', '/api/admin/seo-tracking/' + p['id'])['blogId'] is None
|
||||
try:
|
||||
api('POST', '/api/admin/seo-tracking/' + p['id'] + '/publication', {}, bearer='invalid')
|
||||
raise AssertionError('unauthenticated publication accepted')
|
||||
except Blocked as e:
|
||||
assert str(e) == 'HTTP 401'
|
||||
print('PUBLICATION_REAL_HTTP_PASSED')
|
||||
Reference in new issue
Block a user