<commit_before># -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2017 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.

import io
import shutil
import sys
import unittest
import tempfile

from supysonic.config import DefaultConfig
from supysonic.managers.user import UserManager
from supysonic.web import create_application, store

class TestConfig(DefaultConfig):
    TESTING = True
    LOGGER_HANDLER_POLICY = 'never'
    BASE = {
        'database_uri': 'sqlite:',
        'scanner_extensions': None
    }
    MIMETYPES = {
        'mp3': 'audio/mpeg',
        'weirdextension': 'application/octet-stream'
    }

    def __init__(self, with_webui, with_api):
        super(TestConfig, self).__init__

        self.WEBAPP.update({
            'mount_webui': with_webui,
            'mount_api': with_api
        })

class TestBase(unittest.TestCase):
    __with_webui__ = False
    __with_api__ = False

    def setUp(self):
        self.__dir = tempfile.mkdtemp()
        config = TestConfig(self.__with_webui__, self.__with_api__)
        config.WEBAPP['cache_dir'] = self.__dir

        app = create_application(config)
        self.__ctx = app.app_context()
        self.__ctx.push()

        self.store = store
        with io.open('schema/sqlite.sql', 'r') as sql:
            schema = sql.read()
            for statement in schema.split(';'):
                self.store.execute(statement)

        self.client = app.test_client()

        UserManager.add(self.store, 'alice', 'Alic3', '<EMAIL>', True)
        UserManager.add(self.store, 'bob', 'B0b', '<EMAIL>', False)

    def tearDown(self):
        self.__ctx.pop()
        shutil.rmtree(self.__dir)

        to_unload = [ m for m in sys.modules if m.startswith('supysonic') ]
        for m in to_unload:
            del sys.modules[m]<commit_msg>Fixed tests init<commit_after># -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2017 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.

import io
import shutil
import sys
import unittest
import tempfile

from supysonic.config import DefaultConfig
from supysonic.managers.user import UserManager
from supysonic.web import create_application, store

class TestConfig(DefaultConfig):
    TESTING = True
    LOGGER_HANDLER_POLICY = 'never'
    BASE = {
        'database_uri': 'sqlite:',
        'scanner_extensions': None
    }
    MIMETYPES = {
        'mp3': 'audio/mpeg',
        'weirdextension': 'application/octet-stream'
    }

    def __init__(self, with_webui, with_api):
        super(TestConfig, self).__init__()

        for attr, value in self.__class__.__dict__.iteritems():
            if attr.startswith('_') or attr != attr.upper():
                continue

            if isinstance(value, dict):
                setattr(self, attr, value.copy())
            else:
                setattr(self, attr, value)

        self.WEBAPP.update({
            'mount_webui': with_webui,
            'mount_api': with_api
        })

class TestBase(unittest.TestCase):
    __with_webui__ = False
    __with_api__ = False

    def setUp(self):
        self.__dir = tempfile.mkdtemp()
        config = TestConfig(self.__with_webui__, self.__with_api__)
        config.WEBAPP['cache_dir'] = self.__dir

        app = create_application(config)
        self.__ctx = app.app_context()
        self.__ctx.push()

        self.store = store
        with io.open('schema/sqlite.sql', 'r') as sql:
            schema = sql.read()
            for statement in schema.split(';'):
                self.store.execute(statement)
        self.store.commit()

        self.client = app.test_client()

        UserManager.add(self.store, 'alice', 'Alic3', '<EMAIL>', True)
        UserManager.add(self.store, 'bob', 'B0b', '<EMAIL>', False)

    def tearDown(self):
        self.__ctx.pop()
        shutil.rmtree(self.__dir)

        to_unload = [ m for m in sys.modules if m.startswith('supysonic') ]
        for m in to_unload:
            del sys.modules[m]
{'fraction_non_alphanumeric': 0.11431270666036844, 'fraction_numerical': 0.0051960321209258385, 'mean_word_length': 2.488467874794069, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5241527', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1339, 'n_words': 319}