From b2e6508b16f12425452aa9d256edca7745cb8405 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 15 Jul 2022 20:17:32 -0700 Subject: [PATCH] rssbridge: Add functional tests Signed-off-by: Sunil Mohan Adapa --- .../rssbridge/tests/test_functional.py | 57 +++++++++++++++++++ plinth/tests/functional/__init__.py | 1 + 2 files changed, 58 insertions(+) create mode 100644 plinth/modules/rssbridge/tests/test_functional.py diff --git a/plinth/modules/rssbridge/tests/test_functional.py b/plinth/modules/rssbridge/tests/test_functional.py new file mode 100644 index 000000000..53b2e466f --- /dev/null +++ b/plinth/modules/rssbridge/tests/test_functional.py @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +""" +Functional, browser based tests for RSS-Bridge app. +""" + +import json +import ssl +import subprocess +import urllib + +import pytest + +from plinth.tests import functional + + +class TestRSSBridgeApp(functional.BaseAppTests): + app_name = 'rssbridge' + has_service = False + has_web = True + + def test_active_bridges(self, session_browser): + """Check that bridges are active.""" + functional.app_enable(session_browser, self.app_name) + functional.visit(session_browser, '/rss-bridge/') + assert session_browser.find_by_css( + '#bridge-Wikipedia button[type="submit"]') + + def test_feed_html(self, session_browser): + """Check that a feed is properly rendered.""" + functional.app_enable(session_browser, self.app_name) + url = '/rss-bridge/?action=display&bridge=Wikipedia&' \ + 'language=en&subject=tfa&format=Html' + functional.visit(session_browser, url) + assert not session_browser.find_by_css('.exception-message') + assert session_browser.find_by_css('.feeditem') + + def test_feed_json(self, session_browser): + """Check that a feed is properly rendered.""" + functional.app_enable(session_browser, self.app_name) + path = '/rss-bridge/?action=display&bridge=Wikipedia&' \ + 'language=en&subject=tfa&format=Json' + url = functional.config['DEFAULT']['url'] + path + + # Unauthorized + result = subprocess.run(['curl', '-k', '--basic', url], + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, check=True) + assert '401 Unauthorized' in result.stdout.decode() + + # Authorized + username = functional.config['DEFAULT']['username'] + password = functional.config['DEFAULT']['password'] + result = subprocess.run( + ['curl', '-k', '--basic', '--user', f'{username}:{password}', url], + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, check=True) + feed = json.loads(result.stdout) + assert len(feed['items']) diff --git a/plinth/tests/functional/__init__.py b/plinth/tests/functional/__init__.py index 07eebec29..c9074ea40 100644 --- a/plinth/tests/functional/__init__.py +++ b/plinth/tests/functional/__init__.py @@ -46,6 +46,7 @@ _site_url = { 'jsxc': '/plinth/apps/jsxc/jsxc/', 'cockpit': '/_cockpit/', 'syncthing': '/syncthing/', + 'rssbridge': '/rss-bridge/', } _sys_modules = [