From f227593655ba6facc9d0dbebb1f056df2b87cfd7 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 25 Mar 2020 15:23:52 -0400 Subject: [PATCH] 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. --- tests/test_rtutil.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/test_rtutil.py b/tests/test_rtutil.py index 9aed048..042634c 100644 --- a/tests/test_rtutil.py +++ b/tests/test_rtutil.py @@ -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', [