61 lines
2.8 KiB
Python
61 lines
2.8 KiB
Python
"""The 101st pending quote and older approved quotes remain reachable on the board."""
|
|
from uuid import uuid4
|
|
from urllib.parse import urlencode
|
|
|
|
from psycopg.types.json import Jsonb
|
|
|
|
from app.core import db
|
|
from tests.smoke_test import Client
|
|
|
|
|
|
def run():
|
|
owner = uuid4()
|
|
pending_ids = [uuid4() for _ in range(105)]
|
|
approved_ids = [uuid4() for _ in range(22)]
|
|
created = pending_ids + approved_ids
|
|
draft = {'customer': {'mail': 'pagination-fixture@example.test'},
|
|
'items': [], 'freight': {'service': 'pickup'}}
|
|
try:
|
|
with db.connect() as c:
|
|
for uid in pending_ids:
|
|
c.execute('''INSERT INTO dtf_local.quotes
|
|
(id,owner,request_key,request_hash,draft,created_at)
|
|
VALUES(%s,%s,%s,%s,%s,now()+interval '1 hour')''',
|
|
(uid, owner, uuid4(), 'pagination-fixture', Jsonb(draft)))
|
|
for uid in approved_ids:
|
|
c.execute('''INSERT INTO dtf_local.quotes
|
|
(id,owner,request_key,request_hash,draft,approved,approved_at,created_at)
|
|
VALUES(%s,%s,%s,%s,%s,%s,now(),now()+interval '1 hour')''',
|
|
(uid, owner, uuid4(), 'pagination-fixture', Jsonb(draft),
|
|
Jsonb({'items': [], 'total_cents': 0})))
|
|
|
|
client = Client()
|
|
board = client.call('/operator/board', operator=True)
|
|
assert board['pending_total'] >= 105
|
|
assert board['approved_total'] >= 22
|
|
for kind, fixture_ids in [('pending', pending_ids), ('approved', approved_ids)]:
|
|
first = [q for q in board['quotes'] if (q['approved'] is None) == (kind == 'pending')]
|
|
seen = {q['id'] for q in first}
|
|
assert len(first) == (100 if kind == 'pending' else 20)
|
|
last = first[-1]
|
|
for _ in range(5):
|
|
path = '/operator/quotes?' + urlencode({
|
|
'kind': kind, 'limit': 50,
|
|
'before_created_at': last['created_at'], 'before_id': last['id']})
|
|
page = client.call(path, operator=True)
|
|
assert page['quotes'], 'An older quote page disappeared'
|
|
assert not seen.intersection(q['id'] for q in page['quotes']), 'Quote page repeated rows'
|
|
seen.update(q['id'] for q in page['quotes'])
|
|
if set(map(str, fixture_ids)) <= seen:
|
|
break
|
|
last = page['quotes'][-1]
|
|
assert set(map(str, fixture_ids)) <= seen, f'{kind} quotes were hidden by the board limit'
|
|
print('PASS: 105 pending and 22 approved quotes remain reachable across board pages')
|
|
finally:
|
|
with db.connect() as c:
|
|
c.execute('DELETE FROM dtf_local.quotes WHERE id=ANY(%s)', (created,))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run()
|