def test_anonymous_user_can_submit_county_selection(self): self.be_anonymous() with self.assertLogs( 'project.services.logging_service', logging.INFO) as logs: response = self.client.fill_form( reverse('intake-apply'), counties=['contracosta'], confirm_county_selection='yes', headers={'HTTP_USER_AGENT': 'tester'}) self.assertRedirects(response, reverse('intake-county_application')) applicant_id = self.client.session.get('applicant_id') self.assertTrue(applicant_id) applicant = models.Applicant.objects.get(id=applicant_id) self.assertTrue(applicant) self.assertTrue(applicant.visitor_id) visitor = models.Visitor.objects.get(id=applicant.visitor_id) self.assertTrue(visitor) self.assertEqual(len(logs.output), 4) assertInLogsCount(logs, { 'event_name=site_entered': 1, 'event_name=page_viewed': 1, 'event_name=application_started': 1, 'event_name=application_page_complete': 1, 'call_to_mixpanel': 4, 'distinct_id=' + visitor.get_uuid(): 4, }) assertInLogs( logs, 'user_agent', 'referrer', 'source', 'counties', 'contracosta' )
def test_anonymous_user_can_submit_county_selection(self): self.be_anonymous() with self.assertLogs('project.services.logging_service', logging.INFO) as logs: response = self.client.fill_form( reverse('intake-apply'), counties=['contracosta'], headers={'HTTP_USER_AGENT': 'tester'}) self.assertRedirects(response, reverse('intake-county_application')) applicant_id = self.client.session.get('applicant_id') self.assertTrue(applicant_id) applicant = models.Applicant.objects.get(id=applicant_id) self.assertTrue(applicant) self.assertTrue(applicant.visitor_id) visitor = models.Visitor.objects.get(id=applicant.visitor_id) self.assertTrue(visitor) self.assertEqual(len(logs.output), 4) assertInLogsCount( logs, { 'event_name=site_entered': 1, 'event_name=page_viewed': 1, 'event_name=application_started': 1, 'event_name=application_page_complete': 1, 'call_to_mixpanel': 4, 'distinct_id=' + visitor.get_uuid(): 4, }) assertInLogs(logs, 'user_agent', 'referrer', 'source', 'counties', 'contracosta')
def test_logs_validation_errors_event(self): with self.assertLogs('project.services.logging_service', logging.INFO) as logs: response = self.client.fill_form(reverse('intake-apply')) assertInLogs(logs, 'application_errors') assertInLogs(logs, 'distinct_id=' + response.wsgi_request.visitor.get_uuid())
def test_logs_validation_errors_event(self): with self.assertLogs( 'project.services.logging_service', logging.INFO) as logs: response = self.client.fill_form( reverse('intake-apply'), confirm_county_selection='yes') assertInLogs(logs, 'application_errors') assertInLogs( logs, 'distinct_id=' + response.wsgi_request.visitor.get_uuid())
def test_notifies_admin_if_mailgun_api_error(self, mock_email_admins, mock_mailgun_service): mock_mailgun_service.side_effect = MailgunAPIError( "Mailgun responded with 404") with self.assertLogs('project.services.logging_service', logging.ERROR) as logs: mailgun_email_validator('*****@*****.**') assertInLogs(logs, 'mailgun_api_error') self.assertEqual(1, len(mock_email_admins.mock_calls))
def test_notifies_admin_if_mailgun_api_error( self, mock_email_admins, mock_mailgun_service): mock_mailgun_service.side_effect = MailgunAPIError( "Mailgun responded with 404") with self.assertLogs( 'project.services.logging_service', logging.ERROR) as logs: mailgun_email_validator('*****@*****.**') assertInLogs(logs, 'mailgun_api_error') self.assertEqual(1, len(mock_email_admins.mock_calls))
def test_logs_page_complete_and_application_started(self): with self.assertLogs('project.services.logging_service', logging.INFO) as logs: self.client.fill_form(reverse('intake-apply'), counties=['alameda', 'contracosta']) assertInLogsCount( logs, { 'event_name=application_page_complete': 1, 'event_name=application_started': 1, }) assertInLogs(logs, 'alameda', 'contracosta')
def test_logs_page_complete_and_application_started(self): with self.assertLogs( 'project.services.logging_service', logging.INFO) as logs: self.client.fill_form( reverse('intake-apply'), counties=['alameda', 'contracosta'], confirm_county_selection='yes') assertInLogsCount( logs, { 'event_name=application_page_complete': 1, 'event_name=application_started': 1, }) assertInLogs(logs, 'alameda', 'contracosta')