From c54e0d322be19d75be7985bbf9f11f204b0bd661 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 21 Dec 2017 17:18:35 +0000 Subject: [PATCH] A little clean up --- tests/app/conftest.py | 20 ++---------------- tests/app/dao/test_inbound_sms_dao.py | 21 +++++++++++-------- tests/app/db.py | 1 - .../v2/inbound_sms/test_get_inbound_sms.py | 7 ++++--- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/tests/app/conftest.py b/tests/app/conftest.py index e51aedd7d..bf675ed2b 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -57,8 +57,7 @@ from tests.app.db import ( create_service, create_api_key, create_inbound_number, - create_letter_contact, - create_inbound_sms, + create_letter_contact ) @@ -649,16 +648,6 @@ def sample_email_notification(notify_db, notify_db_session): return notification -@pytest.fixture(scope='function') -def mock_statsd_inc(mocker): - return mocker.patch('app.statsd_client.incr') - - -@pytest.fixture(scope='function') -def mock_statsd_timing(mocker): - return mocker.patch('app.statsd_client.timing') - - @pytest.fixture(scope='function') def sample_notification_history( notify_db, @@ -1048,18 +1037,13 @@ def sample_provider_rate(notify_db, notify_db_session, valid_from=None, rate=Non @pytest.fixture def sample_inbound_numbers(notify_db, notify_db_session, sample_service): service = create_service(service_name='sample service 2') - inbound_numbers = [] + inbound_numbers = list() inbound_numbers.append(create_inbound_number(number='1', provider='mmg')) inbound_numbers.append(create_inbound_number(number='2', provider='mmg', active=False, service_id=service.id)) inbound_numbers.append(create_inbound_number(number='3', provider='firetext', service_id=sample_service.id)) return inbound_numbers -@pytest.fixture -def sample_inbound_sms(notify_db, notify_db_session, sample_service): - return create_inbound_sms(sample_service) - - @pytest.fixture def restore_provider_details(notify_db, notify_db_session): """ diff --git a/tests/app/dao/test_inbound_sms_dao.py b/tests/app/dao/test_inbound_sms_dao.py index 8c8d0305f..c74abb1b5 100644 --- a/tests/app/dao/test_inbound_sms_dao.py +++ b/tests/app/dao/test_inbound_sms_dao.py @@ -90,25 +90,28 @@ def test_should_not_delete_inbound_sms_before_seven_days(sample_service): assert len(InboundSms.query.all()) == 2 -def test_get_inbound_sms_by_id_returns(sample_inbound_sms): - inbound_from_db = dao_get_inbound_sms_by_id(sample_inbound_sms.service.id, sample_inbound_sms.id) +def test_get_inbound_sms_by_id_returns(sample_service): + inbound_sms = create_inbound_sms(service=sample_service) + inbound_from_db = dao_get_inbound_sms_by_id(inbound_sms.service.id, inbound_sms.id) - assert sample_inbound_sms == inbound_from_db + assert inbound_sms == inbound_from_db -def test_dao_get_paginated_inbound_sms_for_service(sample_inbound_sms): - inbound_from_db = dao_get_paginated_inbound_sms_for_service(sample_inbound_sms.service.id) +def test_dao_get_paginated_inbound_sms_for_service(sample_service): + inbound_sms = create_inbound_sms(service=sample_service) + inbound_from_db = dao_get_paginated_inbound_sms_for_service(inbound_sms.service.id) - assert sample_inbound_sms == inbound_from_db[0] + assert inbound_sms == inbound_from_db[0] -def test_dao_get_paginated_inbound_sms_for_service_return_only_for_service(sample_inbound_sms): +def test_dao_get_paginated_inbound_sms_for_service_return_only_for_service(sample_service): + inbound_sms = create_inbound_sms(service=sample_service) another_service = create_service(service_name='another service') another_inbound_sms = create_inbound_sms(another_service) - inbound_from_db = dao_get_paginated_inbound_sms_for_service(sample_inbound_sms.service.id) + inbound_from_db = dao_get_paginated_inbound_sms_for_service(inbound_sms.service.id) - assert sample_inbound_sms in inbound_from_db + assert inbound_sms in inbound_from_db assert another_inbound_sms not in inbound_from_db diff --git a/tests/app/db.py b/tests/app/db.py index 922493b23..50926481b 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -126,7 +126,6 @@ def create_template( template_name=None, subject='Template subject', content='Dear Sir/Madam, Hello. Yours Truly, The Government.', - template_id=None, reply_to=None ): data = { diff --git a/tests/app/v2/inbound_sms/test_get_inbound_sms.py b/tests/app/v2/inbound_sms/test_get_inbound_sms.py index e499089c3..dfd4ae0b9 100644 --- a/tests/app/v2/inbound_sms/test_get_inbound_sms.py +++ b/tests/app/v2/inbound_sms/test_get_inbound_sms.py @@ -97,15 +97,16 @@ def test_get_next_inbound_sms_will_get_correct_inbound_sms_list(client, sample_s _external=True) == json_response['links']['next'] -def test_get_next_inbound_sms_at_end_will_return_empty_inbound_sms_list(client, sample_inbound_sms, mocker): +def test_get_next_inbound_sms_at_end_will_return_empty_inbound_sms_list(client, sample_service, mocker): + inbound_sms = create_inbound_sms(service=sample_service) mocker.patch.dict( "app.v2.inbound_sms.get_inbound_sms.current_app.config", {"API_PAGE_SIZE": 1} ) - auth_header = create_authorization_header(service_id=sample_inbound_sms.service.id) + auth_header = create_authorization_header(service_id=inbound_sms.service.id) response = client.get( - path=url_for('v2_inbound_sms.get_inbound_sms', older_than=sample_inbound_sms.id), + path=url_for('v2_inbound_sms.get_inbound_sms', older_than=inbound_sms.id), headers=[('Content-Type', 'application/json'), auth_header]) assert response.status_code == 200