mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Merge pull request #189 from alphagov/job-metadata
Add count of rows in csv file as a notification count.
This commit is contained in:
@@ -127,7 +127,7 @@ def check_sms(service_id, upload_id):
|
||||
template_id = upload_data.get('template_id')
|
||||
raw_template = templates_dao.get_service_template_or_404(service_id, template_id)['data']
|
||||
upload_result = _get_rows(contents, raw_template)
|
||||
print(upload_result)
|
||||
session['upload_data']['notification_count'] = len(upload_result['rows'])
|
||||
template = Template(
|
||||
raw_template,
|
||||
values=upload_result['rows'][0] if upload_result['valid'] else {},
|
||||
@@ -148,9 +148,10 @@ def check_sms(service_id, upload_id):
|
||||
upload_data = session['upload_data']
|
||||
original_file_name = upload_data.get('original_file_name')
|
||||
template_id = upload_data.get('template_id')
|
||||
notification_count = upload_data.get('notification_count')
|
||||
session.pop('upload_data')
|
||||
try:
|
||||
job_api_client.create_job(upload_id, service_id, template_id, original_file_name)
|
||||
job_api_client.create_job(upload_id, service_id, template_id, original_file_name, notification_count)
|
||||
except HTTPError as e:
|
||||
if e.status_code == 404:
|
||||
abort(404)
|
||||
|
||||
@@ -20,14 +20,15 @@ class JobApiClient(BaseAPIClient):
|
||||
else:
|
||||
return self.get(url='/service/{}/job'.format(service_id))
|
||||
|
||||
def create_job(self, job_id, service_id, template_id, original_file_name):
|
||||
def create_job(self, job_id, service_id, template_id, original_file_name, notification_count):
|
||||
data = {
|
||||
"id": job_id,
|
||||
"service": service_id,
|
||||
"template": template_id,
|
||||
"original_file_name": original_file_name,
|
||||
"bucket_name": "service-{}-notify".format(service_id),
|
||||
"file_name": "{}.csv".format(job_id)
|
||||
"file_name": "{}.csv".format(job_id),
|
||||
"notification_count": notification_count
|
||||
}
|
||||
|
||||
resp = self.post(url='/service/{}/job'.format(service_id), data=data)
|
||||
|
||||
@@ -95,6 +95,7 @@ def job_json():
|
||||
'original_file_name': 'thisisatest.csv',
|
||||
'bucket_name': 'service-1-{}-notify'.format(job_id),
|
||||
'file_name': '{}.csv'.format(job_id),
|
||||
'created_at': created_at
|
||||
'created_at': created_at,
|
||||
'notification_count': 1
|
||||
}
|
||||
return data
|
||||
|
||||
@@ -7,6 +7,7 @@ def test_client_creates_job_data_correctly(mocker):
|
||||
service_id = str(uuid.uuid4())
|
||||
template_id = 1
|
||||
original_file_name = 'test.csv'
|
||||
notification_count = 1
|
||||
|
||||
expected_data = {
|
||||
"id": job_id,
|
||||
@@ -14,7 +15,8 @@ def test_client_creates_job_data_correctly(mocker):
|
||||
"template": template_id,
|
||||
"original_file_name": original_file_name,
|
||||
"bucket_name": "service-{}-notify".format(service_id),
|
||||
"file_name": "{}.csv".format(job_id)
|
||||
"file_name": "{}.csv".format(job_id),
|
||||
"notification_count": 1
|
||||
}
|
||||
|
||||
expected_url = '/service/{}/job'.format(service_id)
|
||||
@@ -22,6 +24,6 @@ def test_client_creates_job_data_correctly(mocker):
|
||||
client = JobApiClient()
|
||||
mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')
|
||||
|
||||
client.create_job(job_id, service_id, template_id, original_file_name)
|
||||
client.create_job(job_id, service_id, template_id, original_file_name, notification_count)
|
||||
|
||||
mock_post.assert_called_once_with(url=expected_url, data=expected_data)
|
||||
|
||||
@@ -136,16 +136,20 @@ def test_upload_csvfile_with_valid_phone_shows_all_numbers(app_,
|
||||
response = client.post(url_for('main.send_sms', service_id=12345, template_id=54321),
|
||||
data=upload_data,
|
||||
follow_redirects=True)
|
||||
with client.session_transaction() as sess:
|
||||
assert int(sess['upload_data']['template_id']) == 54321
|
||||
assert sess['upload_data']['original_file_name'] == 'valid.csv'
|
||||
assert sess['upload_data']['notification_count'] == 6
|
||||
|
||||
content = response.get_data(as_text=True)
|
||||
content = response.get_data(as_text=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert '+44 7700 900981' in content
|
||||
assert '+44 7700 900982' in content
|
||||
assert '+44 7700 900983' in content
|
||||
assert '+44 7700 900984' in content
|
||||
assert '+44 7700 900985' in content
|
||||
assert '+44 7700 900986' in content
|
||||
assert response.status_code == 200
|
||||
assert '+44 7700 900981' in content
|
||||
assert '+44 7700 900982' in content
|
||||
assert '+44 7700 900983' in content
|
||||
assert '+44 7700 900984' in content
|
||||
assert '+44 7700 900985' in content
|
||||
assert '+44 7700 900986' in content
|
||||
|
||||
|
||||
@moto.mock_s3
|
||||
@@ -164,15 +168,18 @@ def test_create_job_should_call_api(app_,
|
||||
job_id = job_data['id']
|
||||
original_file_name = job_data['original_file_name']
|
||||
template_id = job_data['template']
|
||||
notification_count = job_data['notification_count']
|
||||
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
with client.session_transaction() as session:
|
||||
session['upload_data'] = {'original_file_name': original_file_name, 'template_id': template_id}
|
||||
session['upload_data'] = {'original_file_name': original_file_name,
|
||||
'template_id': template_id,
|
||||
'notification_count': notification_count}
|
||||
url = url_for('main.check_sms', service_id=service_one['id'], upload_id=job_id)
|
||||
response = client.post(url, data=job_data, follow_redirects=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'We’ve started sending your messages' in response.get_data(as_text=True)
|
||||
mock_create_job.assert_called_with(job_id, service_id, template_id, original_file_name)
|
||||
mock_create_job.assert_called_with(job_id, service_id, template_id, original_file_name, notification_count)
|
||||
|
||||
@@ -468,13 +468,14 @@ def job_data():
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_create_job(mocker, job_data):
|
||||
def _create(job_id, service_id, template_id, file_name):
|
||||
def _create(job_id, service_id, template_id, file_name, notification_count):
|
||||
job_data['id'] = job_id
|
||||
job_data['service'] = service_id
|
||||
job_data['template'] = template_id
|
||||
job_data['bucket_name'] = 'service-{}-notify'.format(job_id)
|
||||
job_data['original_file_name'] = file_name
|
||||
job_data['file_name'] = '{}.csv'.format(job_id)
|
||||
job_data['notification_count'] = notification_count
|
||||
return job_data
|
||||
return mocker.patch('app.job_api_client.create_job', side_effect=_create)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user