def test_error_empty(self): responses.add( responses.GET, settings.DEVELOPER_BLOG_URL, json=[], ) with self.assertRaises(BadRequest): update_blog_posts()
def test_error_not_json(self): responses.add( responses.GET, settings.DEVELOPER_BLOG_URL, body='error', ) with self.assertRaises(BadRequest): update_blog_posts()
def test_error_status_code(self): responses.add( responses.GET, settings.DEVELOPER_BLOG_URL, json=self.content, status=500, ) with self.assertRaises(BadRequest): update_blog_posts()
def test_rss_cron(self): url = os.path.join(settings.ROOT, "src", "olympia", "devhub", "tests", "rss_feeds", "blog.xml") settings.DEVELOPER_BLOG_URL = url update_blog_posts() eq_(BlogPost.objects.count(), 5) bp = BlogPost.objects.all()[0] url = "http://blog.mozilla.com/addons/2011/06/10/" "update-in-time-for-thunderbird-5/" eq_(bp.title, "Test!") eq_(bp.date_posted, datetime.date(2011, 6, 10)) eq_(bp.permalink, url)
def test_rss_cron(self): url = os.path.join(settings.ROOT, 'src', 'olympia', 'devhub', 'tests', 'rss_feeds', 'blog.xml') settings.DEVELOPER_BLOG_URL = url update_blog_posts() assert BlogPost.objects.count() == 5 bp = BlogPost.objects.all()[0] url = ("http://blog.mozilla.com/addons/2011/06/10/" "update-in-time-for-thunderbird-5/") assert bp.title == 'Test!' assert bp.date_posted == datetime.date(2011, 6, 10) assert bp.permalink == url
def test_rss_cron(self): url = os.path.join( settings.ROOT, 'src', 'olympia', 'devhub', 'tests', 'rss_feeds', 'blog.xml') settings.DEVELOPER_BLOG_URL = url update_blog_posts() assert BlogPost.objects.count() == 5 bp = BlogPost.objects.all()[0] url = ("http://blog.mozilla.com/addons/2011/06/10/" "update-in-time-for-thunderbird-5/") assert bp.title == 'Test!' assert bp.date_posted == datetime.date(2011, 6, 10) assert bp.permalink == url
def test_replace_existing(self): responses.add( responses.GET, settings.DEVELOPER_BLOG_URL, json=self.content, ) no_change = BlogPost.objects.create( post_id=9018, date_posted=date(2021, 7, 29), date_modified=datetime(2021, 7, 28, 13, 17, 37), title='Foo', ) # change because different modified changed = BlogPost.objects.create( post_id=9012, title='Baa', ) old1 = BlogPost.objects.create(post_id=12345) old2 = BlogPost.objects.create(post_id=67890) update_blog_posts() assert BlogPost.objects.count() == 5 post = BlogPost.objects.all()[0] assert post.title == 'Thank you, Recommended Extensions Community Board!' assert not BlogPost.objects.filter(id=old1.id).exists() assert not BlogPost.objects.filter(id=old2.id).exists() # Post 9018 not updated because it was already there and modified hadn't changed assert ( BlogPost.objects.get(post_id=9018).title == no_change.reload().title == 'Foo' ) # post 9012 was updated because the modified date was different assert ( BlogPost.objects.get(post_id=9012).title == changed.reload().title == ('Review Articles on AMO and New Blog Name') )
def test_from_empty(self): responses.add( responses.GET, settings.DEVELOPER_BLOG_URL, json=self.content, ) assert BlogPost.objects.count() == 0 update_blog_posts() assert BlogPost.objects.count() == 5 post = BlogPost.objects.all()[0] assert post.post_id == 9022 assert post.title == 'Thank you, Recommended Extensions Community Board!' assert post.date_posted == date(2021, 8, 5) assert post.date_modified == datetime(2021, 8, 6, 11, 7, 11) assert post.permalink == ( 'https://blog.mozilla.org/addons/2021/08/05/' 'thank-you-recommended-extensions-community-board/' )
def test_update_blog_posts(): blog_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'json_feeds', 'blog.json') with open(blog_path) as blog_file: content = json.load(blog_file) responses.add( responses.GET, settings.DEVELOPER_BLOG_URL, json=content, ) update_blog_posts() assert BlogPost.objects.count() == 5 post = BlogPost.objects.all()[0] assert post.title == 'Thank you, Recommended Extensions Community Board!' assert post.date_posted == datetime.date(2021, 8, 5) assert post.permalink == ( 'https://blog.mozilla.org/addons/2021/08/05/' 'thank-you-recommended-extensions-community-board/')