Add initial test

This commit is contained in:
Sonny Bakker 2020-08-07 17:52:10 +02:00
parent fec9af5626
commit 90bbcb4d27
3 changed files with 47 additions and 1 deletions

View file

@ -28,3 +28,7 @@ class FeedFactory(CollectionRuleFactory):
class SubredditFactory(CollectionRuleFactory):
type = RuleTypeChoices.subreddit
website_url = REDDIT_URL
class TwitterProfileFactory(CollectionRuleFactory):
type = RuleTypeChoices.twitter

View file

@ -1,6 +1,17 @@
from datetime import datetime
from unittest import skip
from unittest.mock import MagicMock
from django.template.defaultfilters import truncatechars
from django.test import TestCase
from django.utils.html import format_html
import pytz
from newsreader.news.collection.tests.factories import TwitterProfileFactory
from newsreader.news.collection.tests.twitter.builder.mocks import simple_mock
from newsreader.news.collection.twitter import TWITTER_URL, TwitterBuilder
from newsreader.news.core.models import Post
class TwitterBuilderTestCase(TestCase):
@ -9,7 +20,35 @@ class TwitterBuilderTestCase(TestCase):
@skip("Not implemented")
def test_simple_post(self):
pass
builder = TwitterBuilder
profile = TwitterProfileFactory()
mock_stream = MagicMock(rule=profile)
with builder((simple_mock, mock_stream)) as builder:
builder.save()
posts = {post.remote_identifier: post for post in Post.objects.all()}
self.assertCountEqual(
("1291528756373286914", "1288550304095416320"), posts.keys()
)
post = posts["1291528756373286914"]
full_text = "@ArieNeoSC Here you go, goodnight!\n\nhttps://t.co/trAcIxBMlX"
self.assertEquals(post.rule, profile)
self.assertEquals(post.title, truncatechars(full_text, 20))
self.assertEquals(post.body, format_html(full_text))
self.assertEquals(post.author, "Star Citizen")
self.assertEquals(
post.url, f"{TWITTER_URL}/RobertsSpaceInd/1291528756373286914"
)
self.assertEquals(
post.publication_date, pytz.utc.localize(datetime(2020, 8, 7, 0, 17, 5))
)
# Note that only one media type can be uploaded to an Tweet
# see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/extended-entities-object

View file

@ -1,6 +1,9 @@
from newsreader.news.collection.base import Builder, Client, Collector, Stream
TWITTER_URL = "https://twitter.com"
class TwitterScheduler:
pass