mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
403 when creating a letter job in trial mode
This commit is contained in:
@@ -32,7 +32,7 @@ from app.schemas import (
|
|||||||
|
|
||||||
from app.celery.tasks import process_job
|
from app.celery.tasks import process_job
|
||||||
|
|
||||||
from app.models import JOB_STATUS_SCHEDULED, JOB_STATUS_PENDING, JOB_STATUS_CANCELLED
|
from app.models import JOB_STATUS_SCHEDULED, JOB_STATUS_PENDING, JOB_STATUS_CANCELLED, LETTER_TYPE
|
||||||
|
|
||||||
from app.utils import pagination_links
|
from app.utils import pagination_links
|
||||||
|
|
||||||
@@ -190,6 +190,9 @@ def create_job(service_id):
|
|||||||
})
|
})
|
||||||
template = dao_get_template_by_id(data['template'])
|
template = dao_get_template_by_id(data['template'])
|
||||||
|
|
||||||
|
if template.template_type == LETTER_TYPE and service.restricted:
|
||||||
|
raise InvalidRequest("Create letter job is not allowed for service in trial mode ", 403)
|
||||||
|
|
||||||
errors = unarchived_template_schema.validate({'archived': template.archived})
|
errors = unarchived_template_schema.validate({'archived': template.archived})
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
|
|||||||
@@ -186,6 +186,29 @@ def test_create_job_returns_403_if_service_is_not_active(client, fake_uuid, samp
|
|||||||
mock_job_dao.assert_not_called()
|
mock_job_dao.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_job_returns_403_if_letter_template_type_and_service_in_trial(
|
||||||
|
client, fake_uuid, sample_service, sample_trial_letter_template, mocker):
|
||||||
|
data = {
|
||||||
|
'id': fake_uuid,
|
||||||
|
'service': str(sample_trial_letter_template.service.id),
|
||||||
|
'template': str(sample_trial_letter_template.id),
|
||||||
|
'original_file_name': 'thisisatest.csv',
|
||||||
|
'notification_count': 1,
|
||||||
|
'created_by': str(sample_trial_letter_template.created_by.id)
|
||||||
|
}
|
||||||
|
mock_job_dao = mocker.patch("app.dao.jobs_dao.dao_create_job")
|
||||||
|
auth_header = create_authorization_header()
|
||||||
|
response = client.post('/service/{}/job'.format(sample_service.id),
|
||||||
|
data=json.dumps(data),
|
||||||
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
|
assert response.status_code == 403
|
||||||
|
resp_json = json.loads(response.get_data(as_text=True))
|
||||||
|
assert resp_json['result'] == 'error'
|
||||||
|
assert resp_json['message'] == "Create letter job is not allowed for service in trial mode "
|
||||||
|
mock_job_dao.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_create_scheduled_job_more_then_24_hours_hence(notify_api, sample_template, mocker, fake_uuid):
|
def test_should_not_create_scheduled_job_more_then_24_hours_hence(notify_api, sample_template, mocker, fake_uuid):
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
|
|||||||
Reference in New Issue
Block a user