Exemple #1
0
    def test_it_allows_to_specify_the_page_size(self, pyramid_request, query):
        pyramid_request.params['page_size'] = 100
        activity.search(pyramid_request)

        query.execute.assert_called_once_with(pyramid_request,
                                              query.extract.return_value,
                                              page_size=100)
Exemple #2
0
    def test_it_uses_default_page_size_when_value_is_a_string(self, pyramid_request, query):
        pyramid_request.params['page_size'] = 'foobar'
        activity.search(pyramid_request)

        query.execute.assert_called_once_with(pyramid_request,
                                              query.extract.return_value,
                                              page_size=activity.PAGE_SIZE)
Exemple #3
0
    def test_it_uses_default_page_size_when_value_is_a_string(self, pyramid_request, query):
        pyramid_request.params['page_size'] = 'foobar'
        activity.search(pyramid_request)

        query.execute.assert_called_once_with(pyramid_request,
                                              query.extract.return_value,
                                              page_size=activity.PAGE_SIZE)
Exemple #4
0
    def test_it_allows_to_specify_the_page_size(self, pyramid_request, query):
        pyramid_request.params['page_size'] = 100
        activity.search(pyramid_request)

        query.execute.assert_called_once_with(pyramid_request,
                                              query.extract.return_value,
                                              page_size=100)
Exemple #5
0
    def test_it_checks_for_redirects(self, pyramid_request, query):
        pyramid_request.feature.flags['search_page'] = True

        search(pyramid_request)

        query.check_url.assert_called_once_with(pyramid_request,
                                                query.extract.return_value)
Exemple #6
0
    def test_it_uses_passed_in_page_size_for_pagination(self, pyramid_request, paginate):
        pyramid_request.params['page_size'] = 100
        activity.search(pyramid_request)

        paginate.assert_called_once_with(pyramid_request,
                                         mock.ANY,
                                         page_size=100)
Exemple #7
0
    def test_it_uses_passed_in_page_size_for_pagination(self, pyramid_request, paginate):
        pyramid_request.params['page_size'] = 100
        activity.search(pyramid_request)

        paginate.assert_called_once_with(pyramid_request,
                                         mock.ANY,
                                         page_size=100)
Exemple #8
0
    def test_it_executes_a_search_query(self, pyramid_request, query):
        pyramid_request.feature.flags['search_page'] = True

        search(pyramid_request)

        query.execute.assert_called_once_with(pyramid_request,
                                              query.extract.return_value,
                                              page_size=PAGE_SIZE)
Exemple #9
0
    def test_is_uses_passed_in_page_size_for_pagination(
            self, pyramid_request, paginate):
        pyramid_request.feature.flags['search_page'] = True

        pyramid_request.params['page_size'] = 100
        search(pyramid_request)

        paginate.assert_called_once_with(pyramid_request,
                                         mock.ANY,
                                         page_size=100)
Exemple #10
0
    def test_it_returns_usernames(self, pyramid_request, query):
        """
        It should return a list of usernames to the template.

        query.execute() returns userids, search() should insert new values with
        just the username parts.

        """
        query.execute.return_value = mock.Mock(
            aggregations={
                'users': [
                    {
                        'user': '******'
                    },
                    {
                        'user': '******'
                    },
                    {
                        'user': '******'
                    },
                ]
            })

        result = activity.search(pyramid_request)

        usernames = [
            user['username'] for user in result['aggregations']['users']
        ]
        assert usernames == ['test_user_1', 'test_user_2', 'test_user_3']
Exemple #11
0
    def test_it_returns_group_suggestions(self, factories, pyramid_request,
                                          query):
        """It should return a list of group_suggestsions to the template."""
        fake_group_1 = factories.Group()
        fake_group_2 = factories.Group()
        fake_group_3 = factories.Group()
        pyramid_request.authenticated_user.groups = [
            fake_group_1, fake_group_2, fake_group_3
        ]

        result = activity.search(pyramid_request)

        assert result['groups_suggestions'] == [
            {
                'name': fake_group_1.name,
                'pubid': fake_group_1.pubid
            },
            {
                'name': fake_group_2.name,
                'pubid': fake_group_2.pubid
            },
            {
                'name': fake_group_3.name,
                'pubid': fake_group_3.pubid
            },
        ]
Exemple #12
0
    def test_it_returns_userids(self, pyramid_request, query):
        """
        It should return a list of userids to the template.

        query.execute() returns userids as "user", search() should rename these
        to "userid".

        """
        query.execute.return_value = mock.Mock(
            aggregations={
                'users': [
                    {'user': '******'},
                    {'user': '******'},
                    {'user': '******'},
                ]
            }
        )

        result = activity.search(pyramid_request)

        userids = [user['userid'] for user in result['aggregations']['users']]
        assert userids == [
            'acct:[email protected]',
            'acct:[email protected]',
            'acct:[email protected]',
        ]
Exemple #13
0
    def test_it_does_not_crash_if_there_are_no_users(self, pyramid_request,
                                                     query):
        """
        It shouldn't crash if query.execute() returns no users.

        Sometimes there is no "users" key in the aggregations.

        """
        query.execute.return_value = mock.Mock(aggregations={})

        result = activity.search(pyramid_request)

        assert 'users' not in result['aggregations']
Exemple #14
0
    def test_it_returns_group_suggestions(self,
                                          factories,
                                          pyramid_request,
                                          query):
        """It should return a list of group_suggestsions to the template."""
        fake_group_1 = factories.Group()
        fake_group_2 = factories.Group()
        fake_group_3 = factories.Group()
        pyramid_request.authenticated_user.groups = [
            fake_group_1, fake_group_2, fake_group_3]

        result = activity.search(pyramid_request)

        assert result['groups_suggestions'] == [
            {'name': fake_group_1.name, 'pubid': fake_group_1.pubid},
            {'name': fake_group_2.name, 'pubid': fake_group_2.pubid},
            {'name': fake_group_3.name, 'pubid': fake_group_3.pubid},
        ]
Exemple #15
0
    def test_it_returns_404_when_feature_turned_off(self, pyramid_request):
        pyramid_request.feature.flags['search_page'] = False

        with pytest.raises(httpexceptions.HTTPNotFound):
            activity.search(pyramid_request)
Exemple #16
0
    def test_it_checks_for_redirects(self, pyramid_request, query):
        activity.search(pyramid_request)

        query.check_url.assert_called_once_with(pyramid_request,
                                                query.extract.return_value)
Exemple #17
0
    def test_it_executes_a_search_query(self, pyramid_request, query):
        activity.search(pyramid_request)

        query.execute.assert_called_once_with(pyramid_request,
                                              query.extract.return_value,
                                              page_size=activity.PAGE_SIZE)
Exemple #18
0
    def test_it_executes_a_search_query(self, pyramid_request, query):
        activity.search(pyramid_request)

        query.execute.assert_called_once_with(pyramid_request,
                                              query.extract.return_value,
                                              page_size=activity.PAGE_SIZE)
Exemple #19
0
    def test_it_checks_for_redirects(self, pyramid_request, query):
        activity.search(pyramid_request)

        query.check_url.assert_called_once_with(pyramid_request,
                                                query.extract.return_value)
Exemple #20
0
    def test_it_returns_404_when_feature_turned_off(self, pyramid_request):
        pyramid_request.feature.flags['search_page'] = False

        with pytest.raises(httpexceptions.HTTPNotFound):
            activity.search(pyramid_request)
Exemple #21
0
 def test_it_generates_username_links(self, pyramid_request):
     result = activity.search(pyramid_request)
     user_link = result['user_link']('acct:[email protected]')
     assert user_link == 'http://example.com/users/jim.smith/search'
Exemple #22
0
 def test_it_generates_usernames(self, pyramid_request):
     result = activity.search(pyramid_request)
     username = result['username_from_id']('acct:[email protected]')
     assert username == 'jim.smith'
Exemple #23
0
 def test_it_generates_tag_links(self, pyramid_request):
     result = activity.search(pyramid_request)
     tag_link = result['tag_link']('foo')
     assert tag_link == 'http://example.com/search?q=tag%3Afoo'