예제 #1
0
    def test_same_guids(self, get):
        get.return_value = responses(304)
        feed = FeedFactory.create(user__ttl=99999)

        parsed = feedparser.parse(data_file("aldaily-06-27.xml"))
        data = list(filter(None, [UniqueFeed.objects.entry_data(entry, parsed) for entry in parsed.entries]))

        with self.assertNumQueries(1 + len(data)):
            store_entries(feed.url, data)

        count = es.counts(feed.user, [feed.pk], unread=False)[str(feed.pk)][str(feed.pk)]["doc_count"]
        self.assertEqual(count, 4)

        data = list(filter(None, [UniqueFeed.objects.entry_data(entry, parsed) for entry in parsed.entries]))
        with self.assertNumQueries(1):
            store_entries(feed.url, data)
        count = es.counts(feed.user, [feed.pk], unread=False)[str(feed.pk)][str(feed.pk)]["doc_count"]
        self.assertEqual(count, 4)

        parsed = feedparser.parse(data_file("aldaily-06-30.xml"))
        data = list(filter(None, [UniqueFeed.objects.entry_data(entry, parsed) for entry in parsed.entries]))

        with self.assertNumQueries(7):
            store_entries(feed.url, data)

        count = es.counts(feed.user, [feed.pk], unread=False)[str(feed.pk)][str(feed.pk)]["doc_count"]
        self.assertEqual(count, 10)
예제 #2
0
    def test_suspending_user(self, get):
        get.return_value = responses(304)
        feed = FeedFactory.create(user__is_suspended=True)
        call_command("delete_unsubscribed")
        self.assertEqual(UniqueFeed.objects.count(), 0)

        parsed = feedparser.parse(data_file("sw-all.xml"))
        data = list(filter(None, [UniqueFeed.objects.entry_data(entry, parsed) for entry in parsed.entries]))

        with self.assertNumQueries(1):  # no insert
            store_entries(feed.url, data)

        last_updates = feed.user.last_updates()
        self.assertEqual(last_updates, {})

        feed2 = FeedFactory.create(url=feed.url, user__ttl=99999)
        self.assertEqual(UniqueFeed.objects.count(), 1)
        call_command("delete_unsubscribed")
        self.assertEqual(UniqueFeed.objects.count(), 1)

        data = list(filter(None, [UniqueFeed.objects.entry_data(entry, parsed) for entry in parsed.entries]))
        with self.assertNumQueries(30 + 1):  # insert
            store_entries(feed.url, data)

        count = es.counts(feed.user, [feed.pk])[str(feed.pk)][str(feed.pk)]["doc_count"]
        count2 = es.counts(feed2.user, [feed2.pk])[str(feed2.pk)][str(feed2.pk)]["doc_count"]
        self.assertEqual(count, 0)
        self.assertEqual(count2, 30)
        last_updates = feed2.user.last_updates()
        self.assertEqual(list(last_updates.keys()), [feed2.url])
예제 #3
0
    def test_same_guids(self, get, head):
        head.side_efect = resolve_url
        get.return_value = responses(304)
        feed = FeedFactory.create(user__ttl=99999)

        parsed = feedparser.parse(data_file('aldaily-06-27.xml'))
        data = list(
            filter(None, [
                UniqueFeed.objects.entry_data(entry, parsed)
                for entry in parsed.entries
            ]))

        with self.assertNumQueries(1 + len(data)):
            store_entries(feed.url, data)

        count = es.counts(feed.user, [feed.pk], unread=False)[str(
            feed.pk)][str(feed.pk)]['doc_count']
        self.assertEqual(count, 4)

        data = list(
            filter(None, [
                UniqueFeed.objects.entry_data(entry, parsed)
                for entry in parsed.entries
            ]))
        with self.assertNumQueries(1):
            store_entries(feed.url, data)
        count = es.counts(feed.user, [feed.pk], unread=False)[str(
            feed.pk)][str(feed.pk)]['doc_count']
        self.assertEqual(count, 4)

        parsed = feedparser.parse(data_file('aldaily-06-30.xml'))
        data = list(
            filter(None, [
                UniqueFeed.objects.entry_data(entry, parsed)
                for entry in parsed.entries
            ]))

        with self.assertNumQueries(7):
            store_entries(feed.url, data)

        count = es.counts(feed.user, [feed.pk], unread=False)[str(
            feed.pk)][str(feed.pk)]['doc_count']
        self.assertEqual(count, 10)
예제 #4
0
    def test_suspending_user(self, get, head):
        head.side_efect = resolve_url
        get.return_value = responses(304)
        feed = FeedFactory.create(user__is_suspended=True)
        call_command('delete_unsubscribed')
        self.assertEqual(UniqueFeed.objects.count(), 0)

        parsed = feedparser.parse(data_file('sw-all.xml'))
        data = list(
            filter(None, [
                UniqueFeed.objects.entry_data(entry, parsed)
                for entry in parsed.entries
            ]))

        with self.assertNumQueries(1):  # no insert
            store_entries(feed.url, data)

        last_updates = feed.user.last_updates()
        self.assertEqual(last_updates, {})

        feed2 = FeedFactory.create(url=feed.url, user__ttl=99999)
        self.assertEqual(UniqueFeed.objects.count(), 1)
        call_command('delete_unsubscribed')
        self.assertEqual(UniqueFeed.objects.count(), 1)

        data = list(
            filter(None, [
                UniqueFeed.objects.entry_data(entry, parsed)
                for entry in parsed.entries
            ]))
        with self.assertNumQueries(30 + 1):  # insert
            store_entries(feed.url, data)

        count = es.counts(feed.user,
                          [feed.pk])[str(feed.pk)][str(feed.pk)]['doc_count']
        count2 = es.counts(feed2.user, [feed2.pk])[str(feed2.pk)][str(
            feed2.pk)]['doc_count']
        self.assertEqual(count, 0)
        self.assertEqual(count2, 30)
        last_updates = feed2.user.last_updates()
        self.assertEqual(list(last_updates.keys()), [feed2.url])