tests: New RT client classes start with seeded ticket data.

This reduces the amount of setup many tests need to do before they modify
the ticket data.
This commit is contained in:
Brett Smith 2020-03-25 15:23:52 -04:00
parent 1155212376
commit f227593655

View file

@ -43,7 +43,7 @@ def rt():
@pytest.fixture
def new_client():
class RTClient(testutil.RTClient):
TICKET_DATA = {'1': [], '2': []}
TICKET_DATA = testutil.RTClient.TICKET_DATA.copy()
return RTClient()
@pytest.mark.parametrize('ticket_id,attachment_id,expected', EXPECTED_URLS)
@ -53,20 +53,19 @@ def test_url(rt, ticket_id, attachment_id, expected):
assert rt.url(ticket_id, attachment_id) == expected
@pytest.mark.parametrize('attachment_id', [
3,
13,
None,
])
def test_url_caches(new_client, attachment_id):
new_client.TICKET_DATA['1'].append(('3', '(Unnamed)', 'text/plain', '3.0k'))
if attachment_id is None:
fragment = ''
else:
fragment = '#txn-3'
expected = '{}Ticket/Display.html?id=1{}'.format(DEFAULT_RT_URL, fragment)
fragment = '#txn-11'
expected = '{}Ticket/Display.html?id=2{}'.format(DEFAULT_RT_URL, fragment)
rt = rtutil.RT(new_client)
assert rt.url(1, attachment_id) == expected
assert rt.url(2, attachment_id) == expected
new_client.TICKET_DATA.clear()
assert rt.url(1, attachment_id) == expected
assert rt.url(2, attachment_id) == expected
@pytest.mark.parametrize('mimetype,extension', [
('application/pdf', 'pdf'),
@ -75,7 +74,7 @@ def test_url_caches(new_client, attachment_id):
('x-test/x-unknown', 'bin'),
])
def test_url_default_filename(new_client, mimetype, extension):
new_client.TICKET_DATA['1'].append(('9', '(Unnamed)', mimetype, '50.5k'))
new_client.TICKET_DATA['1'] = [('9', '(Unnamed)', mimetype, '50.5k')]
rt = rtutil.RT(new_client)
expected = '{}Ticket/Attachment/9/9/RT1%20attachment%209.{}'.format(DEFAULT_RT_URL, extension)
assert rt.url(1, 9) == expected
@ -86,16 +85,15 @@ def test_exists(rt, ticket_id, attachment_id, expected):
assert rt.exists(ticket_id, attachment_id) is expected
def test_exists_caches(new_client):
new_client.TICKET_DATA['1'].append(('3', '(Unnamed)', 'text/plain', '3.0k'))
rt = rtutil.RT(new_client)
assert rt.exists(1, 3)
assert rt.exists(2)
assert not rt.exists(1, 9)
assert not rt.exists(1, 99)
assert not rt.exists(9)
new_client.TICKET_DATA.clear()
assert rt.exists(1, 3)
assert rt.exists(2)
assert not rt.exists(1, 9)
assert not rt.exists(1, 99)
assert not rt.exists(9)
@pytest.mark.parametrize('link,expected', [