예제 #1
0
def test_named_resources():
    exposed = [getattr(resources, name) for name in dir(resources) if name.startswith("RESOURCES")]

    for resource_name in exposed:
        assert resources.exists(resource_name)
        assert resources.isdir(resource_name)
        assert resources.listdir(resource_name)
def load_template_projects():
    projects = []
    projects_names = [
        name for name in resources.listdir("data")
        if "template-projects" in name
    ]
    for name in projects_names:
        with resources.stream(f"data/{name}") as fp:
            projects.extend(json.load(fp))
    return projects
예제 #3
0
import re
import uuid as uuidlib
from typing import Dict
from simcore_service_webserver.utils import now_str

from aiohttp import web

from simcore_service_webserver.projects.projects_db import (
    APP_PROJECT_DBAPI,
    DB_EXCLUSIVE_COLUMNS,
)
from simcore_service_webserver.resources import resources

fake_template_resources = [
    "data/" + name
    for name in resources.listdir("data")
    if re.match(r"^fake-template-(.+).json", name)
]

fake_project_resources = [
    "data/" + name
    for name in resources.listdir("data")
    if re.match(r"^fake-user-(.+).json", name)
]


def empty_project_data():
    return {
        "uuid": f"project-{uuidlib.uuid4()}",
        "name": "Empty name",
        "description": "some description of an empty project",
예제 #4
0
    # default
    response = await client.get(f"/{api_version_prefix}/config")

    data, _ = await assert_status(response, web.HTTPOk)
    assert not data["invitation_required"]

    # w/ invitation explicitly
    for enabled in (True, False):
        client.app[APP_CONFIG_KEY]["login"] = {
            "registration_invitation_required": enabled
        }
        response = await client.get(f"/{api_version_prefix}/config")

        data, _ = await assert_status(response, web.HTTPOk)
        assert data["invitation_required"] is enabled


# FIXME: hard-coded v0
@pytest.mark.parametrize("resource_name", resources.listdir("api/v0/schemas"))
def test_validate_component_schema(resource_name, api_version_prefix):
    try:
        with resources.stream(
                f"api/{api_version_prefix}/schemas/{resource_name}") as fh:
            schema_under_test = json.load(fh)

        validator = jsonschema.validators.validator_for(schema_under_test)
        validator.check_schema(schema_under_test)

    except jsonschema.SchemaError as err:
        pytest.fail(msg=str(err))
예제 #5
0
import pytest
import trafaret
from pytest_simcore.helpers.utils_environs import eval_service_environ
from servicelib.aiohttp.application_keys import APP_CONFIG_KEY
from servicelib.aiohttp.application_setup import is_setup_function
from simcore_service_webserver.application_config import create_schema
from simcore_service_webserver.cli import parse, setup_parser
from simcore_service_webserver.db_config import CONFIG_SECTION_NAME as DB_SECTION
from simcore_service_webserver.email_config import CONFIG_SECTION_NAME as SMTP_SECTION
from simcore_service_webserver.login.cfg import DEFAULTS as CONFIG_DEFAULTS
from simcore_service_webserver.login.cfg import Cfg
from simcore_service_webserver.login.config import CONFIG_SECTION_NAME as LOGIN_SECTION
from simcore_service_webserver.login.config import create_login_internal_config
from simcore_service_webserver.resources import resources

config_yaml_filenames = [str(name) for name in resources.listdir("config")]


@pytest.fixture(scope="session")
def app_config_schema() -> trafaret.Dict:
    return create_schema()


@pytest.fixture(scope="session")
def service_webserver_environ(services_docker_compose_file, env_devel_dict,
                              osparc_simcore_root_dir):
    """Creates a dict with the environment variables
    inside of a webserver container
    """
    host_environ = env_devel_dict.copy()
    image_environ = {
예제 #6
0
    for item in environ_items:
        key, value = item.split("=")
        m = MATCH.match(value)
        if m:
            envkey = m.groups()[0]
            value = devel_environ[envkey]
        container_environ[key] = value

    return container_environ


# TESTS ----------------------------------------------------------------------

@pytest.mark.parametrize("configfile", [str(n)
                                        for n in resources.listdir("config")
                                        ])
def test_correctness_under_environ(configfile, container_environ):
    parser = setup_parser(argparse.ArgumentParser("test-parser"))

    with mock.patch('os.environ', container_environ):
        cmd = ["-c", configfile]
        config = parse(cmd, parser)

        for key, value in config.items():
            assert value != 'None', "Use instead Null in {} for {}".format(
                configfile, key)

        # adds some defaults checks here
        assert config['smtp']['username'] is None