Add the yearly free limit to the service model.

This allows us to reference it across the API code base and return it in the API.

But not currently attached to the service DB model - a static method on the class.
This commit is contained in:
Martyn Inglis
2017-06-06 14:49:05 +01:00
parent 18dcc10a06
commit 75bf693f44
4 changed files with 22 additions and 2 deletions

View File

@@ -239,6 +239,8 @@ class Config(object):
}
}
FREE_SMS_TIER_FRAGMENT_COUNT = 250000
######################
# Config overrides ###

View File

@@ -217,6 +217,10 @@ class Service(db.Model, Versioned):
self.can_send_letters = LETTER_TYPE in [p.permission for p in self.permissions]
self.can_send_international_sms = INTERNATIONAL_SMS_TYPE in [p.permission for p in self.permissions]
@staticmethod
def free_sms_fragment_limit():
return current_app.config['FREE_SMS_TIER_FRAGMENT_COUNT']
@classmethod
def from_json(cls, data):
"""

View File

@@ -25,9 +25,8 @@ from notifications_utils.recipients import (
from app import ma
from app import models
from app.models import ServicePermission, INTERNATIONAL_SMS_TYPE, SMS_TYPE, LETTER_TYPE, EMAIL_TYPE
from app.models import ServicePermission, INTERNATIONAL_SMS_TYPE, LETTER_TYPE
from app.dao.permissions_dao import permission_dao
from app.dao.service_permissions_dao import dao_fetch_service_permissions
from app.utils import get_template_instance
@@ -176,6 +175,7 @@ class ProviderDetailsHistorySchema(BaseSchema):
class ServiceSchema(BaseSchema):
free_sms_fragment_limit = fields.Method('get_free_sms_fragment_limit')
created_by = field_for(models.Service, 'created_by', required=True)
organisation = field_for(models.Service, 'organisation')
branding = field_for(models.Service, 'branding')
@@ -183,6 +183,9 @@ class ServiceSchema(BaseSchema):
permissions = fields.Method("service_permissions")
override_flag = False
def get_free_sms_fragment_limit(selfs, service):
return service.free_sms_fragment_limit()
def service_permissions(self, service):
return [p.permission for p in service.permissions]

View File

@@ -147,6 +147,17 @@ def test_get_service_by_id(client, sample_service):
assert json_resp['data']['sms_sender'] == current_app.config['FROM_NUMBER']
def test_get_service_by_id_returns_free_sms_limit(client, sample_service):
auth_header = create_authorization_header()
resp = client.get(
'/service/{}'.format(sample_service.id),
headers=[auth_header]
)
assert resp.status_code == 200
json_resp = json.loads(resp.get_data(as_text=True))
assert json_resp['data']['free_sms_fragment_limit'] == 250000
def test_get_service_list_has_default_permissions(client, service_factory):
service_factory.get('one')
service_factory.get('two')