예제 #1
0
def test_get_runs_auth(monkeypatch, teams_service, users):
    checker = TeamRunChecker()
    runs_service = RunsService(teams_service, checker)
    # patch the catalog into the service to override stock intake catalog
    monkeypatch.setattr('splash.runs.runs_service.catalog', root_catalog)
    runs = runs_service.get_runs(users['leader'], "root_catalog")
    assert runs is not None and len(
        runs) == 2, '2 available runs match those submitted by same_team'
    runs = runs_service.get_runs(users['other_team'], "root_catalog")
    assert len(
        runs) == 1, 'one run available to use who is a member of other_team'
예제 #2
0
def test_thumb_auth(monkeypatch, teams_service, users):
    checker = TeamRunChecker()
    runs_service = RunsService(teams_service, checker)
    # patch the catalog into the service to override stock intake catalog
    monkeypatch.setattr('splash.runs.runs_service.catalog', root_catalog)
    image_array = runs_service.get_run_thumb(users['leader'], "root_catalog",
                                             'same_team_1', 0)
    assert image_array is not None, 'retrieved slice image for run user has access to'
    with pytest.raises(AccessDenied):
        image_array = runs_service.get_run_thumb(users['leader'],
                                                 "root_catalog",
                                                 'other_team_1', 0)
예제 #3
0
def test_thumb_auth(monkeypatch, teams_service, users, tmpdir):
    checker = TeamRunChecker()
    runs_service = RunsService(teams_service, checker)
    # patch the catalog into the service to override stock intake catalog
    monkeypatch.setattr('splash.runs.runs_service.catalog', root_catalog)
    root_catalog['root_catalog'].root_map = {"thumbs": tmpdir}
    thumb_dir = Path(tmpdir)
    file_name = 'same_team_1.png'
    with open(thumb_dir / file_name, 'wb') as thumb_file:
        thumb_file.write(b"nonsense file")
    image_array = runs_service.get_run_thumb(users['leader'], "root_catalog",
                                             'same_team_1')
    assert image_array is not None, 'retrieved slice image for run user has access to'

    with pytest.raises(AccessDenied):
        image_array = runs_service.get_run_thumb(users['leader'],
                                                 "root_catalog",
                                                 'other_team_1')
예제 #4
0
def setup_services():
    # setup_services separated so that service_provider creation
    # is decoupled from app creation, allowing test code to
    # mock the service_provider
    from pymongo import MongoClient
    init_logging()
    db_uri = ConfigStore.MONGO_DB_URI
    db = MongoClient(db_uri).splash
    users_svc = UsersService(db, 'users')
    compounds_svc = CompoundsService(db, 'compounds')
    teams_svc = TeamsService(db, 'teams')
    runs_svc = RunsService(teams_svc, TeamRunChecker())
    set_auth_services(users_svc)
    set_compounds_service(compounds_svc)
    set_runs_service(runs_svc)
    set_teams_service(teams_svc)
    set_users_service(users_svc)
예제 #5
0
def setup_services():
    # setup_services separated so that service_provider creation
    # is decoupled from app creation, allowing test code to
    # mock the service_provider
    from pymongo import MongoClient

    init_logging()
    db_uri = ConfigStore.MONGO_DB_URI
    db = MongoClient(db_uri).splash
    users_svc = UsersService(db, "users")
    pages_svc = PagesService(db, "pages", "pages_old")
    references_svc = ReferencesService(db, "references")
    teams_svc = TeamsService(db, "teams")
    runs_svc = RunsService(teams_svc, TeamRunChecker())
    set_auth_services(users_svc)
    set_pages_service(pages_svc)
    set_references_service(references_svc)
    set_runs_service(runs_svc)
    set_teams_service(teams_svc)
    set_users_service(users_svc)
예제 #6
0
from splash.teams.teams_service import TeamsService
from splash.api.auth import create_access_token, set_services as set_auth_services

from splash.api.main import app
API_URL_ROOT = "/api/v1"
os.environ[
    "TOKEN_SECRET_KEY"] = "the_question_to_the_life_the_universe_and_everything"
os.environ["GOOGLE_CLIENT_ID"] = "Gollum"
os.environ["GOOGLE_CLIENT_SECRET"] = "the_one_ring"

db = mongomock.MongoClient().db
users_svc = UsersService(db, "users")
pages_svc = PagesService(db, "pages", "pages_old")
references_svc = ReferencesService(db, "references")
teams_svc = TeamsService(db, "teams")
runs_svc = RunsService(teams_svc, TeamRunChecker())
set_auth_services(users_svc)
set_pages_service(pages_svc)
set_references_service(references_svc)
set_runs_service(runs_svc)
set_teams_service(teams_svc)
set_users_service(users_svc)


def collationMock(self, collation):
    assert collation.document == {"locale": "en_US"}
    return self


@pytest.fixture(scope="function", autouse=True)
def mock_collation_prop(monkeypatch):