def create(): db = MongoClient() users_svc = UsersService(db, 'users') teams_svc = TeamsService(db, 'teams') user_dict = { "given_name": "User", "family_name": "McLastName", "authenticators": [ { "issuer": "https://accounts.google.com", "subject": "x", "email": "*****@*****.**" } ] } user = NewUser(**user_dict) print(user) new_user_uid = users_svc.create("foo", user) new_team = { "name": "testr", "members": { new_user_uid: [ "member" ] } } teams_svc.create("foo", NewTeam(**new_team))
def test_get_user_teams(teams_service: TeamsService, request_user): teams = list(teams_service.get_user_teams(request_user, 'indurain')) assert len(teams) == 1 assert teams[0].name == 'banesto' teams = list(teams_service.get_user_teams(request_user, 'shared_user')) assert len(teams) == 2 assert teams[0].name == 'banesto' assert teams[1].name == 'motorola'
def test_get_user_teams(teams_service: TeamsService, request_user): teams = list(teams_service.get_user_teams(request_user, "indurain")) assert len(teams) == 1 assert teams[0].name == "banesto" teams = list(teams_service.get_user_teams(request_user, "shared_user")) assert len(teams) == 2 assert teams[0].name == "banesto" assert teams[1].name == "motorola"
def teams_service(mongodb, users): teams_service = TeamsService(mongodb, "teams") db.teams.delete_many({}) teams_service.create( users["leader"], NewTeam(**{ "name": "other_team", "members": { users["other_team"].uid: ["leader"] } }), ) teams_service.create( users["leader"], NewTeam( **{ "name": "same_team", "members": { users["leader"].uid: ["leader"], users["same_team"].uid: ["domestique"], }, }), ) return teams_service
def teams_service(mongodb, request_user): teams_service = TeamsService(mongodb, "teams") with freeze_time("2020-02-9T13:40:53", tz_offset=-4, auto_tick_seconds=15): teams_service.create( request_user, NewTeam( **{ "name": "banesto", "members": { "indurain": ["legend"], "delgado": ["domestique"], "shared_user": ["domestique"], }, } ), ) teams_service.create( request_user, NewTeam( **{ "name": "motorola", "members": { "armstrong": ["doper"], "landis": ["domestique"], "shared_user": ["domestique"], }, } ), ) return teams_service
def teams_service(mongodb, request_user): teams_service = TeamsService(mongodb, "teams") teams_service.create(request_user, NewTeam(**{"name": "banesto", "members": {"indurain": ['legend'], "delgado": ['domestique'], "shared_user": ['domestique']}})) teams_service.create(request_user, NewTeam(**{"name": "motorola", "members": {"armstrong": ['doper'], "landis": ['domestique'], "shared_user": ['domestique']}})) return teams_service
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)
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)
def teams_service(mongodb, users): teams_service = TeamsService(mongodb, "teams") teams_service.create( "foobar", NewTeam(**{ "name": "other_team", "members": { users['other_team'].uid: ['leader'] } })) teams_service.create( "foobar", NewTeam( **{ 'name': 'same_team', 'members': { users['leader'].uid: ['leader'], users['same_team'].uid: ['domestique'] } })) return teams_service
from splash.teams.teams_routes import set_teams_service 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)
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" test_user = NewUser(given_name="ford", family_name="prefect", email="*****@*****.**") token_info = {"sub": None, "scopes": ['splash']} db = mongomock.MongoClient().db 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) @pytest.fixture def mongodb(): return db @pytest.fixture def splash_client(mongodb, monkeypatch):