Exemple #1
0
    def setup_class(cls):
        cls._test_config = botconfig.BotConfig()
        cls._test_dispatcher = telegramcontroller.TelegramController(cls._test_config, None)

        for entry in cls._test_data:
            name, title_id, playlist_id = entry
            cls._test_config.set_bookmark(name, title_id, playlist_id)
Exemple #2
0
 def setup_class(cls):
     cls._test_config = botconfig.BotConfig()
     for item in cls._test_data:
         telegram_id, access_granted, exception_expected = item
         if access_granted:
             if exception_expected:
                 with pytest.raises(KeyError):
                     cls._test_config.add_access(telegram_id)
             else:
                 cls._test_config.add_access(telegram_id)
Exemple #3
0
def test_mark_current(monkeypatch):
    config = botconfig.BotConfig()

    dispatcher = telegramcontroller.TelegramController(
        config, spotifycontroller.SpotifyController(config))

    monkeypatch.setattr(dispatcher._spotify_controller, "get_current",
                        mockget_current)

    dispatcher.mark(None)

    assert mockget_current() == config.get_bookmark(botconfig.bookmark_current)
Exemple #4
0
def botmain():
    # Which configfile to use? If a parameter is given, this should be the configfile. If not, look for it at
    # several locations

    if len(sys.argv) > 2:
        print("Usage: %s <configfile>" % sys.argv[0])
        exit(1)

    if len(sys.argv) == 2:
        configfile = Path(sys.argv[1])
    else:
        # Current directory and $HOME
        for path in (Path.cwd(), Path.home()):
            for location in _config_locations:
                configfile = (Path(path) / location).resolve()
                if configfile.is_file():
                    break
            else:
                # Looped through all alternatives -> no configfile found
                configfile = None
            # Break from the inner loop? Break the outer loop if found
            if configfile:
                break
        else:
            # Finished, no luck
            configfile = None

    if not configfile:
        print("Unable to find configfile!")
        exit(1)

    config = botconfig.BotConfig()
    error = config.load_config(configfile)

    if not error:
        spotify_controller = spotifycontroller.SpotifyController(config)
        spotify_controller.connect()
        telegram_controller = telegramcontroller.TelegramController(
            config, spotify_controller)
        telegram_controller.connect()
    else:
        print(error)
        exit(1)
Exemple #5
0
 def setup_class(cls):
     cls._test_config = botconfig.BotConfig()
     cls._test_dispatcher = telegramcontroller.TelegramController(
         cls._test_config,
         spotifycontroller.SpotifyController(cls._test_config))
 def setup_class(cls):
     cls._config = botconfig.BotConfig()
     cls._config._load_config(_config_file_valid)
import configparser
import os

import pytest

from spottelbot import botexceptions, botconfig

_config_path = os.path.dirname(os.path.realpath(__file__))
_config_file_valid = os.path.join(_config_path, "valid.config")
_config = botconfig.BotConfig()


def test_loadconfig():
    _config._load_config(_config_file_valid)


@pytest.mark.parametrize("filename",
                         ("missingsection1.config", "missingsection2.config"))
def test_loadconfig_missingsections(filename):
    config_file_missingsection = os.path.join(_config_path, filename)

    with pytest.raises(botexceptions.MissingSection):
        _config._load_config(config_file_missingsection)


def test_telegram_token():
    _config._load_config(_config_file_valid)
    assert "110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw" == _config.telegram_token


def test_spotify_username():
 def setup_class(cls):
     cls._config = botconfig.BotConfig()
     cls._config_path = os.path.dirname(os.path.realpath(__file__))
     cls._config_file_valid = os.path.join(cls._config_path, "valid.config")
Exemple #9
0
 def setup_class(cls):
     cls._test_config = botconfig.BotConfig()
     bookmarks = cls._test_data[0]
     for bookmark in bookmarks:
         cls._test_config.set_bookmark(bookmark, None,
                                       None)  # Payload is unimportant
Exemple #10
0
 def setup_class(cls):
     cls._test_config = botconfig.BotConfig()
     for entry in cls._test_data:
         name = entry[0]
         cls._test_config.set_bookmark(name, name, cls._test_playlist)
Exemple #11
0
 def setup_class(cls):
     cls._test_config = botconfig.BotConfig()
Exemple #12
0
def test_illegal_bookmark(bookmarkname):
    config = botconfig.BotConfig()
    with pytest.raises(botexceptions.InvalidBookmark):
        config.set_bookmark(bookmarkname, None, None)
import datetime

import dateutil.tz

from spottelbot import spotifycontroller, botconfig

# Played at today

_dummy_config = botconfig.BotConfig()
_controller = spotifycontroller.SpotifyController(_dummy_config)


def test_format_date_today():
    today = datetime.datetime.now(dateutil.tz.tzlocal())
    formatted = _controller._format_played_at(today.isoformat())

    assert formatted.startswith("Today")


def test_format_date_yesterdax():
    today = datetime.date.today()
    yesterday = today - datetime.timedelta(days=1)

    formatted = _controller._format_played_at(yesterday.isoformat())

    assert formatted.startswith("Yesterday")