def test_update_user(self): requests = _get_request_mock() expected_result = {"id": 123, "theme": "Black", "language": "fr_FR"} response = mock.Mock() response.status_code = 201 response.json.return_value = expected_result requests.put.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.update_user(123, theme="black", language="fr_FR") requests.put.assert_called_once_with('http://localhost/v1/users/123', headers=None, auth=('username', 'password'), data=mock.ANY, timeout=30) _, kwargs = requests.put.call_args payload = json.loads(kwargs.get('data')) self.assertNotIn('username', payload) self.assertNotIn('password', payload) self.assertEqual(payload.get("theme"), "black") self.assertEqual(payload.get("language"), "fr_FR") self.assertEqual(result, expected_result)
def test_update_feed(self): requests = _get_request_mock() expected_result = {"id": 123, "crawler": True, "username": "******"} response = mock.Mock() response.status_code = 201 response.json.return_value = expected_result requests.put.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.update_feed(123, crawler=True, username="******") requests.put.assert_called_once_with('http://localhost/v1/feeds/123', headers=None, auth=('username', 'password'), data=mock.ANY, timeout=30) _, kwargs = requests.put.call_args payload = json.loads(kwargs.get('data')) self.assertNotIn('feed_url', payload) self.assertNotIn('category_id', payload) self.assertEqual(payload.get('username'), "test") self.assertTrue(payload.get('crawler')) self.assertEqual(result, expected_result)
def test_discover_with_credentials(self): requests = _get_request_mock() expected_result = [{"url": "http://example.org/feed", "title": "Example", "type": "RSS"}] response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.post.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.discover("http://example.org/", username="******", password="******", user_agent="Bot") requests.post.assert_called_once_with('http://localhost/v1/discover', headers=None, auth=('username', 'password'), data=mock.ANY, timeout=30) _, kwargs = requests.post.call_args payload = json.loads(kwargs.get('data')) self.assertEqual(payload.get('url'), "http://example.org/") self.assertEqual(payload.get('username'), "foobar") self.assertEqual(payload.get('password'), "secret") self.assertEqual(payload.get('user_agent'), "Bot") self.assertEqual(result, expected_result)
def get_client(server_url, username, password): client = miniflux.Client(server_url, username, password) try: client.me() return client except Exception as e: raise e
def test_create_feed_with_custom_user_agent_and_crawler_disabled(self): requests = _get_request_mock() expected_result = {"feed_id": 42} response = mock.Mock() response.status_code = 201 response.json.return_value = expected_result requests.post.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.create_feed("http://example.org/feed", 123, crawler=False, user_agent="GoogleBot") requests.post.assert_called_once_with('http://localhost/v1/feeds', headers=None, auth=('username', 'password'), data=mock.ANY, timeout=30) _, kwargs = requests.post.call_args payload = json.loads(kwargs.get('data')) self.assertEqual(payload.get('feed_url'), "http://example.org/feed") self.assertEqual(payload.get('category_id'), 123) self.assertIsNone(payload.get('username')) self.assertIsNone(payload.get('password')) self.assertFalse(payload.get('crawler')) self.assertEqual(payload.get('user_agent'), "GoogleBot") self.assertEqual(result, expected_result['feed_id'])
def list_articles(api_url, user, password): client = miniflux.Client(api_url, user, password) entries = client.get_entries( starred=True, limit=10, order='published_at', direction='desc', ) for entry in entries['entries']: yield entry
def test_get_me_with_server_error(self): requests = _get_request_mock() response = mock.Mock() response.status_code = 500 requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") with self.assertRaises(ClientError): client.me()
def test_timeout(self): requests = _get_request_mock() requests.get.side_effect = Timeout() client = miniflux.Client("http://localhost", "username", "password", 1.0) with self.assertRaises(Timeout): client.export() requests.get.assert_called_once_with('http://localhost/v1/export', headers=None, auth=('username', 'password'), timeout=1.0)
def test_discover_with_server_error(self): requests = _get_request_mock() expected_result = {'error_message': 'some error'} response = mock.Mock() response.status_code = 500 response.json.return_value = expected_result requests.post.return_value = response client = miniflux.Client("http://localhost", "username", "password") with self.assertRaises(ClientError): client.discover("http://example.org/")
def test_mark_user_entries_as_read(self): requests = _get_request_mock() response = mock.Mock() response.status_code = 204 requests.put.return_value = response client = miniflux.Client("http://localhost", api_key="secret") client.mark_user_entries_as_read(123) requests.put.assert_called_once_with('http://localhost/v1/users/123/mark-all-as-read', headers={'X-Auth-Token': 'secret'}, auth=None, timeout=30)
def test_api_key_auth(self): requests = _get_request_mock() response = mock.Mock() response.status_code = 200 response.json.return_value = {} requests.get.return_value = response client = miniflux.Client("http://localhost", api_key="secret") client.export() requests.get.assert_called_once_with('http://localhost/v1/export', headers={'X-Auth-Token': 'secret'}, auth=None, timeout=30.0)
def test_import(self): requests = _get_request_mock() input_data = "my opml data" response = mock.Mock() response.status_code = 201 requests.post.return_value = response client = miniflux.Client("http://localhost", "username", "password") client.import_feeds(input_data) requests.post.assert_called_once_with('http://localhost/v1/import', headers=None, data=input_data, auth=('username', 'password'), timeout=30)
def test_get_user_by_username(self): requests = _get_request_mock() expected_result = [] response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.get_user_by_username("foobar") requests.get.assert_called_once_with('http://localhost/v1/users/foobar', headers=None, auth=('username', 'password'), timeout=30) assert result == expected_result
def test_get_me(self): requests = _get_request_mock() expected_result = {"id": 123, "username": "******"} response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.me() requests.get.assert_called_once_with('http://localhost/v1/me', headers=None, auth=('username', 'password'), timeout=30) self.assertEqual(result, expected_result)
def test_refresh_feed(self): requests = _get_request_mock() expected_result = True response = mock.Mock() response.status_code = 201 response.json.return_value = expected_result requests.put.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.refresh_feed(123) requests.put.assert_called_once_with('http://localhost/v1/feeds/123/refresh', headers=None, auth=('username', 'password'), timeout=30) assert result == expected_result
def test_export(self): requests = _get_request_mock() expected_result = "OPML feed" response = mock.Mock() response.status_code = 200 response.text = expected_result requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.export() requests.get.assert_called_once_with('http://localhost/v1/export', headers=None, auth=('username', 'password'), timeout=30) self.assertEqual(result, expected_result)
def test_get_entries_with_starred_param_at_false(self): requests = _get_request_mock() expected_result = [] response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.get_entries(starred=False, after_entry_id=123) requests.get.assert_called_once_with('http://localhost/v1/entries', headers=None, auth=('username', 'password'), params={'after_entry_id': 123}, timeout=30) assert result == expected_result
def test_base_url_with_trailing_slash(self): requests = _get_request_mock() expected_result = [{"url": "http://example.org/feed", "title": "Example", "type": "RSS"}] response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.post.return_value = response client = miniflux.Client("http://localhost/", "username", "password") result = client.discover("http://example.org/") requests.post.assert_called_once_with('http://localhost/v1/discover', headers=None, auth=('username', 'password'), data=mock.ANY, timeout=30) self.assertEqual(result, expected_result)
def test_get_entries(self): requests = _get_request_mock() expected_result = [] response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.get_entries(status='unread', limit=10, offset=5) requests.get.assert_called_once_with('http://localhost/v1/entries', headers=None, auth=('username', 'password'), params=mock.ANY, timeout=30) assert result == expected_result
def test_import_failure(self): requests = _get_request_mock() input_data = "my opml data" response = mock.Mock() response.status_code = 500 response.json.return_value = {"error_message": "random error"} requests.post.return_value = response client = miniflux.Client("http://localhost", "username", "password") with self.assertRaises(ClientError): client.import_feeds(input_data) requests.post.assert_called_once_with('http://localhost/v1/import', headers=None, data=input_data, auth=('username', 'password'), timeout=30)
def test_get_feed_entries_with_direction_param(self): requests = _get_request_mock() expected_result = [] response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.get_feed_entries(123, direction='asc') requests.get.assert_called_once_with('http://localhost/v1/feeds/123/entries', headers=None, auth=('username', 'password'), params={'direction': 'asc'}, timeout=30) assert result == expected_result
def test_get_entries_with_before_param(self): param_value = int(time.time()) requests = _get_request_mock() expected_result = [] response = mock.Mock() response.status_code = 200 response.json.return_value = expected_result requests.get.return_value = response client = miniflux.Client("http://localhost", "username", "password") result = client.get_entries(before=param_value) requests.get.assert_called_once_with('http://localhost/v1/entries', headers=None, auth=('username', 'password'), params={'before': param_value}, timeout=30) assert result == expected_result
import miniflux import requests import os notify_url = os.environ['REACT_NOTIFY_URL_WITH_CODE'] miniflux_site = os.environ['MINIFLUX'] username = os.environ['USERNAME'] password = os.environ['PASSWORD'] client = miniflux.Client(miniflux_site, username, password) # Unread entries notification entries = client.get_entries(status="unread", limit=1000, direction="desc") message = '' if 'total' in entries: unread_count = entries['total'] if unread_count > 0 and unread_count < 1000: message = f'You have {unread_count} unread entries at {miniflux_site}' elif unread_count is 1000: message = f'You have 1000+ unread entries at {miniflux_site}' print(message) if message: body = {"msg": message, "recipientId": "240963940"} requests.post(notify_url, json=body)
import miniflux import const client = miniflux.Client(const.MINIFLUX_URL, const.MINIFLUX_USER, const.MINIFLUX_PASS) feeds = client.get_feeds() def get_feeds_num(): return len(feeds) def discover(url): if not url.startswith('http'): url = 'http://' + url ret = [] try: ret = client.discover(url) except: ret = [] return ret def create_feed(url): feedid = -1 state = '' try: feedid = client.create_feed(url, 6) state = 'ok' except miniflux.ClientError as e:
import miniflux import config client = miniflux.Client(config.miniflux_url, config.miniflux_user, config.miniflux_pass) feeds = client.get_feeds() def get_entries(after_entry_id): if after_entry_id == None: return [] entries = client.get_entries(status="unread", limit=10, order='id', direction='asc', after_entry_id=after_entry_id) return entries['entries']
#coding:utf-8 import miniflux import os HOST = os.environ.get('host') or '127.0.0.1' PORT = os.environ.get('port') or '8080' USERNAME = os.environ.get('username') or 'admin' PASSWORD = os.environ.get('password') or '123456' # pylint: disable=invalid-name admin_client = miniflux.Client("http://{host}:{port}".format(host=HOST,port=PORT), USERNAME, PASSWORD) SERBER_ADDR = "http://{host}:{port}".format(host=HOST,port=PORT)
def __init__(self): self.client = miniflux.Client(MINIFLUX_URL, MINIFLUX_USER, MINIFLUX_PSW)