Esempio n. 1
0
    def test_submission_site_validation(self):
        """ Test creating a submission from a message with site provided. """

        callback = lambda: Submission.from_message(
            self.m, Site.objects.get(domain=self.sites[0]))
        self.assertRaises(ValidationError, callback)
        callback = lambda: Submission.from_message(self.m, None)
        self.assertRaises(ValidationError, callback)
Esempio n. 2
0
    def test_changelist(self):
        """ Testing submission admin change list display. """

        # Assure there's a submission
        Submission.from_message(self.message)

        response = self.client.get(self.changelist_url)
        self.assertContains(
            response, '<td class="field-admin_status_text">Not sent.</td>')
Esempio n. 3
0
    def test_changelist(self):
        """ Testing submission admin change list display. """

        # Assure there's a submission
        Submission.from_message(self.message)

        response = self.client.get(self.changelist_url)
        self.assertContains(
            response,
            '<td class="field-admin_status_text">Not sent.</td>'
        )
Esempio n. 4
0
def putWeekReport(report, newsletter):

    # if nothing changed, nothing to report, moving on.
    if report['db_changes'] == None and report['discussion'] == None and report['characteristic'] == None:
        return

    now = timezone.now()

    mess = Message(title=newsletter.title+" - Recent Changes - "+now.strftime("%Y-%m-%d %H:%M"),slug=newsletter.slug+'_'+now.strftime("%Y%m%d%H%M%S"), newsletter=newsletter)
    mess.save()

    if report['db_changes'] != None:
        art = Article(title="Changes on Database:", text=report['db_changes'], post=mess)
        art.save()

    if report['discussion'] != None:
        art2 = Article(title="New Discussion:", text=report['discussion'], post=mess)
        art2.save()

    if report['characteristic'] != None:
        art3 = Article(title="New Population Characteristic Data:", text=report['characteristic'], post=mess)
        art3.save()

    subm = Submission.from_message(mess)

    subm.prepared = True

    subm.save()
Esempio n. 5
0
    def test_duplicate_fail(self):
        """ Test that a message cannot be published twice. """

        # Assure there's a submission
        Submission.from_message(self.message)

        response = self.client.post(self.add_url, data={
            'message': self.message.pk,
            'publish_date_0': '2016-01-09',
            'publish_date_1': '07:24',
            'publish': 'on',
        })
        self.assertContains(
            response,
            "This message has already been published in some other submission."
        )
Esempio n. 6
0
    def test_duplicate_fail(self):
        """ Test that a message cannot be published twice. """

        # Assure there's a submission
        Submission.from_message(self.message)

        response = self.client.post(self.add_url, data={
            'message': self.message.pk,
            'publish_date_0': '2016-01-09',
            'publish_date_1': '07:24',
            'publish': 'on',
        })
        self.assertContains(
            response,
            "This message has already been published in some other submission."
        )
Esempio n. 7
0
    def test_submission_subscribed(self):
        """ Test a simple submission with single subscriber. """

        self.s.subscribed = False
        self.s.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(list(subscriptions), [self.s2])
Esempio n. 8
0
    def test_submission_unsubscribed(self):
        """ Test submission with unsubscribed activated subscriber. """

        self.s.unsubscribed = True
        self.s.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(list(subscriptions), [self.s2])
Esempio n. 9
0
    def test_submission_subscribed(self):
        """ Test a simple submission with single subscriber. """

        self.s.subscribed = False
        self.s.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(list(subscriptions), [self.s2])
Esempio n. 10
0
    def test_submission_unsubscribed(self):
        """ Test submission with unsubscribed activated subscriber. """

        self.s.unsubscribed = True
        self.s.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(list(subscriptions), [self.s2])
Esempio n. 11
0
    def test_submission_from_message(self):
        """ Test creating a submission from a message. """

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(set(subscriptions), {self.s, self.s2})

        self.assertFalse(sub.prepared)
        self.assertFalse(sub.sent)
        self.assertFalse(sub.sending)
Esempio n. 12
0
    def test_submission_from_message(self):
        """ Test creating a submission from a message. """

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(set(subscriptions), {self.s, self.s2})

        self.assertFalse(sub.prepared)
        self.assertFalse(sub.sent)
        self.assertFalse(sub.sending)
Esempio n. 13
0
    def test_twosubmissions_unsubscried(self):
        """ Test submission with two subscribers, one unactivated. """

        s2 = Subscription(name='Test Name 2',
                          email='*****@*****.**',
                          newsletter=self.n,
                          subscribed=False)
        s2.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(list(subscriptions), [self.s])
Esempio n. 14
0
    def test_twosubmissions_unsubscried(self):
        """ Test submission with two subscribers, one unactivated. """

        s2 = Subscription(
            name='Test Name 2', email='*****@*****.**',
            newsletter=self.n, subscribed=False
        )
        s2.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(list(subscriptions), [self.s])
Esempio n. 15
0
    def test_submission_from_message(self):
        """ Test creating a submission from a message. """

        sub = Submission.from_message(self.m, self.get_site())
        unsubscribe_link = sub.extra_headers['List-Unsubscribe']
        self.assertIn(self.get_site().domain, unsubscribe_link)

        subscriptions = sub.subscriptions.all()
        self.assertEqual(set(subscriptions), {self.s, self.s2})

        self.assertFalse(sub.prepared)
        self.assertFalse(sub.sent)
        self.assertFalse(sub.sending)
Esempio n. 16
0
    def send_email(self, action):
        assert action in ACTIONS + ('message', ), 'Unknown action: %s' % action

        if action == 'message':
            # Create submission
            sub = Submission.from_message(self.m)
            sub.prepared = True
            sub.publish_date = now() - timedelta(seconds=1)
            sub.save()

            # Send message email
            Submission.submit_queue()
        else:
            self.s.send_activation_email(action)
Esempio n. 17
0
    def test_twosubmissions(self):
        """ Test submission with two activated subscribers. """

        s2 = Subscription(name='Test Name 2',
                          email='*****@*****.**',
                          newsletter=self.n,
                          subscribed=True)
        s2.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertTrue(self.s in list(subscriptions))
        self.assertTrue(s2 in list(subscriptions))
Esempio n. 18
0
    def test_twosubmissions(self):
        """ Test submission with two activated subscribers. """

        s2 = Subscription(
            name='Test Name 2', email='*****@*****.**',
            newsletter=self.n, subscribed=True
        )
        s2.save()

        sub = Submission.from_message(self.m)

        subscriptions = sub.subscriptions.all()
        self.assertTrue(self.s in list(subscriptions))
        self.assertTrue(s2 in list(subscriptions))
Esempio n. 19
0
    def send_email(self, action):
        assert action in ACTIONS + ('message', ), 'Unknown action: %s' % action

        if action == 'message':
            # Create submission
            sub = Submission.from_message(self.m)
            sub.prepared = True
            sub.publish_date = now() - timedelta(seconds=1)
            sub.save()

            # Send message email
            Submission.submit_queue()
        else:
            self.s.send_activation_email(action)
Esempio n. 20
0
    def send_email(self, action):
        assert action in ACTIONS + ('message', ), 'Unknown action: %s' % action

        if action == 'message':
            # Create submission
            sub = Submission.from_message(self.m, Site.objects.get_current())
            sub.prepared = True
            sub.publish_date = now() - timedelta(seconds=1)
            sub.save()

            # Send message email
            Submission.submit_queue()
        else:
            for subscriber in self.n.get_subscriptions():
                subscriber.send_activation_email(Site.objects.get_current(),
                                                 action)
Esempio n. 21
0
    def setUp(self):
        """ Make sure we have a few submissions to test with. """

        # Pick some newsletter
        try:
            self.newsletter = Newsletter.objects.all()[0]
        except IndexError:
            self.newsletter = None

        # Create a message first
        message = Message.objects.create(
            title='Test message',
            slug='test-message',
            newsletter=self.newsletter,
        )

        # Make sure there's a HTML template for this newsletter,
        # otherwise the archive will not function.
        self.assertTrue(message.html_template)

        # Create a submission
        self.submission = Submission.from_message(message)
Esempio n. 22
0
    def setUp(self):
        """ Make sure we have a few submissions to test with. """

        # Pick some newsletter
        try:
            self.newsletter = Newsletter.objects.all()[0]
        except IndexError:
            self.newsletter = None

        # Create a message first
        message = Message.objects.create(
            title='Test message',
            slug='test-message',
            newsletter=self.newsletter,
        )

        # Make sure there's a HTML template for this newsletter,
        # otherwise the archive will not function.
        self.assertTrue(message.html_template)

        # Create a submission
        self.submission = Submission.from_message(message)
Esempio n. 23
0
def putWeekReport(report, newsletter):

    # if nothing changed, nothing to report, moving on.
    if report['db_changes'] == None and report[
            'discussion'] == None and report['characteristic'] == None:
        return

    now = timezone.now()

    mess = Message(title=newsletter.title + " - Recent Changes - " +
                   now.strftime("%Y-%m-%d %H:%M"),
                   slug=newsletter.slug + '_' + now.strftime("%Y%m%d%H%M%S"),
                   newsletter=newsletter)
    mess.save()

    if report['db_changes'] != None:
        art = Article(title="Changes on Database:",
                      text=report['db_changes'],
                      post=mess)
        art.save()

    if report['discussion'] != None:
        art2 = Article(title="New Discussion:",
                       text=report['discussion'],
                       post=mess)
        art2.save()

    if report['characteristic'] != None:
        art3 = Article(title="New Population Characteristic Data:",
                       text=report['characteristic'],
                       post=mess)
        art3.save()

    subm = Submission.from_message(mess)

    subm.prepared = True

    subm.save()
Esempio n. 24
0
    def setUp(self):
        super(SubmitSubmissionTestCase, self).setUp()

        self.sub = Submission.from_message(self.m)
        self.sub.save()
Esempio n. 25
0
    def setUp(self):
        super(SubmitSubmissionTestCase, self).setUp()

        self.sub = Submission.from_message(self.m)
        self.sub.save()
Esempio n. 26
0
    def setUp(self):
        super().setUp()

        self.sub = Submission.from_message(self.m)
        self.sub.save()