2010-06-29 20:16:09 -04:00
|
|
|
import os
|
|
|
|
from django.test.client import Client
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from apps.reader.models import UserSubscription, UserSubscriptionFolders
|
|
|
|
from apps.feed_import.models import GoogleReaderImporter
|
2010-10-23 13:06:28 -04:00
|
|
|
from utils import json_functions as json
|
2010-06-29 20:16:09 -04:00
|
|
|
|
|
|
|
class ImportTest(TestCase):
|
2011-08-31 09:41:34 -07:00
|
|
|
fixtures = ['opml_import.json']
|
2010-06-29 20:16:09 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = Client()
|
|
|
|
|
|
|
|
def test_opml_import(self):
|
|
|
|
self.client.login(username='conesus', password='test')
|
|
|
|
user = User.objects.get(username='conesus')
|
|
|
|
|
|
|
|
# Verify user has no feeds
|
|
|
|
subs = UserSubscription.objects.filter(user=user)
|
|
|
|
self.assertEquals(subs.count(), 0)
|
|
|
|
|
|
|
|
|
|
|
|
f = open(os.path.join(os.path.dirname(__file__), 'fixtures/opml.xml'))
|
|
|
|
response = self.client.post(reverse('opml-upload'), {'file': f})
|
|
|
|
self.assertEquals(response.status_code, 200)
|
|
|
|
|
|
|
|
|
|
|
|
# Verify user now has feeds
|
|
|
|
subs = UserSubscription.objects.filter(user=user)
|
|
|
|
self.assertEquals(subs.count(), 54)
|
|
|
|
|
|
|
|
def test_opml_import__empty(self):
|
|
|
|
self.client.login(username='conesus', password='test')
|
|
|
|
user = User.objects.get(username='conesus')
|
|
|
|
|
|
|
|
# Verify user has no feeds
|
|
|
|
subs = UserSubscription.objects.filter(user=user)
|
|
|
|
self.assertEquals(subs.count(), 0)
|
|
|
|
|
|
|
|
response = self.client.post(reverse('opml-upload'))
|
|
|
|
self.assertEquals(response.status_code, 200)
|
|
|
|
|
|
|
|
# Verify user now has feeds
|
|
|
|
subs = UserSubscription.objects.filter(user=user)
|
|
|
|
self.assertEquals(subs.count(), 0)
|
|
|
|
|
|
|
|
def test_google_reader_import(self):
|
|
|
|
self.client.login(username='conesus', password='test')
|
|
|
|
user = User.objects.get(username='conesus')
|
|
|
|
f = open(os.path.join(os.path.dirname(__file__), 'fixtures/google_reader.xml'))
|
|
|
|
xml = f.read()
|
|
|
|
f.close()
|
|
|
|
|
2011-08-31 18:04:45 -07:00
|
|
|
reader_importer = GoogleReaderImporter(user, xml=xml)
|
2011-08-31 09:41:34 -07:00
|
|
|
reader_importer.import_feeds()
|
2010-06-29 20:16:09 -04:00
|
|
|
|
|
|
|
subs = UserSubscription.objects.filter(user=user)
|
|
|
|
self.assertEquals(subs.count(), 66)
|
|
|
|
|
|
|
|
usf = UserSubscriptionFolders.objects.get(user=user)
|
2011-08-31 18:04:45 -07:00
|
|
|
self.assertEquals(json.decode(usf.folders), [{'Blogs \xe2\x80\x94 The Bloglets': [6, 16, 22, 35, 51, 56]}, {'Blogs': [1, 3, 25, 29, 30, 39, 40, 41, 50, 55, 57, 58, 59, 60, 66]}, {'Cooking': [11, 15, 42, 43, 46]}, {'New York': [7, 8, 17, 18, 19, 36, 45, 47, 52, 61]}, {'Tech': [2, 4, 9, 10, 12, 13, 14, 20, 23, 24, 26, 27, 28, 31, 32, 33, 34, 48, 49, 62, 64]}, {'Blogs \xe2\x80\x94 Tumblrs': [5, 21, 37, 38, 53, 54, 63, 65]}, 44])
|