Skip to content

Commit

Permalink
Cambio del subject de reportes
Browse files Browse the repository at this point in the history
- Se ubica el nombre del nodo en el asunto
- Se modifica 'API de Series de Tiempo' por 'Validación de series de tiempo'
  • Loading branch information
lucaslavandeira committed Nov 22, 2019
1 parent a28fce9 commit 841afa5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ def generate_context(self, node):

def send_email(self, context, node=None):
start_time = self._format_date(self.task.created)
subject = f'[{settings.ENV_TYPE}] API Series de Tiempo: {start_time}'
subject = self._subject(start_time, node)
html_msg = render_to_string('indexing/report.html', context=context)
admins = NodeAdmins(node) if node else GlobalAdmins()

sender = ReportMailSender(admins=admins, subject=subject, body=html_msg)
self.add_attachments(sender, node)
sender.send()

def _subject(self, start_time, node=None):
if node is None:
return f'[{settings.ENV_TYPE}] Validación de series de tiempo: {start_time}'

return f'[{settings.ENV_TYPE}] Validación de series de tiempo {node.catalog_id}: {start_time}'

def add_attachments(self, mail_sender, node):
mail_attachments = (
('catalogs.csv', attachments.generate_catalog_attachment(node=node)),
Expand Down
7 changes: 7 additions & 0 deletions series_tiempo_ar_api/libs/indexing/tests/report_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,12 @@ def test_error_logs_for_single_node_does_not_have_other_catalog_errors(self, *_)
log_body = mail.outbox[1].attachments[-1][1]
self.assertNotIn(other_id, log_body)

def test_subject_includes_catalog_id(self, *_):
self.index_catalog('test_catalog', os.path.join(SAMPLES_DIR, 'one_distribution_ok_one_error.json'))
Node.objects.get(catalog_id='test_catalog').admins.add(User.objects.first())
ReportGenerator(self.task).generate()
subject = mail.outbox[1].subject
self.assertIn('test_catalog', subject)

def index_catalog(self, catalog_id, catalog_path):
index_catalog(catalog_id, catalog_path, self.mock_index)

0 comments on commit 841afa5

Please sign in to comment.