From 977647684b5d488396a6c6454e337888cee7680e Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Wed, 3 Oct 2018 18:58:50 +0200 Subject: [PATCH] Basic test and extension setup --- mopidy_funkwhale/__init__.py | 32 +++++++++++++++++++++++- mopidy_funkwhale/ext.conf | 5 ++++ mopidy_funkwhale/mopidy_funkwhale.py | 3 --- setup.cfg | 12 ++++++++- tests/__init__.py | 0 tests/test_mopidy_funkwhale.py | 37 ++++++++++++++-------------- 6 files changed, 65 insertions(+), 24 deletions(-) create mode 100644 mopidy_funkwhale/ext.conf delete mode 100644 mopidy_funkwhale/mopidy_funkwhale.py create mode 100644 tests/__init__.py diff --git a/mopidy_funkwhale/__init__.py b/mopidy_funkwhale/__init__.py index ed123bf..ad3c9ee 100644 --- a/mopidy_funkwhale/__init__.py +++ b/mopidy_funkwhale/__init__.py @@ -1,7 +1,37 @@ # -*- coding: utf-8 -*- - """Top-level package for mopidy-funkwhale.""" +from __future__ import unicode_literals + +import logging +import mopidy.config +import mopidy.ext +import os + __author__ = """Eliot Berriot""" __email__ = 'contact+funkwhale@eliotberriot.com' __version__ = '0.1.0' + +logger = logging.getLogger(__name__) + + +class Extension(mopidy.ext.Extension): + + dist_name = 'Mopidy-Funkwhale' + ext_name = 'funkwhale' + version = __version__ + + def get_default_config(self): + conf_file = os.path.join(os.path.dirname(__file__), 'ext.conf') + return mopidy.config.read(conf_file) + + def get_config_schema(self): + schema = super(Extension, self).get_config_schema() + schema['url'] = mopidy.config.String() + schema['username'] = mopidy.config.Secret(optional=True) + schema['password'] = mopidy.config.Secret(optional=True) + return schema + + def setup(self, registry): + from .backend import FoobarBackend + registry.add('backend', FoobarBackend) diff --git a/mopidy_funkwhale/ext.conf b/mopidy_funkwhale/ext.conf new file mode 100644 index 0000000..0f49252 --- /dev/null +++ b/mopidy_funkwhale/ext.conf @@ -0,0 +1,5 @@ +[funkwhale] +enabled = true +url = https://demo.funkwhale.audio +username = demo +password = demo diff --git a/mopidy_funkwhale/mopidy_funkwhale.py b/mopidy_funkwhale/mopidy_funkwhale.py deleted file mode 100644 index 7fbbae4..0000000 --- a/mopidy_funkwhale/mopidy_funkwhale.py +++ /dev/null @@ -1,3 +0,0 @@ -# -*- coding: utf-8 -*- - -"""Main module.""" diff --git a/setup.cfg b/setup.cfg index 77b46ae..fec88a2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,14 +19,24 @@ zip_safe = True include_package_data = True packages = find: install_requires = + mopidy requests -[options.extras_require] +[options.entry_points] +mopidy.ext = + funkwhale = mopidy_funkwhale:Extension + +[options.extras_require] test = pytest pytest-cov +dev = + pygobject + ipython + ipdb + [options.packages.find] exclude = tests diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_mopidy_funkwhale.py b/tests/test_mopidy_funkwhale.py index c1c9196..bbf61e9 100644 --- a/tests/test_mopidy_funkwhale.py +++ b/tests/test_mopidy_funkwhale.py @@ -1,25 +1,24 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +from __future__ import unicode_literals -"""Tests for `mopidy_funkwhale` package.""" - -import pytest +import mopidy_funkwhale -from mopidy_funkwhale import mopidy_funkwhale +def test_get_default_config(): + ext = mopidy_funkwhale.Extension() + + config = ext.get_default_config() + + assert '[funkwhale]' in config + assert 'enabled = true' in config + assert 'url = https://demo.funkwhale.audio' in config + assert 'username = demo' in config + assert 'password = demo' in config -@pytest.fixture -def response(): - """Sample pytest fixture. +def test_get_config_schema(): + ext = mopidy_funkwhale.Extension() - See more at: http://doc.pytest.org/en/latest/fixture.html - """ - # import requests - # return requests.get('https://github.com/audreyr/cookiecutter-pypackage') - - -def test_content(response): - """Sample pytest test function with the pytest fixture as an argument.""" - # from bs4 import BeautifulSoup - # assert 'GitHub' in BeautifulSoup(response.content).title.string + schema = ext.get_config_schema() + assert 'url' in schema + assert 'username' in schema + assert 'password' in schema