def mock_import_service() -> ImportService: # duda mock_import_service = MemoryImportService() user_1 = User( **{ 'id': "1", 'external_source': "erp.users", 'external_id': "1", 'username': "******", 'email': "*****@*****.**", 'name': "Pablo Mendoza", 'gender': "male", 'attributes': { 'site_ids': ["84"] } }) user_2 = User( **{ 'external_source': "erp.users", 'external_id': "2", 'username': "******", 'email': "*****@*****.**", 'name': "Mario Duarte", 'gender': "male", 'attributes': { 'site_ids': ["12"] } }) user_4 = User( **{ 'external_source': "erp.users", 'external_id': "2", 'username': "******", 'email': "*****@*****.**", 'name': "Mario Duarte", 'gender': "male", 'attributes': { 'site_ids': ["12"] } }) credential_1 = Credential(value="HASHED: PASS1") credential_2 = Credential(value="HASHED: PASS2") dominion_1 = Dominion(name="default") dominion_2 = Dominion(name="platformxyz") role_1 = [[Role(name="admin"), dominion_1], [Role(name="user"), dominion_2]] users_list = [[user_1, credential_1, role_1], [user_2, None, None], [user_4, credential_2, role_1]] mock_import_service.users = users_list return mock_import_service
def dominion_repository(auth_provider, parser) -> DominionRepository: dominion_repository = MemoryDominionRepository(parser, auth_provider) dominion_repository.load( {"default": { "1": Dominion(id='1', name='Data Server') }}) return dominion_repository
async def test_access_service_generate_token(access_service) -> None: tenant = Tenant(id='T1', name='Default') user = User(id='U1', username='******', email='johndoe') dominion = Dominion(id='D1', name='Data Server') token = await access_service.generate_token(tenant, user, dominion) assert isinstance(token, Token)
def mock_dominion_repository(mock_auth_provider, parser) -> DominionRepository: mock_dominion_repository = MemoryDominionRepository( parser, mock_auth_provider) mock_dominion_repository.load( {"default": { "1": Dominion(id='1', name='default') }}) return mock_dominion_repository
async def test_access_service_generate_token_roles(access_service) -> None: tenant = Tenant(id='1', name='Default') user = User(id='1', username='******', email='johndoe') dominion = Dominion(id='1', name='Data Server') user = User(id='1', username='******', email='johndoe') dominion = Dominion(id='1', name='Data Server') token = await access_service.generate_token(tenant, user, dominion) assert token.value == json.dumps({ "tid": "1", "tenant": "default", "organization": "Default", "uid": "1", "username": "******", "name": "", "email": "johndoe", "attributes": {}, "roles": ['admin|1'] })
def dominion(): return Dominion(name='superapp')