Exemple #1
0
def test_create_group(mocker):
    target_group = TargetGroup.from_dict({
        "name":
        "Fake Group",
        "id":
        "id123",
        "createdById":
        "3563ed98a93f44c0a016fed2e5c8ce9d",
        "lastUpdatedById":
        "3563ed98a93f44c0a016fed2e5c8ce9d",
        "ownerId":
        "3563ed98a93f44c0a016fed2e5c8ce9d",
        "createdTime":
        "2020-05-22T10:57:40.449-04:00",
        "lastUpdatedTime":
        "2020-05-22T10:57:40.449-04:00"
    })

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'default_value',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current, '_post', return_value=target_group)

    # run test
    response = GsGroupsApi.create_group(target_group)
    GsSession.current._post.assert_called_with('/groups',
                                               target_group,
                                               cls=TargetGroup)
    assert response.name == 'Fake Group'
Exemple #2
0
 def update_group(cls,
                  group_id: str,
                  group: Group) -> Group:
     # PUT request for updating a group can't have the group ID in it
     group_dict = group.to_json()
     if group_dict.get('entitlements'):
         group_dict['entitlements'] = group_dict['entitlements'].to_json()
     group_dict.pop('id')
     return GsSession.current._put(f'/groups/{group_id}', group_dict, cls=Group)
Exemple #3
0
def test_get_many():
    groups = [
        TargetGroup.from_dict({
            'name': 'fakeGroup',
            'id': 'groupId',
            'tags': []
        }),
        TargetGroup.from_dict({
            'name': 'fakeGroup2',
            'id': 'groupId2',
            'tags': []
        })
    ]
    replace = Replacer()
    mock = replace('gs_quant.api.gs.groups.GsGroupsApi.get_groups', Mock())
    mock.return_value = groups
    assert len(Group.get_many(group_ids=['groupId', 'groupId2'])) == 2
    replace.restore()
Exemple #4
0
def test_get():
    group = TargetGroup.from_dict({
        'name': 'fakeGroup',
        'id': 'groupId',
        'tags': []
    })
    replace = Replacer()
    mock = replace('gs_quant.api.gs.groups.GsGroupsApi.get_group', Mock())
    mock.return_value = group
    assert Group.get('groupId').name == 'fakeGroup'
    replace.restore()
Exemple #5
0
def get_fake_group():
    group = TargetGroup.from_dict({
        'name': 'fakeGroup',
        'id': 'groupId',
        'tags': []
    })

    replace = Replacer()
    mock = replace('gs_quant.api.gs.groups.GsGroupsApi.get_group', Mock())
    mock.return_value = group
    group = Group.get(group_id='groupId')
    replace.restore()

    return group
Exemple #6
0
def test_save_create():
    group = TargetGroup.from_dict({
        'name': 'fakeGroup',
        'id': 'groupId',
        'tags': []
    })
    replace = Replacer()
    mock = replace('gs_quant.api.gs.groups.GsGroupsApi.create_group', Mock())
    mock.return_value = group
    mock = replace('gs_quant.entities.entitlements.Group._group_exists', Mock())
    mock.return_value = False
    g = Group(group_id='groupId', name='fakeGroup', tags=[])
    assert g.save().name == 'fakeGroup'
    replace.restore()