def from_target(cls, entitlements: TargetEntitlements): """ Create an Entitlement object from a target object :param entitlements: Entitlements as a target object :return: A new Entitlements object with all specified entitlements """ entitlements = TargetEntitlements.default_instance() if entitlements is None else entitlements return cls.from_dict(entitlements.to_json())
def from_dict(cls, obj, reference_list: Optional[List] = None): id_ = obj.get('id', None) name = obj.get('name', '') parameters = obj.get('parameters', {}) entitlements = Entitlements_.from_dict(obj.get('entitlements', {})) # If a reference list is given, then the entities will be resolved by the caller if reference_list is not None: should_resolve_entities = False else: should_resolve_entities = True reference_list = [] rows = [row_from_dict(row, reference_list) for row in parameters.get('rows', [])] columns = [DataColumn.from_dict(column, reference_list) for column in parameters.get('columns', [])] sorts = [DataGridSort.from_dict(sort) for sort in parameters.get('sorts', [])] filters = [DataGridFilter.from_dict(filter_) for filter_ in parameters.get('filters', [])] multi_column_groups = [MultiColumnGroup.from_dict(group) for group in parameters.get('multiColumnGroups', [])] if should_resolve_entities: resolve_entities(reference_list) return DataGrid(name=name, rows=rows, columns=columns, id_=id_, entitlements=entitlements, primary_column_index=parameters.get('primaryColumnIndex', 0), polling_time=parameters.get('pollingTime', 0), multiColumnGroups=multi_column_groups, sorts=sorts, filters=filters)
def to_target(self) -> TargetEntitlements: """ Return Entitlement object as a target object :return: Entitlements as a target object """ target_entitlements = TargetEntitlements.default_instance() if not self.admin.is_empty(): target_entitlements.admin = self.admin.to_list() if not self.delete.is_empty(): target_entitlements.delete = self.delete.to_list() if not self.display.is_empty(): target_entitlements.display = self.display.to_list() if not self.upload.is_empty(): target_entitlements.upload = self.upload.to_list() if not self.edit.is_empty(): target_entitlements.edit = self.edit.to_list() if not self.execute.is_empty(): target_entitlements.execute = self.execute.to_list() if not self.plot.is_empty(): target_entitlements.plot = self.plot.to_list() if not self.query.is_empty(): target_entitlements.query = self.query.to_list() if not self.rebalance.is_empty(): target_entitlements.rebalance = self.rebalance.to_list() if not self.trade.is_empty(): target_entitlements.trade = self.trade.to_list() if not self.view.is_empty(): target_entitlements.view = self.view.to_list() return target_entitlements
def from_target(cls, entitlements: TargetEntitlements): """ Create an Entitlement object from a target object :param entitlements: Entitlements as a target object :return: A new Entitlements object with all specified entitlements """ return cls.from_dict(entitlements.to_json())
def test_create(mocker): portfolio = Portfolio(position_sets=(PositionSet( positions=(Position(asset_id='MA4B66MW5E27UAHKG34', quantity=50), ), date=datetime.date(2020, 1, 1)), ), name='Test Portfolio', currency='EUR') mq_portfolio = MQPortfolio( name='Test Portfolio', currency='EUR', id='portfolio_id', entitlements=Entitlements(admin=('guid:12345', ))) mocker.patch.object(GsSession.current, '_post', return_value=mq_portfolio) mocker.patch.object(GsSession.current, '_put', return_value=()) mocker.patch.object(Portfolio, 'update_positions', return_value=()) mocker.patch.object(Portfolio, '_schedule_first_reports', return_value=()) mocker.patch.object(User, 'get_many', return_value=([ User(user_id='12345', name='Fake User', email='*****@*****.**', company='Goldman Sachs') ])) portfolio._create() assert portfolio.currency.value == 'EUR'
def test_basket_update_entitlements(mocker): mock_session() mock_basket_init(mocker, user_ia) basket = Basket.get(ticker) mock_response(mocker, GsUsersApi, 'get_users', [TargetUser.from_dict(user_ena)]) new_admin = User.get(user_id='user_xyz') basket.entitlements.admin.users += [new_admin] entitlements_response = TargetEntitlements( admin=['guid:user_abc', 'guid:user_xyz']) mock_response(mocker, GsAssetApi, 'update_asset_entitlements', entitlements_response) response = basket.update() GsAssetApi.update_asset_entitlements.assert_called() assert response == entitlements_response.as_dict()
def _get_content_response(cls): return ContentResponse( id=cls._data['id'], version=cls._data['version'], name=cls._data['name'], entitlements=Entitlements(cls._data['entitlements']['view'], cls._data['entitlements']['edit'], cls._data['entitlements']['admin'], cls._data['entitlements']['delete']), created_by_id=cls._data['createdById'], created_time=cls._data['createdTime'], last_updated_time=cls._data['lastUpdatedTime'], channels=cls._data['channels'], content=Content(cls._data['content']['body'], cls._data['content']['mimeType'], cls._data['content']['encoding']))
def test_update_portfolio(mocker): old_portfolio = test_pull_from_marquee(mocker) assert old_portfolio.name == 'Test Portfolio' old_portfolio.name = 'Changed Portfolio' new_mq_portfolio = MQPortfolio(name='Changed Portfolio', currency='EUR', id='portfolio_id', entitlements=Entitlements(view=['guid:XX'], edit=['guid:XX'], admin=['guid:XX' ])) mocker.patch.object(GsSession.current, '_put', return_value=new_mq_portfolio) old_portfolio._update() assert old_portfolio.name == 'Changed Portfolio'
def _get_content_response(cls): return ContentResponse( cls._data['id'], cls._data['version'], cls._data['name'], Entitlements( cls._data['entitlements']['view'], cls._data['entitlements']['edit'], cls._data['entitlements']['admin'], cls._data['entitlements']['delete'] ), cls._data['createdById'], cls._data['createdTime'], cls._data['lastUpdatedTime'], cls._data['channels'], Content( cls._data['content']['body'], cls._data['content']['mimeType'], cls._data['content']['encoding'] ) )
def test_pull_from_marquee(mocker): portfolio_search_results = { 'results': [ MQPortfolio(id='portfolio_id', name='Test Portfolio', currency='USD', entitlements=Entitlements(admin=('guid:12345', ))) ] } mocker.patch.object(GsSession.current, '_get', return_value=portfolio_search_results) mocker.patch.object(User, 'get_many', return_value=([ User(user_id='12345', name='Fake User', email='*****@*****.**', company='Goldman Sachs') ])) portfolio = Portfolio.get(name='Test Portfolio') assert portfolio.id == 'portfolio_id' return portfolio