From c636a78b10f1ff6866cc804218204a6385477e8c Mon Sep 17 00:00:00 2001 From: Jonathan Math Date: Wed, 18 Nov 2020 09:38:47 -0500 Subject: [PATCH] build WIP tests for duplicate_feeds --- .../feed_import/fixtures/duplicate_feeds.json | 58 ------------------- apps/feed_import/fixtures/subscriptions.json | 28 --------- apps/feed_import/test_feed_import.py | 46 +++++++++++++-- 3 files changed, 40 insertions(+), 92 deletions(-) delete mode 100644 apps/feed_import/fixtures/duplicate_feeds.json delete mode 100644 apps/feed_import/fixtures/subscriptions.json diff --git a/apps/feed_import/fixtures/duplicate_feeds.json b/apps/feed_import/fixtures/duplicate_feeds.json deleted file mode 100644 index 590759069..000000000 --- a/apps/feed_import/fixtures/duplicate_feeds.json +++ /dev/null @@ -1,58 +0,0 @@ -[{ - "pk": 1, - "premium_subscribers": 0, - "creation": "2011-07-18", - "exception_code": 500, - "last_load_time": 1, - "active_subscribers": 1, - "feed_address": "http://blog.newsblur.com/rss", - "feed_link": "http://blog.newsblur.com/", - "last_update": "2011-07-18 04:27:26", - "etag": "", - "average_stories_per_month": 0, - "hash_address_and_link": "17", - "feed_title": "The NewsBlur Blog", - "last_modified": null, - "next_scheduled_update": "2011-07-18 16:43:25", - "favicon_color": "de9b3c", - "stories_last_month": 0, - "active": true, - "favicon_not_found": false, - "has_page_exception": false, - "fetched_once": true, - "days_to_trim": 90, - "num_subscribers": 1, - "last_story_date": "2011-07-18 04:10:01", - "min_to_decay": 720, - "has_feed_exception": false - -}, -{ - "pk": 2, - "premium_subscribers": 0, - "creation": "2011-07-18", - "exception_code": 500, - "last_load_time": 1, - "active_subscribers": 1, - "feed_address": "https://blog.newsblur.com/rss", - "feed_link": "https://blog.newsblur.com/", - "last_update": "2011-07-18 04:27:26", - "etag": "", - "average_stories_per_month": 0, - "hash_address_and_link": "18", - "feed_title": "The NewsBlur Blog", - "last_modified": null, - "next_scheduled_update": "2011-07-18 16:43:25", - "favicon_color": "de9b3c", - "stories_last_month": 0, - "active": true, - "favicon_not_found": false, - "has_page_exception": false, - "fetched_once": true, - "days_to_trim": 90, - "num_subscribers": 1, - "last_story_date": "2011-07-18 04:10:01", - "min_to_decay": 720, - "has_feed_exception": false -} -] \ No newline at end of file diff --git a/apps/feed_import/fixtures/subscriptions.json b/apps/feed_import/fixtures/subscriptions.json deleted file mode 100644 index e81724256..000000000 --- a/apps/feed_import/fixtures/subscriptions.json +++ /dev/null @@ -1,28 +0,0 @@ -[{ - "pk": 1, - "model": "reader.usersubscription", - "fields": { - "feed": 1, - "unread_count_updated": "2009-08-01 00:23:42", - "mark_read_date": "2009-07-28 23:17:27", - "unread_count_neutral": 0, - "unread_count_positive": 0, - "unread_count_negative": 0, - "user": 1, - "last_read_date": "2009-07-28 23:17:27" - } -}, -{ - "pk": 2, - "model": "reader.usersubscription", - "fields": { - "feed": 2, - "unread_count_updated": "2009-08-01 00:23:42", - "mark_read_date": "2009-07-28 23:17:27", - "unread_count_neutral": 0, - "unread_count_positive": 0, - "unread_count_negative": 0, - "user": 2, - "last_read_date": "2009-07-28 23:17:27" - } -}] \ No newline at end of file diff --git a/apps/feed_import/test_feed_import.py b/apps/feed_import/test_feed_import.py index 9fb5c9ffb..b739eb157 100644 --- a/apps/feed_import/test_feed_import.py +++ b/apps/feed_import/test_feed_import.py @@ -4,10 +4,15 @@ from django.test import TestCase from django.contrib.auth.models import User from django.urls import reverse from apps.reader.models import UserSubscription, UserSubscriptionFolders -from utils import json_functions as json - +from apps.rss_feeds.models import merge_feeds, DuplicateFeed, Feed +from utils import json_functions as json_functions +import json +from django.core.management import call_command class Test_Import(TestCase): - fixtures = ['opml_import.json'] + fixtures = [ + 'apps/rss_feeds/fixtures/initial_data.json', + 'opml_import.json' + ] def setUp(self): self.client = Client() @@ -29,8 +34,8 @@ class Test_Import(TestCase): self.assertEqual(subs.count(), 54) usf = UserSubscriptionFolders.objects.get(user=user) - print(json.decode(usf.folders)) - self.assertEqual(json.decode(usf.folders), [{'Tech': [4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]}, 1, 2, 3, 6, {'New York': [1, 2, 3, 4, 5, 6, 7, 8, 9]}, {'tech': []}, {'Blogs': [29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, {'The Bloglets': [45, 46, 47, 48, 49]}]}, {'Cooking': [50, 51, 52, 53]}, 54]) + print(json_functions.decode(usf.folders)) + self.assertEqual(json_functions.decode(usf.folders), [{'Tech': [4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]}, 1, 2, 3, 6, {'New York': [1, 2, 3, 4, 5, 6, 7, 8, 9]}, {'tech': []}, {'Blogs': [29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, {'The Bloglets': [45, 46, 47, 48, 49]}]}, {'Cooking': [50, 51, 52, 53]}, 54]) def test_opml_import__empty(self): self.client.login(username='conesus', password='test') @@ -49,4 +54,33 @@ class Test_Import(TestCase): self.assertEquals(subs.count(), 0) class Test_Duplicate_Feeds(TestCase): - pass \ No newline at end of file + fixtures = [ + 'apps/rss_feeds/fixtures/initial_data.json', + ] + + + def test_duplicate_feeds(self): + # had to load the feed data this way to hit the save() override. + # it wouldn't work with loaddata or fixures + + with open('apps/feed_import/fixtures/duplicate_feeds.json') as json_file: + feed_data = json.loads(json_file.read()) + feed_data_1 = feed_data[0] + feed_data_2 = feed_data[1] + feed_1 = Feed(**feed_data_1) + feed_2 = Feed(**feed_data_2) + feed_1.save() + feed_2.save() + + call_command('loaddata', 'apps/feed_import/fixtures/subscriptions.json') + + user_1_feed_subscription = UserSubscription.objects.filter(user__id=1)[0].feed_id + user_2_feed_subscription = UserSubscription.objects.filter(user__id=2)[0].feed_id + + self.assertNotEqual(user_1_feed_subscription, user_2_feed_subscription) + + original_feed_id = merge_feeds(user_1_feed_subscription, user_2_feed_subscription) + + user_1_feed_subscription = UserSubscription.objects.filter(user__id=1)[0].feed_id + user_2_feed_subscription = UserSubscription.objects.filter(user__id=2)[0].feed_id + self.assertEqual(user_1_feed_subscription, user_2_feed_subscription)