Exemplo n.º 1
0
class TestRemoveEmailsOlders(TestCase):
    """Test command erase_emails, if older emails are removed"""
    def setUp(self):
        # Create two reports
        self.old_report = ReportFactory(email="*****@*****.**")
        self.recent_report = ReportFactory(email="*****@*****.**")

        # Modify date_insert for old_report
        one_year_one_day = timezone.timedelta(days=370)
        self.old_report.date_insert = timezone.now() - one_year_one_day
        self.old_report.save()

    def test_erase_old_emails(self):
        output = StringIO()
        call_command('erase_emails', stdout=output)
        old_report = Report.objects.get(id=self.old_report.id)
        self.assertEqual(old_report.email, "")
        self.assertEqual(old_report.__str__(), "Anonymous report")

    def test_dry_run_command(self):
        """Test if dry_run mode keeps emails"""
        output = StringIO()
        call_command('erase_emails', dry_run=True, stdout=output)
        old_report = Report.objects.get(id=self.old_report.id)
        self.assertEqual(old_report.email, "*****@*****.**")
Exemplo n.º 2
0
 def test_email_format_and_content(self):
     ReportFactory.create(email='*****@*****.**',
                          comment="This is a 'comment'")
     sent_mail = mail.outbox[0]
     self.assertEqual(sent_mail.subject,
                      '[Geotrek] Feedback from [email protected]')
     self.assertIn("Comment : This is a 'comment'", sent_mail.body)
     self.assertIn("Lat : 46.500000 / Lon : 3.000000", sent_mail.body)
Exemplo n.º 3
0
    def setUp(self):
        # Create two reports
        self.old_report = ReportFactory(email="*****@*****.**")
        self.recent_report = ReportFactory(email="*****@*****.**")

        # Modify date_insert for old_report
        one_year_one_day = timezone.timedelta(days=370)
        self.old_report.date_insert = timezone.now() - one_year_one_day
        self.old_report.save()
Exemplo n.º 4
0
 def test_email_format_and_content(self):
     ReportFactory.create(name=u'John Doe',
                          email=u'*****@*****.**',
                          comment=u'This is a comment')
     sent_mail = mail.outbox[0]
     self.assertEquals(sent_mail.subject,
                       u'[Geotrek] Feedback from John Doe ([email protected])')
     self.assertIn(u"Comment : This is a comment", sent_mail.body)
     self.assertIn(u"Lat : 1.13 / Lon : 2.26", sent_mail.body)
Exemplo n.º 5
0
 def test_email_format_and_content(self):
     ReportFactory.create(name=u'John Doe',
                          email=u'*****@*****.**',
                          comment=u'This is a comment')
     sent_mail = mail.outbox[0]
     self.assertEquals(
         sent_mail.subject,
         u'[Geotrek] Feedback from John Doe ([email protected])')
     self.assertIn(u"Comment : This is a comment", sent_mail.body)
     self.assertIn(u"Lat : 46.5 / Lon : 3", sent_mail.body)
Exemplo n.º 6
0
    def test_email_format_and_content_fr(self):
        translation.activate('fr')
        ReportFactory.create(email='*****@*****.**',
                             comment="Ceci est un commentaire")
        sent_mail = mail.outbox[0]
        self.assertEqual(
            sent_mail.subject,
            '[Geotrek] Signalement de [email protected]')
        self.assertIn("Commentaire : Ceci est un commentaire", sent_mail.body)
        self.assertIn("Lat : 46.500000 / Lon : 3.000000", sent_mail.body)
        self.assertIn(
            "http://www.openstreetmap.org/?mlat=46.500000&mlon=3.000000",
            sent_mail.body)

        translation.deactivate()
Exemplo n.º 7
0
    def test_post_request_to_suricate(self, mock_post):
        """Test post request itself
        Request post is mock
        """
        # Create a report without saving it
        report = ReportFactory.build()

        # Define a mock response
        mock_response = mock.Mock()
        expected_dict = {
            "code_ok":
            "true",
            "check":
            "515996edc2da463424f4c6e21e19352f ",
            "message":
            "Merci d’avoir remonté ce problème, nos services vont traiter votre signalement."
        }
        mock_response.json.return_value = expected_dict
        mock_response.status_code = 200

        # Define response for the fake API
        mock_post.return_value = mock_response

        # Call the function with the report
        result = post_report_to_suricate(report)
        self.assertEqual(result, None)
Exemplo n.º 8
0
    def test_save_report_post_to_suricate(self, mock_post_report_to_suricate):
        """Test post to suricate on save Report
        Helper `post_report_to_suricate` function is mock
        """
        # Create a report
        report = ReportFactory()

        # Assert post_report_to_suricate is called
        mock_post_report_to_suricate.assert_called_once_with(report)
Exemplo n.º 9
0
    def test_post_request_to_suricate_fails(self, mock_post):
        """Test post request itself but fails
        Request post is mock
        """
        # Define a mock response
        mock_response = mock.Mock()
        expected_dict = {
            "code_ok": "false",
            "error": {
                "code": "400",
                "message": "Erreur inconnue."
            }
        }
        mock_response.json.return_value = expected_dict
        mock_response.status_code = 400

        # Define response for the fake API
        mock_post.return_value = mock_response

        # Create a report, should raise an excemption
        self.assertRaises(Exception, ReportFactory())
Exemplo n.º 10
0
 def test_email_format_and_content(self):
     ReportFactory.create(name=u"John Doe", email=u"*****@*****.**", comment=u"This is a comment")
     sent_mail = mail.outbox[0]
     self.assertEquals(sent_mail.subject, u"[Geotrek] Feedback from John Doe ([email protected])")
     self.assertIn(u"Comment : This is a comment", sent_mail.body)
     self.assertIn(u"Lat : 46.5 / Lon : 3", sent_mail.body)
Exemplo n.º 11
0
 def test_a_mail_is_not_sent_on_report_modification(self):
     r = ReportFactory.create()
     self.assertEquals(len(mail.outbox), 1)
     r.name = "toto"
     r.save()
     self.assertEquals(len(mail.outbox), 1)
Exemplo n.º 12
0
 def test_email_failure_does_not_prevent_report_creation(self):
     r = ReportFactory.create()
     self.assertEquals(len(mail.outbox), 0)
     self.assertIsNotNone(r.id)
Exemplo n.º 13
0
 def test_a_mail_is_sent_on_report_creation(self):
     ReportFactory.create()
     self.assertEquals(len(mail.outbox), 1)
Exemplo n.º 14
0
 def test_a_mail_is_not_sent_on_report_modification(self):
     r = ReportFactory.create()
     self.assertEqual(len(mail.outbox), 1)
     r.comment = 'More info about it'
     r.save()
     self.assertEqual(len(mail.outbox), 1)
Exemplo n.º 15
0
 def test_email_failure_does_not_prevent_report_creation(self):
     r = ReportFactory.create()
     self.assertEquals(len(mail.outbox), 0)
     self.assertIsNotNone(r.id)
Exemplo n.º 16
0
 def test_a_mail_is_not_sent_on_report_modification(self):
     r = ReportFactory.create()
     self.assertEquals(len(mail.outbox), 1)
     r.name = 'toto'
     r.save()
     self.assertEquals(len(mail.outbox), 1)
Exemplo n.º 17
0
 def test_a_mail_is_sent_on_report_creation(self):
     ReportFactory.create()
     self.assertEquals(len(mail.outbox), 1)