Use ruff for formatting/linting
This commit is contained in:
parent
bb74e875e0
commit
57375591b5
36 changed files with 241 additions and 245 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class ResendActivationTestCase(TestCase):
|
|||
|
||||
def test_existing_account(self):
|
||||
user = UserFactory(is_active=True)
|
||||
profile = RegistrationProfileFactory(user=user, activated=True)
|
||||
RegistrationProfileFactory(user=user, activated=True)
|
||||
|
||||
response = self.client.post(self.url, {"email": user.email})
|
||||
self.assertEquals(response.status_code, 200)
|
||||
|
|
|
|||
|
|
@ -25,3 +25,28 @@ from newsreader.accounts.views.registration import (
|
|||
RegistrationView,
|
||||
)
|
||||
from newsreader.accounts.views.settings import SettingsView
|
||||
|
||||
__all__ = [
|
||||
"LoginView",
|
||||
"LogoutView",
|
||||
"FaviconRedirectView",
|
||||
"IntegrationsView",
|
||||
"RedditRevokeRedirectView",
|
||||
"RedditTemplateView",
|
||||
"RedditTokenRedirectView",
|
||||
"TwitterAuthRedirectView",
|
||||
"TwitterRevokeRedirectView",
|
||||
"TwitterTemplateView",
|
||||
"PasswordChangeView",
|
||||
"PasswordResetCompleteView",
|
||||
"PasswordResetConfirmView",
|
||||
"PasswordResetDoneView",
|
||||
"PasswordResetView",
|
||||
"ActivationCompleteView",
|
||||
"ActivationResendView",
|
||||
"ActivationView",
|
||||
"RegistrationClosedView",
|
||||
"RegistrationCompleteView",
|
||||
"RegistrationView",
|
||||
"SettingsView",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
from .base import * # isort:skip
|
||||
from .base import * # noqa: F403
|
||||
from .version import get_current_version
|
||||
|
||||
|
||||
SECRET_KEY = "mv4&5#+)-=abz3^&1r^nk_ca6y54--p(4n4cg%z*g&rb64j%wl"
|
||||
|
||||
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
|
||||
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa: F405
|
||||
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
INSTALLED_APPS += ["debug_toolbar", "django_extensions"]
|
||||
INSTALLED_APPS += ["debug_toolbar", "django_extensions"] # noqa: F405
|
||||
|
||||
# Project settings
|
||||
VERSION = get_current_version()
|
||||
|
|
@ -23,8 +23,8 @@ try:
|
|||
|
||||
from .local import * # noqa
|
||||
|
||||
SENTRY_CONFIG.update({"release": VERSION})
|
||||
SENTRY_CONFIG.update({"release": VERSION}) # noqa: F405
|
||||
|
||||
sentry_init(**SENTRY_CONFIG)
|
||||
sentry_init(**SENTRY_CONFIG) # noqa: F405
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
from .base import * # isort:skip
|
||||
from .base import * # noqa: F403
|
||||
from .version import get_current_version
|
||||
|
||||
|
||||
ALLOWED_HOSTS = ["django", "127.0.0.1"]
|
||||
|
||||
INSTALLED_APPS += ["debug_toolbar", "django_extensions"]
|
||||
INSTALLED_APPS += ["debug_toolbar", "django_extensions"] # noqa: F405
|
||||
|
||||
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]
|
||||
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] # noqa: F405
|
||||
|
||||
LOGGING["loggers"].update(
|
||||
LOGGING["loggers"].update( # noqa: F405
|
||||
{
|
||||
"celery.task": {"handlers": ["console", "celery"], "level": "DEBUG"},
|
||||
}
|
||||
|
|
@ -33,8 +33,8 @@ try:
|
|||
|
||||
from .local import * # noqa
|
||||
|
||||
SENTRY_CONFIG.update({"release": VERSION, "environment": ENVIRONMENT})
|
||||
SENTRY_CONFIG.update({"release": VERSION, "environment": ENVIRONMENT}) # noqa: F405
|
||||
|
||||
sentry_init(**SENTRY_CONFIG)
|
||||
sentry_init(**SENTRY_CONFIG) # noqa: F405
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
from .base import * # isort:skip
|
||||
from .base import * # noqa: F403
|
||||
from .version import get_current_version
|
||||
|
||||
|
||||
DEBUG = True
|
||||
|
||||
|
||||
del LOGGING["handlers"]["file"]
|
||||
del LOGGING["handlers"]["celery"]
|
||||
del LOGGING["handlers"]["file"] # noqa: F405
|
||||
del LOGGING["handlers"]["celery"] # noqa: F405
|
||||
|
||||
LOGGING["loggers"].update(
|
||||
LOGGING["loggers"].update( # noqa: F405
|
||||
{
|
||||
"celery.task": {"handlers": ["console"], "level": "DEBUG"},
|
||||
"newsreader": {"handlers": ["console"], "level": "INFO"},
|
||||
|
|
@ -39,8 +39,8 @@ try:
|
|||
# Optionally use sentry integration
|
||||
from sentry_sdk import init as sentry_init
|
||||
|
||||
SENTRY_CONFIG.update({"release": VERSION, "environment": ENVIRONMENT})
|
||||
SENTRY_CONFIG.update({"release": VERSION, "environment": ENVIRONMENT}) # noqa: F405
|
||||
|
||||
sentry_init(**SENTRY_CONFIG)
|
||||
sentry_init(**SENTRY_CONFIG) # noqa: F405
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import os
|
|||
from .version import get_current_version
|
||||
|
||||
|
||||
from .base import * # isort:skip
|
||||
from .base import * # noqa: F403
|
||||
|
||||
DEBUG = False
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ ADMINS = [
|
|||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [os.path.join(DJANGO_PROJECT_DIR, "templates")],
|
||||
"DIRS": [os.path.join(DJANGO_PROJECT_DIR, "templates")], # noqa: F405
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
|
|
@ -68,10 +68,10 @@ REGISTRATION_OPEN = False
|
|||
try:
|
||||
from sentry_sdk import init as sentry_init
|
||||
|
||||
SENTRY_CONFIG.update(
|
||||
SENTRY_CONFIG.update( # noqa: F405
|
||||
{"release": VERSION, "environment": ENVIRONMENT, "debug": False}
|
||||
)
|
||||
|
||||
sentry_init(**SENTRY_CONFIG)
|
||||
sentry_init(**SENTRY_CONFIG) # noqa: F405
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -15,3 +15,20 @@ from newsreader.news.collection.exceptions.stream import (
|
|||
StreamTimeOutException,
|
||||
StreamTooManyException,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"BuilderDuplicateException",
|
||||
"BuilderException",
|
||||
"BuilderMissingDataException",
|
||||
"BuilderParseException",
|
||||
"BuilderSkippedException",
|
||||
"StreamConnectionException",
|
||||
"StreamDeniedException",
|
||||
"StreamException",
|
||||
"StreamForbiddenException",
|
||||
"StreamNotFoundException",
|
||||
"StreamParseException",
|
||||
"StreamTimeOutException",
|
||||
"StreamTooManyException",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class FaviconBuilder(Builder):
|
|||
icons = set()
|
||||
|
||||
for link in links:
|
||||
if not "href" in link.attrs:
|
||||
if "href" not in link.attrs:
|
||||
continue
|
||||
|
||||
if "favicon" in link["href"]:
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class FeedBuilder(PostBuilder):
|
|||
data = {"rule_id": self.stream.rule.pk}
|
||||
|
||||
for field, model_field in field_mapping.items():
|
||||
if not field in entry:
|
||||
if field not in entry:
|
||||
continue
|
||||
|
||||
value = truncate_text(Post, model_field, entry[field])
|
||||
|
|
@ -77,7 +77,7 @@ class FeedBuilder(PostBuilder):
|
|||
content_details = self.get_content_details(entry)
|
||||
|
||||
# use content details key if it contains more information
|
||||
if not "body" in data or len(data["body"]) < len(content_details):
|
||||
if "body" not in data or len(data["body"]) < len(content_details):
|
||||
data["body"] = content_details
|
||||
|
||||
return Post(**data)
|
||||
|
|
|
|||
|
|
@ -2,3 +2,11 @@ from newsreader.news.collection.forms.feed import FeedForm, OPMLImportForm
|
|||
from newsreader.news.collection.forms.reddit import SubRedditForm
|
||||
from newsreader.news.collection.forms.rules import CollectionRuleBulkForm
|
||||
from newsreader.news.collection.forms.twitter import TwitterTimelineForm
|
||||
|
||||
__all__ = [
|
||||
"FeedForm",
|
||||
"OPMLImportForm",
|
||||
"SubRedditForm",
|
||||
"CollectionRuleBulkForm",
|
||||
"TwitterTimelineForm",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class RedditBuilder(PostBuilder):
|
|||
def build(self):
|
||||
results = {}
|
||||
|
||||
if not "data" in self.payload or not "children" in self.payload["data"]:
|
||||
if "data" not in self.payload or "children" not in self.payload["data"]:
|
||||
return
|
||||
|
||||
entries = self.payload["data"]["children"]
|
||||
|
|
@ -297,9 +297,7 @@ class RedditStream(PostStream):
|
|||
def __init__(self, rule):
|
||||
super().__init__(rule)
|
||||
|
||||
self.headers = {
|
||||
f"Authorization": f"bearer {self.rule.user.reddit_access_token}"
|
||||
}
|
||||
self.headers = {"Authorization": f"bearer {self.rule.user.reddit_access_token}"}
|
||||
|
||||
def read(self):
|
||||
response = fetch(self.rule.url, headers=self.headers)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from celery.utils.log import get_task_logger
|
|||
from newsreader.accounts.models import User
|
||||
from newsreader.celery import app
|
||||
from newsreader.news.collection.choices import RuleTypeChoices
|
||||
from newsreader.news.collection.exceptions.stream import StreamException
|
||||
from newsreader.news.collection.feed import FeedCollector
|
||||
from newsreader.news.collection.utils import post
|
||||
from newsreader.utils.celery import MemCacheLock
|
||||
|
|
@ -57,7 +58,7 @@ class RedditTask(app.Task):
|
|||
|
||||
with MemCacheLock("reddit-task", self.app.oid) as acquired:
|
||||
if acquired:
|
||||
logger.info(f"Running reddit task")
|
||||
logger.info("Running reddit task")
|
||||
|
||||
scheduler = RedditScheduler()
|
||||
subreddits = scheduler.get_scheduled_rules()
|
||||
|
|
@ -65,7 +66,7 @@ class RedditTask(app.Task):
|
|||
collector = RedditCollector()
|
||||
collector.collect(rules=subreddits)
|
||||
else:
|
||||
logger.warning(f"Cancelling task due to existing lock")
|
||||
logger.warning("Cancelling task due to existing lock")
|
||||
|
||||
raise Reject(reason="Task already running", requeue=False)
|
||||
|
||||
|
|
@ -154,7 +155,7 @@ class TwitterTimelineTask(app.Task):
|
|||
collector = TwitterCollector()
|
||||
collector.collect(rules=timelines)
|
||||
else:
|
||||
logger.warning(f"Cancelling task due to existing lock")
|
||||
logger.warning("Cancelling task due to existing lock")
|
||||
|
||||
raise Reject(reason="Task already running", requeue=False)
|
||||
|
||||
|
|
@ -195,7 +196,7 @@ class FaviconTask(app.Task):
|
|||
rule.favicon = "https://abs.twimg.com/favicons/favicon.ico"
|
||||
rule.save()
|
||||
else:
|
||||
logger.warning(f"Cancelling task due to existing lock")
|
||||
logger.warning("Cancelling task due to existing lock")
|
||||
|
||||
raise Reject(reason="Task already running", requeue=False)
|
||||
|
||||
|
|
|
|||
|
|
@ -64,22 +64,6 @@ class CollectionRuleDetailViewTestCase(TestCase):
|
|||
self.assertEquals(response.status_code, 200)
|
||||
self.assertEquals(data["name"], "The guardian")
|
||||
|
||||
def test_category_change(self):
|
||||
old_category = CategoryFactory(user=self.user)
|
||||
new_category = CategoryFactory(user=self.user)
|
||||
|
||||
rule = FeedFactory(name="BBC", category=old_category, user=self.user)
|
||||
|
||||
response = self.client.patch(
|
||||
reverse("api:news:collection:rules-detail", args=[rule.pk]),
|
||||
data=json.dumps({"category": absolute_url}),
|
||||
content_type="application/json",
|
||||
)
|
||||
data = response.json()
|
||||
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertEquals(data["category"], new_category.pk)
|
||||
|
||||
def test_identifier_cannot_be_changed(self):
|
||||
rule = FeedFactory(user=self.user)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,14 @@ from django.test import TestCase
|
|||
|
||||
from newsreader.news.collection.favicon import FaviconBuilder
|
||||
from newsreader.news.collection.tests.factories import CollectionRuleFactory
|
||||
from newsreader.news.collection.tests.favicon.builder.mocks import *
|
||||
from newsreader.news.collection.tests.favicon.builder.mocks import (
|
||||
simple_mock,
|
||||
mock_without_url,
|
||||
mock_without_header,
|
||||
mock_with_weird_path,
|
||||
mock_with_other_url,
|
||||
mock_with_multiple_icons,
|
||||
)
|
||||
|
||||
|
||||
class FaviconBuilderTestCase(TestCase):
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ feed_mock = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
"links": [
|
||||
|
|
|
|||
|
|
@ -108,8 +108,6 @@ mock_without_url = {
|
|||
"id": "https://www.bbc.co.uk/news/world-us-canada-48338168",
|
||||
"published": "Mon, 20 May 2019 16:07:37 GMT",
|
||||
"published_parsed": struct_time((2019, 5, 20, 16, 7, 37, 0, 140, 0)),
|
||||
"published": None,
|
||||
"published_parsed": None,
|
||||
"summary": "Foreign Minister Mohammad Javad Zarif says the US "
|
||||
"president should try showing Iranians some respect.",
|
||||
"title": "Trump's 'genocidal taunts' will not end Iran - Zarif",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,23 @@ from newsreader.news.collection.tests.factories import FeedFactory
|
|||
from newsreader.news.core.models import Post
|
||||
from newsreader.news.core.tests.factories import FeedPostFactory
|
||||
|
||||
from .mocks import *
|
||||
from .mocks import (
|
||||
multiple_mock,
|
||||
mock_without_identifier,
|
||||
mock_without_publish_date,
|
||||
mock_without_url,
|
||||
mock_without_body,
|
||||
mock_without_author,
|
||||
mock_without_entries,
|
||||
mock_with_update_entries,
|
||||
mock_with_html,
|
||||
mock_with_long_author,
|
||||
mock_with_long_title,
|
||||
mock_with_long_exotic_title,
|
||||
mock_with_longer_content_detail,
|
||||
mock_with_shorter_content_detail,
|
||||
mock_with_multiple_content_detail,
|
||||
)
|
||||
|
||||
|
||||
@freeze_time("2019-10-30 12:30:00")
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ simple_mock = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"links": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -132,7 +132,6 @@ multiple_mock = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"links": [
|
||||
{
|
||||
|
|
@ -158,7 +157,6 @@ empty_mock = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"links": [
|
||||
{
|
||||
|
|
@ -302,7 +300,6 @@ duplicate_mock = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"links": [
|
||||
{
|
||||
|
|
@ -449,7 +446,6 @@ multiple_update_mock = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"links": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ class FeedCollectorTestCase(TestCase):
|
|||
struct_time((2019, 5, 20, 16, 7, 37, 0, 140, 0)), pytz.utc
|
||||
)
|
||||
|
||||
first_post = FeedPostFactory(
|
||||
FeedPostFactory(
|
||||
url="https://www.bbc.co.uk/news/world-us-canada-48338168",
|
||||
title="Trump's 'genocidal taunts' will not end Iran - Zarif",
|
||||
body="Foreign Minister Mohammad Javad Zarif says the US "
|
||||
|
|
@ -155,7 +155,7 @@ class FeedCollectorTestCase(TestCase):
|
|||
struct_time((2019, 5, 20, 12, 19, 19, 0, 140, 0)), pytz.utc
|
||||
)
|
||||
|
||||
second_post = FeedPostFactory(
|
||||
FeedPostFactory(
|
||||
url="https://www.bbc.co.uk/news/technology-48334739",
|
||||
title="Huawei's Android loss: How it affects you",
|
||||
body="Google's move to end business ties with Huawei will "
|
||||
|
|
@ -168,7 +168,7 @@ class FeedCollectorTestCase(TestCase):
|
|||
struct_time((2019, 5, 20, 16, 32, 38, 0, 140, 0)), pytz.utc
|
||||
)
|
||||
|
||||
third_post = FeedPostFactory(
|
||||
FeedPostFactory(
|
||||
url="https://www.bbc.co.uk/news/uk-england-birmingham-48339080",
|
||||
title="Birmingham head teacher threatened over LGBT lessons",
|
||||
body="Police are investigating the messages while an MP "
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class FeedDuplicateHandlerTestCase(TestCase):
|
|||
def test_duplicate_entries_with_remote_identifiers(self):
|
||||
rule = FeedFactory()
|
||||
|
||||
existing_post = FeedPostFactory.create(
|
||||
FeedPostFactory.create(
|
||||
remote_identifier="28f79ae4-8f9a-11e9-b143-00163ef6bee7", rule=rule
|
||||
)
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ class FeedDuplicateHandlerTestCase(TestCase):
|
|||
def test_duplicate_entries_with_different_remote_identifiers(self):
|
||||
rule = FeedFactory()
|
||||
|
||||
existing_post = FeedPostFactory(
|
||||
FeedPostFactory(
|
||||
remote_identifier="28f79ae4-8f9a-11e9-b143-00163ef6bee7",
|
||||
url="https://bbc.com",
|
||||
title="New post",
|
||||
|
|
@ -100,7 +100,7 @@ class FeedDuplicateHandlerTestCase(TestCase):
|
|||
def test_duplicate_entries_in_recent_database(self):
|
||||
rule = FeedFactory()
|
||||
|
||||
existing_post = FeedPostFactory(
|
||||
FeedPostFactory(
|
||||
url="https://www.bbc.co.uk/news/uk-england-birmingham-48339080",
|
||||
title="Birmingham head teacher threatened over LGBT lessons",
|
||||
body="Google's move to end business ties with Huawei will affect current devices",
|
||||
|
|
@ -189,7 +189,7 @@ class FeedDuplicateHandlerTestCase(TestCase):
|
|||
def test_duplicate_entries_outside_time_slot(self):
|
||||
rule = FeedFactory()
|
||||
|
||||
existing_post = FeedPostFactory(
|
||||
FeedPostFactory(
|
||||
url="https://www.bbc.co.uk/news/uk-england-birmingham-48339080",
|
||||
title="Birmingham head teacher threatened over LGBT lessons",
|
||||
body="Google's move to end business ties with Huawei will affect current devices",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ simple_feed_mock = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
"links": [
|
||||
|
|
@ -43,7 +42,6 @@ feed_mock_without_link = {
|
|||
"link": "https://www.bbc.co.uk/news/",
|
||||
"title": "BBC News - Home",
|
||||
"language": "en-gb",
|
||||
"link": "https://www.bbc.co.uk/news/",
|
||||
},
|
||||
"title": "BBC News - Home",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -677,16 +677,6 @@ empty_mock = {
|
|||
},
|
||||
}
|
||||
|
||||
unknown_mock = {
|
||||
"kind": "Comment",
|
||||
"data": {
|
||||
"modhash": "rjewztai5w0ab64547311ae1fb1f9cf81cd18949bfb629cb7f",
|
||||
"dist": 27,
|
||||
"after": "t3_hmytic",
|
||||
"before": None,
|
||||
},
|
||||
}
|
||||
|
||||
unsanitized_mock = {
|
||||
"kind": "Listing",
|
||||
"data": {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,26 @@ import pytz
|
|||
|
||||
from newsreader.news.collection.reddit import RedditBuilder
|
||||
from newsreader.news.collection.tests.factories import SubredditFactory
|
||||
from newsreader.news.collection.tests.reddit.builder.mocks import *
|
||||
from newsreader.news.collection.tests.reddit.builder.mocks import (
|
||||
simple_mock,
|
||||
empty_mock,
|
||||
unknown_mock,
|
||||
unsanitized_mock,
|
||||
author_mock,
|
||||
title_mock,
|
||||
duplicate_mock,
|
||||
image_mock,
|
||||
external_image_mock,
|
||||
video_mock,
|
||||
external_video_mock,
|
||||
external_gifv_mock,
|
||||
nsfw_mock,
|
||||
spoiler_mock,
|
||||
seen_mock,
|
||||
upvote_mock,
|
||||
comment_mock,
|
||||
downvote_mock,
|
||||
)
|
||||
from newsreader.news.core.models import Post
|
||||
from newsreader.news.core.tests.factories import RedditPostFactory
|
||||
|
||||
|
|
@ -164,9 +183,7 @@ class RedditBuilderTestCase(TestCase):
|
|||
subreddit = SubredditFactory()
|
||||
mock_stream = Mock(rule=subreddit)
|
||||
|
||||
duplicate_post = RedditPostFactory(
|
||||
remote_identifier="hm0qct", rule=subreddit, title="foo"
|
||||
)
|
||||
RedditPostFactory(remote_identifier="hm0qct", rule=subreddit, title="foo")
|
||||
|
||||
with builder(simple_mock, mock_stream) as builder:
|
||||
builder.build()
|
||||
|
|
|
|||
|
|
@ -150,7 +150,6 @@ class RedditClientTestCase(TestCase):
|
|||
|
||||
def test_client_catches_long_exception_text(self):
|
||||
subreddit = SubredditFactory()
|
||||
mock_stream = Mock(rule=subreddit)
|
||||
|
||||
self.mocked_read.side_effect = StreamParseException(message=words(1000))
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,6 @@ class TwitterClientTestCase(TestCase):
|
|||
|
||||
def test_client_catches_long_exception_text(self):
|
||||
timeline = TwitterTimelineFactory()
|
||||
mock_stream = Mock(rule=timeline)
|
||||
|
||||
self.mocked_read.side_effect = StreamParseException(message=words(1000))
|
||||
|
||||
|
|
|
|||
|
|
@ -17,3 +17,18 @@ from newsreader.news.collection.views.twitter import (
|
|||
TwitterTimelineCreateView,
|
||||
TwitterTimelineUpdateView,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"FeedCreateView",
|
||||
"FeedUpdateView",
|
||||
"OPMLImportView",
|
||||
"SubRedditCreateView",
|
||||
"SubRedditUpdateView",
|
||||
"CollectionRuleBulkDeleteView",
|
||||
"CollectionRuleBulkDisableView",
|
||||
"CollectionRuleBulkEnableView",
|
||||
"CollectionRuleListView",
|
||||
"TwitterTimelineCreateView",
|
||||
"TwitterTimelineUpdateView",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -138,10 +138,10 @@ class CategoryReadTestCase(TestCase):
|
|||
|
||||
def test_category_read(self):
|
||||
category = CategoryFactory(user=self.user)
|
||||
rules = [
|
||||
rules = FeedFactory.create_batch(size=5, category=category)
|
||||
|
||||
for rule in rules:
|
||||
FeedPostFactory.create_batch(size=5, read=False, rule=rule)
|
||||
for rule in FeedFactory.create_batch(size=5, category=category)
|
||||
]
|
||||
|
||||
response = self.client.post(
|
||||
reverse("api:news:core:categories-read", args=[category.pk])
|
||||
|
|
@ -164,12 +164,10 @@ class CategoryReadTestCase(TestCase):
|
|||
self.client.logout()
|
||||
|
||||
category = CategoryFactory(user=self.user)
|
||||
rules = [
|
||||
rules = FeedFactory.create_batch(size=5, category=category, user=self.user)
|
||||
|
||||
for rule in rules:
|
||||
FeedPostFactory.create_batch(size=5, read=False, rule=rule)
|
||||
for rule in FeedFactory.create_batch(
|
||||
size=5, category=category, user=self.user
|
||||
)
|
||||
]
|
||||
|
||||
response = self.client.post(
|
||||
reverse("api:news:core:categories-read", args=[category.pk])
|
||||
|
|
@ -180,13 +178,10 @@ class CategoryReadTestCase(TestCase):
|
|||
def test_unauthorized_user(self):
|
||||
other_user = UserFactory()
|
||||
category = CategoryFactory(user=other_user)
|
||||
rules = FeedFactory.create_batch(size=5, category=category, user=other_user)
|
||||
|
||||
rules = [
|
||||
for rule in rules:
|
||||
FeedPostFactory.create_batch(size=5, read=False, rule=rule)
|
||||
for rule in FeedFactory.create_batch(
|
||||
size=5, category=category, user=other_user
|
||||
)
|
||||
]
|
||||
|
||||
response = self.client.post(
|
||||
reverse("api:news:core:categories-read", args=[category.pk])
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class NestedCategoryListViewTestCase(TestCase):
|
|||
|
||||
def test_simple(self):
|
||||
category = CategoryFactory.create(user=self.user)
|
||||
rules = FeedFactory.create_batch(size=5, category=category)
|
||||
FeedFactory.create_batch(size=5, category=category)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("api:news:core:categories-nested-rules", kwargs={"pk": category.pk})
|
||||
|
|
@ -213,7 +213,7 @@ class NestedCategoryListViewTestCase(TestCase):
|
|||
self.client.logout()
|
||||
|
||||
category = CategoryFactory.create(user=self.user)
|
||||
rules = FeedFactory.create_batch(size=5, category=category)
|
||||
FeedFactory.create_batch(size=5, category=category)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("api:news:core:categories-nested-rules", kwargs={"pk": category.pk})
|
||||
|
|
@ -225,7 +225,7 @@ class NestedCategoryListViewTestCase(TestCase):
|
|||
other_user = UserFactory.create()
|
||||
|
||||
category = CategoryFactory.create(user=other_user)
|
||||
rules = FeedFactory.create_batch(size=5, category=category)
|
||||
FeedFactory.create_batch(size=5, category=category)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("api:news:core:categories-nested-rules", kwargs={"pk": category.pk})
|
||||
|
|
@ -284,12 +284,10 @@ class NestedCategoryPostView(TestCase):
|
|||
|
||||
def test_simple(self):
|
||||
category = CategoryFactory.create(user=self.user)
|
||||
rules = {
|
||||
rule.pk: FeedPostFactory.create_batch(size=5, rule=rule)
|
||||
for rule in FeedFactory.create_batch(
|
||||
size=5, category=category, user=self.user
|
||||
)
|
||||
}
|
||||
rules = FeedFactory.create_batch(size=5, category=category, user=self.user)
|
||||
|
||||
for rule in rules:
|
||||
FeedPostFactory.create_batch(size=5, rule=rule)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("api:news:core:categories-nested-posts", kwargs={"pk": category.pk})
|
||||
|
|
@ -320,7 +318,7 @@ class NestedCategoryPostView(TestCase):
|
|||
|
||||
def test_no_posts(self):
|
||||
category = CategoryFactory.create(user=self.user)
|
||||
rules = FeedFactory.create_batch(size=5, user=self.user, category=category)
|
||||
FeedFactory.create_batch(size=5, user=self.user, category=category)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("api:news:core:categories-nested-posts", kwargs={"pk": category.pk})
|
||||
|
|
@ -439,31 +437,29 @@ class NestedCategoryPostView(TestCase):
|
|||
),
|
||||
]
|
||||
|
||||
guardian_posts = [
|
||||
FeedPostFactory.create(
|
||||
title="Second Guardian post",
|
||||
rule=guardian_rule,
|
||||
publication_date=datetime(2019, 5, 21, 14, tzinfo=pytz.utc),
|
||||
),
|
||||
FeedPostFactory.create(
|
||||
title="First Guardian post",
|
||||
rule=guardian_rule,
|
||||
publication_date=datetime(2019, 5, 20, 11, tzinfo=pytz.utc),
|
||||
),
|
||||
]
|
||||
FeedPostFactory.create(
|
||||
title="Second Guardian post",
|
||||
rule=guardian_rule,
|
||||
publication_date=datetime(2019, 5, 21, 14, tzinfo=pytz.utc),
|
||||
)
|
||||
|
||||
bbc_posts = [
|
||||
FeedPostFactory.create(
|
||||
title="Second BBC post",
|
||||
rule=bbc_rule,
|
||||
publication_date=datetime(2019, 5, 21, 16, tzinfo=pytz.utc),
|
||||
),
|
||||
FeedPostFactory.create(
|
||||
title="First BBC post",
|
||||
rule=bbc_rule,
|
||||
publication_date=datetime(2019, 5, 20, 13, tzinfo=pytz.utc),
|
||||
),
|
||||
]
|
||||
FeedPostFactory.create(
|
||||
title="First Guardian post",
|
||||
rule=guardian_rule,
|
||||
publication_date=datetime(2019, 5, 20, 11, tzinfo=pytz.utc),
|
||||
)
|
||||
|
||||
FeedPostFactory.create(
|
||||
title="Second BBC post",
|
||||
rule=bbc_rule,
|
||||
publication_date=datetime(2019, 5, 21, 16, tzinfo=pytz.utc),
|
||||
)
|
||||
|
||||
FeedPostFactory.create(
|
||||
title="First BBC post",
|
||||
rule=bbc_rule,
|
||||
publication_date=datetime(2019, 5, 20, 13, tzinfo=pytz.utc),
|
||||
)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("api:news:core:categories-nested-posts", kwargs={"pk": category.pk})
|
||||
|
|
@ -484,22 +480,18 @@ class NestedCategoryPostView(TestCase):
|
|||
|
||||
def test_only_posts_from_category_are_returned(self):
|
||||
category = CategoryFactory.create(user=self.user)
|
||||
other_category = CategoryFactory.create(user=self.user)
|
||||
CategoryFactory.create(user=self.user)
|
||||
|
||||
guardian_rule = FeedFactory.create(
|
||||
name="BBC", category=category, user=self.user
|
||||
)
|
||||
other_rule = FeedFactory.create(name="The Guardian", user=self.user)
|
||||
|
||||
guardian_posts = [
|
||||
FeedPostFactory.create(rule=guardian_rule),
|
||||
FeedPostFactory.create(rule=guardian_rule),
|
||||
]
|
||||
FeedPostFactory.create(rule=guardian_rule)
|
||||
FeedPostFactory.create(rule=guardian_rule)
|
||||
|
||||
other_posts = [
|
||||
FeedPostFactory.create(rule=other_rule),
|
||||
FeedPostFactory.create(rule=other_rule),
|
||||
]
|
||||
FeedPostFactory.create(rule=other_rule)
|
||||
FeedPostFactory.create(rule=other_rule)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("api:news:core:categories-nested-posts", kwargs={"pk": category.pk})
|
||||
|
|
|
|||
|
|
@ -55,9 +55,7 @@ class CategoryCreateViewTestCase(CategoryViewTestCase, TestCase):
|
|||
size=4, user=other_user, category=None
|
||||
)
|
||||
|
||||
user_rules = CollectionRuleFactory.create_batch(
|
||||
size=3, user=self.user, category=None
|
||||
)
|
||||
CollectionRuleFactory.create_batch(size=3, user=self.user, category=None)
|
||||
|
||||
data = {
|
||||
"name": "new-category",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def parse_opml(file, user, skip_existing=False):
|
|||
validate = URLValidator(schemes=["http", "https"])
|
||||
|
||||
for element in root.iter(tag="outline"):
|
||||
if not "xmlUrl" in element.keys():
|
||||
if "xmlUrl" not in element.keys():
|
||||
continue
|
||||
|
||||
feed_url = element.get("xmlUrl")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue