Beispiel #1
0
    def test_suggest_with_orgs(self):
        """Test that calling suggest with orgs filters the query"""
        query = XSEQueries('test', 'test')

        Organization.objects.all().delete()

        org0 = Organization(name='testNameWithOrgs',
                            filter='testFilterWithOrgs')
        org0.save()
        org1 = Organization(name='otherTestNameWithOrgs',
                            filter='otherTestFilterWithOrgs')
        org1.save()

        es = Mock()
        query.search = es

        query.suggest('test')

        print(es.suggest.call_args[1])

        self.assertIn(
            org0.filter,
            es.suggest.call_args[1]['completion']['contexts']['filter'])
        self.assertIn(
            org1.filter,
            es.suggest.call_args[1]['completion']['contexts']['filter'])
        self.assertEqual(
            len(es.suggest.call_args[1]['completion']['contexts']['filter']),
            2)
Beispiel #2
0
    def test_suggest_with_auth(self):
        """Test that calling suggest with no orgs raises an error"""
        Organization.objects.all().delete()

        org0 = Organization(name='testNameWithAuth',
                            filter='testFilterWithAuth')
        org0.save()
        user = XDSUser.objects.create_user('*****@*****.**',
                                           'test1234',
                                           first_name='Jane',
                                           last_name='doe')
        user.organizations.add(org0)
        query = XSEQueries('test', 'test', user=user)

        es = Mock()
        query.search = es

        query.suggest('test')

        self.assertIn(
            org0.filter,
            es.suggest.call_args[1]['completion']['contexts']['filter'])
        self.assertEqual(
            len(es.suggest.call_args[1]['completion']['contexts']['filter']),
            1)
Beispiel #3
0
    def get(self, request):
        # if partial not passed in or empty, return failstate
        if ('partial' not in request.GET or request.GET['partial'] == ''):
            return Response({"message": "No partial data sent"},
                            status=status.HTTP_400_BAD_REQUEST)

        try:
            queries = XSEQueries(
                XDSConfiguration.objects.first().target_xse_host,
                XDSConfiguration.objects.first().target_xse_index)
            response = queries.suggest(partial=request.GET['partial'])

            results = response.suggest.to_dict()['autocomplete_suggestion']

            return Response(results, status=status.HTTP_200_OK)
        except Exception as err:
            logger.error(err)
            return Response({"message": err.args[0]},
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)