Esempio n. 1
0
    def test_it_checks_whether_the_user_has_admin_permission_on_the_group(
            self, group, pyramid_request):
        pyramid_request.authenticated_user = group.members[-1]

        activity.group_search(pyramid_request)

        pyramid_request.has_permission.assert_called_once_with('admin',
                                                               group)
Esempio n. 2
0
    def test_it_returns_404_when_feature_turned_off(self,
                                                    group,
                                                    pyramid_request):
        pyramid_request.feature.flags['search_page'] = False

        for user in (None, group.creator, group.members[-1]):
            pyramid_request.authenticated_user = user
            with pytest.raises(httpexceptions.HTTPNotFound):
                activity.group_search(pyramid_request)
Esempio n. 3
0
    def test_it_calls_search_with_the_request(self,
                                              group,
                                              pyramid_request,
                                              search):
        for user in (None, group.creator, group.members[-1]):
            pyramid_request.authenticated_user = user

            activity.group_search(pyramid_request)

            search.assert_called_once_with(pyramid_request)

            search.reset_mock()
Esempio n. 4
0
    def test_group_search_returns_pubid_in_opts_if_group_does_not_exist(
            self, group, pyramid_request):
        pyramid_request.matchdict['pubid'] = 'does_not_exist'

        result = activity.group_search(pyramid_request)

        assert result['opts']['search_groupname'] == 'does_not_exist'
Esempio n. 5
0
    def test_it_shows_the_normal_version_of_the_page_if_more_info_is_not_in_the_request_params(
            self,
            group,
            pyramid_request):
        pyramid_request.authenticated_user = group.members[-1]

        assert activity.group_search(pyramid_request)['more_info'] is False
Esempio n. 6
0
    def test_it_just_returns_search_result_if_group_does_not_exist(
            self, group, pyramid_request, search):
        for user in (None, group.creator, group.members[-1]):
            pyramid_request.authenticated_user = user
            pyramid_request.matchdict['pubid'] = 'does_not_exist'

            assert activity.group_search(pyramid_request) == search.return_value
Esempio n. 7
0
    def test_it_does_show_the_group_edit_link_to_group_creators(
            self, group, pyramid_request):
        pyramid_request.has_permission = mock.Mock(return_value=True)
        pyramid_request.authenticated_user = group.creator

        result = activity.group_search(pyramid_request)

        assert 'group_edit_url' in result
Esempio n. 8
0
    def test_it_returns_group_members_userid(self, pyramid_request, group):
        pyramid_request.has_permission = mock.Mock(return_value=False)
        pyramid_request.authenticated_user = group.members[-1]

        result = activity.group_search(pyramid_request)

        actual = set([m['userid'] for m in result['group']['members']])
        expected = set([m.userid for m in group.members])
        assert actual == expected
Esempio n. 9
0
    def test_it_does_not_show_the_edit_link_to_group_members(self,
                                                             group,
                                                             pyramid_request):
        pyramid_request.has_permission = mock.Mock(return_value=False)
        pyramid_request.authenticated_user = group.members[-1]

        result = activity.group_search(pyramid_request)

        assert 'group_edit_url' not in result
Esempio n. 10
0
    def test_it_returns_group_members_faceted_by(self, pyramid_request, group):
        pyramid_request.has_permission = mock.Mock(return_value=False)
        pyramid_request.authenticated_user = group.members[-1]

        faceted_user = group.members[0]
        pyramid_request.POST = {'q': 'user:%s' % group.members[0].username}

        result = activity.group_search(pyramid_request)

        for member in result['group']['members']:
            assert member['faceted_by'] is (member['userid'] == faceted_user.userid)
Esempio n. 11
0
    def test_it_returns_group_info_if_user_a_member_of_group(self,
                                                             group,
                                                             pyramid_request):
        pyramid_request.authenticated_user = group.members[-1]

        group_info = activity.group_search(pyramid_request)['group']

        assert group_info['created'] == group.created.strftime('%B, %Y')
        assert group_info['description'] == group.description
        assert group_info['name'] == group.name
        assert group_info['pubid'] == group.pubid
Esempio n. 12
0
    def test_it_returns_annotation_count_for_group_members(self, pyramid_request, group, search, factories):
        user_1 = factories.User()
        user_2 = factories.User()
        group.members = [user_1, user_2]

        pyramid_request.has_permission = mock.Mock(return_value=False)
        pyramid_request.authenticated_user = group.members[-1]

        counts = {user_1.userid: 24, user_2.userid: 6}
        search.return_value = {
            'aggregations': {
                'users': [{'user': user_1.userid, 'count': counts[user_1.userid]},
                          {'user': user_2.userid, 'count': counts[user_2.userid]}]
            },
        }

        result = activity.group_search(pyramid_request)

        for member in result['group']['members']:
            assert member['count'] == counts[member['userid']]
Esempio n. 13
0
 def test_group_search_returns_name_in_opts(self, group, pyramid_request):
     result = activity.group_search(pyramid_request)
     assert result['opts']['search_groupname'] == group.name
Esempio n. 14
0
    def test_it_just_returns_search_result_if_user_not_a_member_of_group(
            self, factories, pyramid_request, search):
        pyramid_request.authenticated_user = factories.User()

        assert activity.group_search(pyramid_request) == search.return_value
Esempio n. 15
0
    def test_it_just_returns_search_result_if_user_not_logged_in(
            self, pyramid_request, search):
        pyramid_request.authenticated_user = None

        assert activity.group_search(pyramid_request) == search.return_value