<commit_before>from callisto_core.notification.models import EmailNotification

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase

from ..delivery import models

User = get_user_model()


class ReportAssertionHelper(object):

    def assert_report_exists(self):
        return bool(models.Report.objects.filter(pk=self.report.pk).count())

    def match_report_email_assertions(self):
        self.assertEqual(len(mail.outbox), 3)
        message = mail.outbox[0]
        self.assertEqual(message.subject, 'test match notification')
        self.assertEqual(message.to, ['<EMAIL>'])
        self.assertIn('Matching" <notification@', message.from_email)
        self.assertIn('test match notification body', message.body)
        message = mail.outbox[1]
        self.assertEqual(message.subject, 'test match notification')
        self.assertEqual(message.to, ['<EMAIL>'])
        self.assertIn('Matching" <notification@', message.from_email)
        self.assertIn('test match notification body', message.body)
        message = mail.outbox[2]
        self.assertEqual(message.subject, 'test match delivery')
        self.assertEqual(message.to, ['<EMAIL>'])
        self.assertIn('"Reports" <reports@', message.from_email)
        self.assertIn('test match delivery body', message.body)
        self.assertRegexpMatches(
            message.attachments[0][0],
            'report_.*\\.pdf\\.gpg')


class ReportPostHelper(object):

    def client_post_report_creation(self):
        response = self.client.post(
            reverse('report_new'),
            data={
                'key': self.secret_key,
                'key_confirmation': self.secret_key,
            },
            follow=True,
        )
        self.report = response.context['report']
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_get_report_delete(self):
        response = self.client.get(
            reverse(
                'report_delete',
                kwargs={
                    'uuid': self.report.uuid,
                },
            ),
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_get_report_view_pdf(self):
        response = self.client.get(
            reverse(
                'report_view_pdf',
                kwargs={
                    'uuid': self.report.uuid,
                },
            ),
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_question_answer(self, url, answer):
        response = self.client.post(
            url,
            data=answer,
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_report_access(self, url):
        response = self.client.post(
            url,
            data={
                'key': self.secret_key,
            },
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_report_prep(self):
        response = self.client.post(
            reverse(
                'reporting_prep',
                kwargs={'uuid': self.report.uuid},
            ),
            data={
                'contact_email': '<EMAIL>',
                'contact_phone': '555-555-5555',
            },
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_matching_enter_empty(self):
        response = self.client.post(
            reverse(
                'report_matching_enter',
                kwargs={'uuid': self.report.uuid},
            ),
            data={
                'identifier': 'INVALID',
            },
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_matching_enter(self):
        response = self.client.post(
            reverse(
                'report_matching_enter',<commit_msg>make empty POST test actually empty<commit_after>from callisto_core.notification.models import EmailNotification

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase

from ..delivery import models

User = get_user_model()


class ReportAssertionHelper(object):

    def assert_report_exists(self):
        return bool(models.Report.objects.filter(pk=self.report.pk).count())

    def match_report_email_assertions(self):
        self.assertEqual(len(mail.outbox), 3)
        message = mail.outbox[0]
        self.assertEqual(message.subject, 'test match notification')
        self.assertEqual(message.to, ['<EMAIL>'])
        self.assertIn('Matching" <notification@', message.from_email)
        self.assertIn('test match notification body', message.body)
        message = mail.outbox[1]
        self.assertEqual(message.subject, 'test match notification')
        self.assertEqual(message.to, ['<EMAIL>'])
        self.assertIn('Matching" <notification@', message.from_email)
        self.assertIn('test match notification body', message.body)
        message = mail.outbox[2]
        self.assertEqual(message.subject, 'test match delivery')
        self.assertEqual(message.to, ['<EMAIL>'])
        self.assertIn('"Reports" <reports@', message.from_email)
        self.assertIn('test match delivery body', message.body)
        self.assertRegexpMatches(
            message.attachments[0][0],
            'report_.*\\.pdf\\.gpg')


class ReportPostHelper(object):

    def client_post_report_creation(self):
        response = self.client.post(
            reverse('report_new'),
            data={
                'key': self.secret_key,
                'key_confirmation': self.secret_key,
            },
            follow=True,
        )
        self.report = response.context['report']
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_get_report_delete(self):
        response = self.client.get(
            reverse(
                'report_delete',
                kwargs={
                    'uuid': self.report.uuid,
                },
            ),
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_get_report_view_pdf(self):
        response = self.client.get(
            reverse(
                'report_view_pdf',
                kwargs={
                    'uuid': self.report.uuid,
                },
            ),
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_question_answer(self, url, answer):
        response = self.client.post(
            url,
            data=answer,
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_report_access(self, url):
        response = self.client.post(
            url,
            data={
                'key': self.secret_key,
            },
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_report_prep(self):
        response = self.client.post(
            reverse(
                'reporting_prep',
                kwargs={'uuid': self.report.uuid},
            ),
            data={
                'contact_email': '<EMAIL>',
                'contact_phone': '555-555-5555',
            },
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_matching_enter_empty(self):
        response = self.client.post(
            reverse(
                'report_matching_enter',
                kwargs={'uuid': self.report.uuid},
            ),
            data={
                'identifier': '',
            },
            follow=True,
        )
        self.assertIn(response.status_code, [200, 301, 302])
        return response

    def client_post_matching_enter(self):
        response = self.client.post(
            reverse(
                'report_matching_enter',
{'fraction_non_alphanumeric': 0.1087492660011744, 'fraction_numerical': 0.018555490311215502, 'mean_word_length': 1.9467128027681662, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1663602', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2263, 'n_words': 445}