Esempio n. 1
0
    def has_isSubscribed_set_to_true_when_current_user_is_subscribed(self):
        from django.contrib.auth.models import User
        from subscriptions.models import Subscriber, Subscription
        from subscriptions.feeds import ContentFeedLibrary
        from main.feeds import NewLegislationFeed

        subscriber = Subscriber(username="******")
        subscriber.set_password("world")
        subscriber.save()

        library = ContentFeedLibrary()
        library.register(NewLegislationFeed, 'blah blah')

        feed = NewLegislationFeed()
        subscription = subscriber.subscribe(feed)
        subscriber.save()

        # Make the request.
        client = Client()
        assert client.login(username="******", password="******")
        response = client.get('/legislation/')

        # Check the context
        assert response.context['is_subscribed']
        assert_equal(response.context['subscription'], subscription)
Esempio n. 2
0
    def has_isSubscribed_set_to_true_when_current_user_is_subscribed(self):
        from django.contrib.auth.models import User
        from subscriptions.models import Subscriber, Subscription
        from subscriptions.feeds import ContentFeedLibrary
        from main.feeds import NewLegislationFeed

        subscriber = Subscriber(username="******")
        subscriber.set_password("world")
        subscriber.save()

        library = ContentFeedLibrary()
        library.register(NewLegislationFeed, 'blah blah')

        feed = NewLegislationFeed()
        subscription = subscriber.subscribe(feed)
        subscriber.save()

        # Make the request.
        client = Client()
        assert client.login(username="******", password="******")
        response = client.get('/legislation/')

        # Check the context
        assert response.context['is_subscribed']
        assert_equal(response.context['subscription'], subscription)
Esempio n. 3
0
    def causes_the_same_feed_record_to_be_returned_on_different_calls_to_getRecord(self):
        library = ContentFeedLibrary(shared=False)
        library.register(ListItemFeed, 'li')

        feed = ListItemFeed('[1, 2, 3]')
        record = library.get_record(feed)

        assert_is(record, library.get_record(feed))
Esempio n. 4
0
    def causes_the_same_feed_record_to_be_returned_on_different_calls_to_getRecord(self):
        library = ContentFeedLibrary(shared=False)
        library.register(ListItemFeed, 'li')

        feed = ListItemFeed('[1, 2, 3]')
        record = library.get_record(feed)

        assert_is(record, library.get_record(feed))
Esempio n. 5
0
    def doesnt_return_the_same_feed_from_different_libraries(self):
        library1 = ContentFeedLibrary(shared=False)
        library1.register(ListItemFeed, 'li')

        library2 = ContentFeedLibrary(shared=False)
        library2.register(ListItemFeed, 'li')

        feed = ListItemFeed('[1, 2, 3]')
        record = library1.get_record(feed)

        assert_is_not(feed, library2.get_feed(record))
Esempio n. 6
0
    def doesnt_return_the_same_feed_from_different_libraries(self):
        library1 = ContentFeedLibrary(shared=False)
        library1.register(ListItemFeed, 'li')

        library2 = ContentFeedLibrary(shared=False)
        library2.register(ListItemFeed, 'li')

        feed = ListItemFeed('[1, 2, 3]')
        record = library1.get_record(feed)

        assert_is_not(feed, library2.get_feed(record))
Esempio n. 7
0
    def setUp(self):
        class DoNothinView (object):
            def get_context_data(self, **kwargs):
                # This is just so that SingleSubscriptionMixin.get_context_data
                # super has something to call.
                return {}

        library = ContentFeedLibrary(shared=False)
        library.register(ListItemFeed, 'my list item feed')

        class SubscriptionView (SingleSubscriptionMixin, DoNothinView):
            def get_content_feed_library(self):
                return library

            def get_content_feed(self):
                return ListItemFeed('[1,2,3]')

        self.view = SubscriptionView()
        self.view.request = Mock()
        self.view.feed_data = ContentFeed
Esempio n. 8
0
    def setUp(self):
        class DoNothinView (object):
            def get_context_data(self, **kwargs):
                # This is just so that SingleSubscriptionMixin.get_context_data
                # super has something to call.
                return {}

        library = ContentFeedLibrary(shared=False)
        library.register(ListItemFeed, 'my list item feed')

        class SubscriptionView (SingleSubscriptionMixin, DoNothinView):
            def get_content_feed_library(self):
                return library

            def get_content_feed(self):
                return ListItemFeed('[1,2,3]')

        self.view = SubscriptionView()
        self.view.request = Mock()
        self.view.feed_data = ContentFeed
Esempio n. 9
0
class Test_ContentFeedUpdater_update (TestCase):

    def setUp(self):
        LegFile.objects.all().delete()

        key = 0
        for intro, final in [ (datetime.date(2011, 1, 28),
                               datetime.date(2011, 1, 29)),
                              (datetime.date(2010, 7, 28),
                               datetime.date(2010, 7, 29)),
                              (datetime.date(2011, 8, 17),
                               datetime.date(2011, 8, 18)),
                              (datetime.date(2006, 12, 11),
                               datetime.date(2006, 12, 12)),
                              (datetime.date(2006, 12, 12),
                               datetime.date(2006, 12, 13)) ]:
            LegFile.objects.create(intro_date=intro, final_date=final, key=key, date_scraped=datetime.date.today())
            key += 1

        self.library = ContentFeedLibrary(shared=False)
        self.library.register(NewLegFilesFeed, 'feed_class_123456')
        self.record = self.library.get_record(NewLegFilesFeed())

    @istest
    def changes_the_lastUpdated_of_a_legfiles_feed_to_most_recent_intro_date(self):
        updater = ContentFeedRecordUpdater()

        updater.update(self.record, self.library)

        assert_equal(self.record.last_updated, datetime.datetime(2011, 8, 17, 0, 0))

    @istest
    def returns_date_min_when_no_content_is_available(self):
        LegFile.objects.all().delete()
        updater = ContentFeedRecordUpdater()

        updater.update(self.record, self.library)

        assert_equal(self.record.last_updated, datetime.datetime.min)
Esempio n. 10
0
class Test_SubscriptionForm_save:

    def setup(self):
        Subscription.objects.all().delete()
        Subscriber.objects.all().delete()
        ContentFeedRecord.objects.all().delete()

        self.library = ContentFeedLibrary(shared=False)
        self.library.register(ListItemFeed, 'my list items')

        self.subscriber = Subscriber.objects.create()
        self.feed = ListItemFeed('[1, 2, 3]')
        self.feed_record = self.library.get_record(self.feed)

    @istest
    def creates_a_subscription_for_the_subscriber_to_the_feed(self):
        form = SubscriptionForm({'subscriber': self.subscriber.pk,
                                 'feed_record': self.feed_record.pk})

        assert form.is_valid(), 'The form had errors: %r' % (form.errors,)
        form.save()
        subscription = self.subscriber.subscription(self.feed, self.library)

        assert subscription is not None
Esempio n. 11
0
class Test_SubscriptionForm_save:

    def setup(self):
        Subscription.objects.all().delete()
        Subscriber.objects.all().delete()
        ContentFeedRecord.objects.all().delete()

        self.library = ContentFeedLibrary(shared=False)
        self.library.register(ListItemFeed, 'my list items')

        self.subscriber = Subscriber.objects.create()
        self.feed = ListItemFeed('[1, 2, 3]')
        self.feed_record = self.library.get_record(self.feed)

    @istest
    def creates_a_subscription_for_the_subscriber_to_the_feed(self):
        form = SubscriptionForm({'subscriber': self.subscriber.pk,
                                 'feed_record': self.feed_record.pk})

        assert form.is_valid(), 'The form had errors: %r' % (form.errors,)
        form.save()
        subscription = self.subscriber.subscription(self.feed, self.library)

        assert subscription is not None
Esempio n. 12
0
def test_subscription_flow():
    Subscriber.objects.all().delete()
    ContentFeedRecord.objects.all().delete()
    del mail.outbox[:]

    library = ContentFeedLibrary(shared=True)

    # First, let's make some content
    content = [
        (datetime.date(2011, 12, 13), 1),
        (datetime.date(2011, 12, 13), 2),
        (datetime.date(2011, 12, 13), 3),
        (datetime.date(2011, 12, 13), 4),
        (datetime.date(2011, 12, 13), 5),
    ]

    # Then, let's make a ContentFeed that watches it.
    class EasyContentFeed(ContentFeed):
        def get_content(self):
            return content

        def get_params(self):
            return {}

        def get_updates_since(self, previous):
            return [t for t in content if t[0] > previous.date()]

        def get_last_updated_time(self):
            return max([t[0] for t in content])

        def get_changes_to(self, item, since):
            if since.date() < item[0]:
                return {"value": item[1]}, datetime.datetime(2011, 12, 13, 14, 15)

        def get_label(self):
            return "Easy..."

    library.register(EasyContentFeed, "easy")
    feed = EasyContentFeed()

    # Now we want a subscriber to subscribe to the feed.
    subscriber = Subscriber.objects.create()
    subscription = subscriber.subscribe(feed, library=library)

    # Assume that we last sent the subscription before the current items.
    subscription.last_sent = datetime.date(2011, 11, 11)
    subscription.save()

    # Now, update all the feeds dates/times and send out the updated content.
    update = updatefeeds.Command()
    update.handle()

    send = sendfeedupdates.Command()
    send.handle()

    # Check that we have a message to send.
    assert_equal(len(mail.outbox), 1)
    assert_equal(mail.outbox[0].subject[:19], "Councilmatic")
    assert_equal(
        mail.outbox[0].body,
        (
            "\n\nCouncilmatic!\n==========================\n\nYou are subscribed to the following feeds:\n\n\n* Easy...\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 5\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 2\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 4\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 1\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 3\n\nMore at http://example.com\n\n\n\nTo manage your subscriptions, visit http://example.com/subscriptions/\n"
        ),
    )

    # Cool.  Clear the mailbox.
    del mail.outbox[:]

    # Now, if we update the feed times and send the updated content, there
    # should be nothing to send.
    update = updatefeeds.Command()
    update.handle()

    send = sendfeedupdates.Command()
    send.handle()

    assert_equal(len(mail.outbox), 0)

    # Put something else into the feed.
    content.append((datetime.date(2012, 2, 4), 6))

    # Now, update all the feeds dates/times and send out the updated content.
    update = updatefeeds.Command()
    update.handle()

    send = sendfeedupdates.Command()
    send.handle()

    assert_equal(len(mail.outbox), 1)
Esempio n. 13
0
def test_subscription_flow():
    Subscriber.objects.all().delete()
    ContentFeedRecord.objects.all().delete()
    del mail.outbox[:]

    library = ContentFeedLibrary(shared=True)

    # First, let's make some content
    content = [(datetime.date(2011, 12, 13), 1),
               (datetime.date(2011, 12, 13), 2),
               (datetime.date(2011, 12, 13), 3),
               (datetime.date(2011, 12, 13), 4),
               (datetime.date(2011, 12, 13), 5)]

    # Then, let's make a ContentFeed that watches it.
    class EasyContentFeed(ContentFeed):
        def get_content(self):
            return content

        def get_params(self):
            return {}

        def get_updates_since(self, previous):
            return [t for t in content if t[0] > previous.date()]

        def get_last_updated_time(self):
            return max([t[0] for t in content])

        def get_changes_to(self, item, since):
            if since.date() < item[0]:
                return {
                    'value': item[1]
                }, datetime.datetime(2011, 12, 13, 14, 15)

        def get_label(self):
            return 'Easy...'

    library.register(EasyContentFeed, 'easy')
    feed = EasyContentFeed()

    # Now we want a subscriber to subscribe to the feed.
    subscriber = Subscriber.objects.create()
    subscription = subscriber.subscribe(feed, library=library)

    # Assume that we last sent the subscription before the current items.
    subscription.last_sent = datetime.date(2011, 11, 11)
    subscription.save()

    # Now, update all the feeds dates/times and send out the updated content.
    update = updatefeeds.Command()
    update.handle()

    send = sendfeedupdates.Command()
    send.handle()

    # Check that we have a message to send.
    assert_equal(len(mail.outbox), 1)
    assert_equal(mail.outbox[0].subject[:19], 'Philly Councilmatic')
    assert_equal(mail.outbox[0].body, (
        '\n\nPhiladelphia Councilmatic!\n==========================\n\nYou are subscribed to the following feeds:\n\n\n* Easy...\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 5\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 2\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 4\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 1\n\nMore at http://example.com\n\n\n--------------------------------------------------------------------------------\n\n \n\nvalue: 3\n\nMore at http://example.com\n\n\n\nTo manage your subscriptions, visit http://example.com/subscriptions/\n'
    ))

    # Cool.  Clear the mailbox.
    del mail.outbox[:]

    # Now, if we update the feed times and send the updated content, there
    # should be nothing to send.
    update = updatefeeds.Command()
    update.handle()

    send = sendfeedupdates.Command()
    send.handle()

    assert_equal(len(mail.outbox), 0)

    # Put something else into the feed.
    content.append((datetime.date(2012, 2, 4), 6))

    # Now, update all the feeds dates/times and send out the updated content.
    update = updatefeeds.Command()
    update.handle()

    send = sendfeedupdates.Command()
    send.handle()

    assert_equal(len(mail.outbox), 1)
Esempio n. 14
0
        search_view.results.queryset.query.query_filter to store the search.
        I'm not certain, but I'm pretty sure this value is search backend-
        specific.  Just keep that in mind.

        """
        self.filter = search_filter

    def get_content(self):
        return SearchQuerySet().raw_search(self.filter)

    def get_changes_to(self, item, datetime):
        if isinstance(item, LegFile):
            return {'Title': item.title}
        elif isinstance(item, LegMinutes):
            return {'Minutes': str(item)}

    def get_last_updated(self, item):
        if isinstance(item, LegFile):
            return item.intro_date
        elif isinstance(item, LegMinutes):
            return item.date_taken

    def get_params(self):
        return self.filter


library.register(NewLegislationFeed, 'newly introduced legislation')
library.register(LegislationUpdatesFeed, 'updates to a piece of legislation')
library.register(SearchResultsFeed, 'results of a search query')
library.register(BookmarkedContentFeed, 'bookmarked content')