Use fixtures for SMS provider test data

This avoids the need to manually copy psuedo fixture data to avoid
breaking other tests.
This commit is contained in:
Ben Thorner
2022-04-06 17:30:35 +01:00
parent 6d77ff54b1
commit 05c396434d

View File

@@ -1,4 +1,3 @@
import copy
from datetime import datetime from datetime import datetime
from unittest.mock import call from unittest.mock import call
@@ -7,7 +6,10 @@ from flask import url_for
from app.main.views.providers import add_monthly_traffic from app.main.views.providers import add_monthly_traffic
sms_provider_1 = {
@pytest.fixture
def sms_provider_1():
return {
'id': 'sms_provider_1-id', 'id': 'sms_provider_1-id',
'active': True, 'active': True,
'priority': 20, 'priority': 20,
@@ -21,7 +23,10 @@ sms_provider_1 = {
'current_month_billable_sms': 5020, 'current_month_billable_sms': 5020,
} }
sms_provider_2 = {
@pytest.fixture
def sms_provider_2():
return {
'id': 'sms_provider_2-id', 'id': 'sms_provider_2-id',
'active': True, 'active': True,
'priority': 10, 'priority': 10,
@@ -35,7 +40,10 @@ sms_provider_2 = {
'current_month_billable_sms': 6891, 'current_month_billable_sms': 6891,
} }
email_provider_1 = {
@pytest.fixture
def email_provider_1():
return {
'id': 'email_provider_1-id', 'id': 'email_provider_1-id',
'active': True, 'active': True,
'priority': 1, 'priority': 1,
@@ -49,7 +57,10 @@ email_provider_1 = {
'current_month_billable_sms': 0, 'current_month_billable_sms': 0,
} }
email_provider_2 = {
@pytest.fixture
def email_provider_2():
return {
'id': 'email_provider_2-id', 'id': 'email_provider_2-id',
'active': True, 'active': True,
'priority': 2, 'priority': 2,
@@ -63,7 +74,10 @@ email_provider_2 = {
'current_month_billable_sms': 0, 'current_month_billable_sms': 0,
} }
sms_provider_intl_1 = {
@pytest.fixture
def sms_provider_intl_1():
return {
'id': 'sms_provider_intl_1-id', 'id': 'sms_provider_intl_1-id',
'active': False, 'active': False,
'priority': 10, 'priority': 10,
@@ -77,7 +91,10 @@ sms_provider_intl_1 = {
'current_month_billable_sms': 0, 'current_month_billable_sms': 0,
} }
sms_provider_intl_2 = {
@pytest.fixture
def sms_provider_intl_2():
return {
'id': 'sms_provider_intl_2-id', 'id': 'sms_provider_intl_2-id',
'active': False, 'active': False,
'priority': 10, 'priority': 10,
@@ -93,7 +110,14 @@ sms_provider_intl_2 = {
@pytest.fixture @pytest.fixture
def stub_providers(): def stub_providers(
sms_provider_1,
sms_provider_2,
email_provider_1,
email_provider_2,
sms_provider_intl_1,
sms_provider_intl_2,
):
return { return {
'provider_details': [ 'provider_details': [
sms_provider_1, sms_provider_1,
@@ -294,6 +318,7 @@ def test_edit_sms_provider_provider_ratio(
platform_admin_user, platform_admin_user,
mocker, mocker,
stub_providers, stub_providers,
sms_provider_1
): ):
mocker.patch( mocker.patch(
'app.provider_client.get_all_providers', 'app.provider_client.get_all_providers',
@@ -317,15 +342,13 @@ def test_edit_sms_provider_provider_ratio_only_shows_active_providers(
platform_admin_user, platform_admin_user,
mocker, mocker,
stub_providers, stub_providers,
sms_provider_1,
): ):
sms_provider_1_inactive = copy.deepcopy(sms_provider_1) sms_provider_1['active'] = False
sms_provider_1_inactive['active'] = False
mocker.patch( mocker.patch(
'app.provider_client.get_all_providers', 'app.provider_client.get_all_providers',
return_value={ return_value=stub_providers,
'provider_details': [sms_provider_1_inactive, sms_provider_2]
}
) )
client_request.login(platform_admin_user) client_request.login(platform_admin_user)