From fd3f6f920f342f8479d65434677b109e034d8512 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 14 Jun 2017 15:43:42 +0100 Subject: [PATCH] Refactor conversation test to not re-request page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s no need to request the page once for each message on it. Quicker to load the page once and then loop through the messages. Still need this as an integration test because it’s testing the ordering and threading of the message. --- tests/app/main/views/test_conversation.py | 119 +++++++++++----------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index 3a30d6a3c..e70aea412 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -70,60 +70,6 @@ def test_get_user_phone_number_raises_if_both_API_requests_fail( mock_get_notification.assert_called_once_with('service', 'notification') -@pytest.mark.parametrize('index, expected', enumerate([ - ( - 'message-8', - 'Failed (sent yesterday at 2:59pm)', - ), - ( - 'message-7', - 'Failed (sent yesterday at 2:59pm)', - ), - ( - 'message-6', - 'Failed (sent yesterday at 4:59pm)', - ), - ( - 'message-5', - 'Failed (sent yesterday at 6:59pm)', - ), - ( - 'message-4', - 'Failed (sent yesterday at 8:59pm)', - ), - ( - 'message-3', - 'Failed (sent yesterday at 10:59pm)', - ), - ( - 'message-2', - 'Failed (sent yesterday at 10:59pm)', - ), - ( - 'message-1', - 'Failed (sent yesterday at 11:00pm)', - ), - ( - 'template content', - 'yesterday at midnight', - ), - ( - 'template content', - 'yesterday at midnight', - ), - ( - 'template content', - 'yesterday at midnight', - ), - ( - 'template content', - 'yesterday at midnight', - ), - ( - 'template content', - 'yesterday at midnight', - ), -])) @freeze_time("2012-01-01 00:00:00") def test_view_conversation( logged_in_client, @@ -131,8 +77,6 @@ def test_view_conversation( mock_get_notification, mock_get_inbound_sms, mock_get_notifications, - index, - expected, ): response = logged_in_client.get(url_for( @@ -148,7 +92,62 @@ def test_view_conversation( assert len(messages) == 13 assert len(statuses) == 13 - assert ( - normalize_spaces(messages[index].text), - normalize_spaces(statuses[index].text), - ) == expected + + for index, expected in enumerate([ + ( + 'message-8', + 'Failed (sent yesterday at 2:59pm)', + ), + ( + 'message-7', + 'Failed (sent yesterday at 2:59pm)', + ), + ( + 'message-6', + 'Failed (sent yesterday at 4:59pm)', + ), + ( + 'message-5', + 'Failed (sent yesterday at 6:59pm)', + ), + ( + 'message-4', + 'Failed (sent yesterday at 8:59pm)', + ), + ( + 'message-3', + 'Failed (sent yesterday at 10:59pm)', + ), + ( + 'message-2', + 'Failed (sent yesterday at 10:59pm)', + ), + ( + 'message-1', + 'Failed (sent yesterday at 11:00pm)', + ), + ( + 'template content', + 'yesterday at midnight', + ), + ( + 'template content', + 'yesterday at midnight', + ), + ( + 'template content', + 'yesterday at midnight', + ), + ( + 'template content', + 'yesterday at midnight', + ), + ( + 'template content', + 'yesterday at midnight', + ), + ]): + assert ( + normalize_spaces(messages[index].text), + normalize_spaces(statuses[index].text), + ) == expected