Exemple #1
0
 def test_get(self):
     response = self.client.get(reverse('home'))
     form = response.context['form']
     # Color
     search_color = form.fields['search_color']
     attrs_color = search_color.widget.build_attrs()
     url_color = attrs_color['data-url']
     self.assertEqual(
         url_color,
         reverse(
             get_namespace() + ':agnocomplete',
             args=['AutocompleteColor']
         )
     )
     # Person
     search_person = form.fields['search_person']
     attrs_person = search_person.widget.build_attrs()
     url_person = attrs_person['data-url']
     self.assertEqual(
         url_person,
         reverse(
             get_namespace() + ':agnocomplete',
             args=['AutocompletePerson']
         )
     )
 def test_get(self):
     response = self.client.get(reverse('home'))
     form = response.context['form']
     # Color
     search_color = form.fields['search_color']
     attrs_color = search_color.widget.build_attrs()
     url_color = attrs_color['data-url']
     self.assertEqual(
         url_color,
         reverse(
             get_namespace() + ':agnocomplete',
             args=['AutocompleteColor']
         )
     )
     # Person
     search_person = form.fields['search_person']
     attrs_person = search_person.widget.build_attrs()
     url_person = attrs_person['data-url']
     self.assertEqual(
         url_person,
         reverse(
             get_namespace() + ':agnocomplete',
             args=['AutocompletePerson']
         )
     )
Exemple #3
0
 def test_timeout(self):
     # Search using the URL proxy view
     search_url = get_namespace() + ':agnocomplete'
     with mock.patch('requests.get', raise_timeout):
         response = self.client.get(reverse(search_url,
                                            args=[self.klass.__name__]),
                                    data={'q': "person"})
         self.assertEqual(response.status_code, 408)
 def test_timeout(self):
     # Search using the URL proxy view
     search_url = get_namespace() + ':agnocomplete'
     with mock.patch('requests.get', raise_timeout):
         response = self.client.get(
             reverse(
                 search_url, args=[self.klass.__name__]),
             data={'q': "person"}
         )
         self.assertEqual(response.status_code, 408)
 def test_model_extra_arg(self):
     search_url = get_namespace() + ':agnocomplete'
     response = self.client.get(
         reverse(search_url, args=['AutocompletePersonExtra']),
         data={'q': "Alice", "extra_argument": "Marseille"}
     )
     # Only the "Alices" that live in Marseille
     result = json.loads(response.content.decode())
     data = result.get('data')
     self.assertEqual(len(data), 2)
 def test_extra_arg(self):
     search_url = get_namespace() + ':agnocomplete'
     response = self.client.get(
         reverse(search_url, args=['AutocompleteColorExtra']),
         data={'q': "green", "extra_argument": "Hello I'm here"}
     )
     result = json.loads(response.content.decode())
     data = result.get('data')
     self.assertEqual(len(data), 2)
     added = data[-1]
     self.assertEqual(added, {'value': 'EXTRA', 'label': 'EXTRA'})
Exemple #7
0
 def test_model_extra_arg(self):
     search_url = get_namespace() + ':agnocomplete'
     response = self.client.get(reverse(search_url,
                                        args=['AutocompletePersonExtra']),
                                data={
                                    'q': "Alice",
                                    "extra_argument": "Marseille"
                                })
     # Only the "Alices" that live in Marseille
     result = json.loads(response.content.decode())
     data = result.get('data')
     self.assertEqual(len(data), 2)
Exemple #8
0
 def test_extra_arg(self):
     search_url = get_namespace() + ':agnocomplete'
     response = self.client.get(reverse(search_url,
                                        args=['AutocompleteColorExtra']),
                                data={
                                    'q': "green",
                                    "extra_argument": "Hello I'm here"
                                })
     result = json.loads(response.content.decode())
     data = result.get('data')
     self.assertEqual(len(data), 2)
     added = data[-1]
     self.assertEqual(added, {'value': 'EXTRA', 'label': 'EXTRA'})
Exemple #9
0
 def test_search_headers_wrong_auth(self):
     # URL construct
     instance = self.klass()
     search_url = instance.search_url
     klass = self.klass_path
     with mock.patch(klass + '.get_search_url') as mock_auto:
         mock_auto.return_value = self.live_server_url + search_url
         # Search using the URL proxy view
         search_url = get_namespace() + ':agnocomplete'
         with mock.patch(klass + '.get_http_headers') as mock_headers:
             mock_headers.return_value = {'NOTHING': 'HERE'}
             response = self.client.get(reverse(search_url,
                                                args=[self.klass.__name__]),
                                        data={'q': "person"})
             self.assertEqual(response.status_code, 403)
Exemple #10
0
 def test_search_headers_auth(self):
     # URL construct
     instance = AutocompleteUrlHeadersAuth()
     search_url = instance.search_url
     klass = 'demo.autocomplete.AutocompleteUrlHeadersAuth'
     with mock.patch(klass + '.get_search_url') as mock_auto:
         mock_auto.return_value = self.live_server_url + search_url
         # Search using the URL proxy view
         search_url = get_namespace() + ':agnocomplete'
         response = self.client.get(reverse(
             search_url, args=['AutocompleteUrlHeadersAuth']),
                                    data={'q': "person"})
         # All the persons
         result = json.loads(response.content.decode())
         data = result.get('data')
         self.assertEqual(len(data), 7)
 def test_search_headers_auth(self):
     # URL construct
     instance = AutocompleteUrlHeadersAuth()
     search_url = instance.search_url
     klass = 'demo.autocomplete.AutocompleteUrlHeadersAuth'
     with mock.patch(klass + '.get_search_url') as mock_auto:
         mock_auto.return_value = self.live_server_url + search_url
         # Search using the URL proxy view
         search_url = get_namespace() + ':agnocomplete'
         response = self.client.get(
             reverse(search_url, args=['AutocompleteUrlHeadersAuth']),
             data={'q': "person"}
         )
         # All the persons
         result = json.loads(response.content.decode())
         data = result.get('data')
         self.assertEqual(len(data), 7)
 def test_search_headers_wrong_auth(self):
     # URL construct
     instance = self.klass()
     search_url = instance.search_url
     klass = self.klass_path
     with mock.patch(klass + '.get_search_url') as mock_auto:
         mock_auto.return_value = self.live_server_url + search_url
         # Search using the URL proxy view
         search_url = get_namespace() + ':agnocomplete'
         with mock.patch(klass + '.get_http_headers') as mock_headers:
             mock_headers.return_value = {
                 'NOTHING': 'HERE'
             }
             response = self.client.get(
                 reverse(
                     search_url, args=[self.klass.__name__]),
                 data={'q': "person"}
             )
             self.assertEqual(response.status_code, 403)
Exemple #13
0
 def _test_error(self, status_code, message):
     instance = AutocompleteUrlErrors()
     search_url = instance.search_url
     klass = 'demo.autocomplete.AutocompleteUrlErrors'
     with mock.patch(klass + '.get_search_url') as mock_auto:
         mock_auto.return_value = self.live_server_url + search_url
         # Search using the URL proxy view
         search_url = get_namespace() + ':agnocomplete'
         response = self.client.get(
             reverse(search_url, args=['AutocompleteUrlErrors']),
             data={'q': "hello {}".format(status_code)})
         # Status code by default
         self.assertEqual(response.status_code, status_code)
         # Result is a JSON
         result = json.loads(response.content.decode())
         self.assertIn('errors', result)
         errors = result['errors']
         self.assertEqual(len(errors), 1)
         error = errors[0]
         self.assertEqual(error['detail'], message)
         self.assertEqual(error['title'], "An error has occurred")
 def _test_error(self, status_code, message):
     instance = AutocompleteUrlErrors()
     search_url = instance.search_url
     klass = 'demo.autocomplete.AutocompleteUrlErrors'
     with mock.patch(klass + '.get_search_url') as mock_auto:
         mock_auto.return_value = self.live_server_url + search_url
         # Search using the URL proxy view
         search_url = get_namespace() + ':agnocomplete'
         response = self.client.get(
             reverse(search_url, args=['AutocompleteUrlErrors']),
             data={'q': "hello {}".format(status_code)}
         )
         # Status code by default
         self.assertEqual(response.status_code, status_code)
         # Result is a JSON
         result = json.loads(response.content.decode())
         self.assertIn('errors', result)
         errors = result['errors']
         self.assertEqual(len(errors), 1)
         error = errors[0]
         self.assertEqual(error['detail'], message)
         self.assertEqual(error['title'], "An error has occurred")
Exemple #15
0
 def setUp(self):
     super(SelectizeExtraTest, self).setUp()
     self.search_url = get_namespace() + ':agnocomplete'
Exemple #16
0
 def url(self):
     ac_url_name = get_namespace() + ':agnocomplete'
     return reverse(ac_url_name, args=[self.klass.__name__])
Exemple #17
0
from agnocomplete import get_namespace

# Needed by Django 1.6
if StrictVersion(django.get_version()) < StrictVersion('1.7'):
    admin.autodiscover()

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),

    # Autodiscovered URLs
    url(
        r'^agnocomplete/',
        include(
            'agnocomplete.urls',
            namespace=get_namespace()
        )
    ),

    # Agnocomplete Custom view
    url(r'^hidden-autocomplete/$', 'demo.views.hidden_autocomplete',
        name='hidden-autocomplete'),

    # Templated DEMO views
    url(r'^$', 'demo.views.index', name='home'),
    url(r'^filled-form/$', 'demo.views.filled_form', name='filled-form'),
    url(r'^search-context/$', 'demo.views.search_context', name='search-context'),  # noqa
    url(r'^custom/$', 'demo.views.search_custom', name='search-custom'),
    # Demo Front JS views
    url(r'^selectize/$', 'demo.views.selectize', name='selectize'),
    url(r'^selectize-multi/$', 'demo.views.selectize_multi', name='selectize-multi'),  # noqa
 def setUp(self):
     super(SelectizeExtraTest, self).setUp()
     self.search_url = get_namespace() + ':agnocomplete'
Exemple #19
0
"""
from django.conf.urls import include
from django.urls import path
from django.contrib import admin

from agnocomplete import get_namespace
from . import views

urlpatterns = [
    path(r'^admin/', admin.site.urls),

    # Autodiscovered URLs
    path(
        r'^agnocomplete/',
        include(('agnocomplete.urls', 'agnocomplete'),
                namespace=get_namespace())),

    # Agnocomplete Custom view
    path(r'^hidden-autocomplete/$',
         views.hidden_autocomplete,
         name='hidden-autocomplete'),

    # Templated DEMO views
    path(r'^$', views.index, name='home'),
    path(r'^filled-form/$', views.filled_form, name='filled-form'),
    path(r'^search-context/$', views.search_context, name='search-context'),
    path(r'^custom/$', views.search_custom, name='search-custom'),
    # Demo Front JS views
    path(r'^selectize/$', views.selectize, name='selectize'),
    path(r'^selectize-extra/$', views.selectize_extra, name='selectize-extra'),
    path(r'^selectize-multi/$', views.selectize_multi, name='selectize-multi'),
 def url(self):
     ac_url_name = get_namespace() + ':agnocomplete'
     return reverse(ac_url_name, args=[self.klass.__name__])
import django
from django.conf.urls import include, url
from django.contrib import admin

from agnocomplete import get_namespace

# Needed by Django 1.6
if StrictVersion(django.get_version()) < StrictVersion('1.7'):
    admin.autodiscover()

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),

    # Autodiscovered URLs
    url(r'^agnocomplete/',
        include('agnocomplete.urls', namespace=get_namespace())),

    # Agnocomplete Custom view
    url(r'^hidden-autocomplete/$',
        'demo.views.hidden_autocomplete',
        name='hidden-autocomplete'),

    # Templated DEMO views
    url(r'^$', 'demo.views.index', name='home'),
    url(r'^filled-form/$', 'demo.views.filled_form', name='filled-form'),
    url(r'^search-context/$',
        'demo.views.search_context',
        name='search-context'),  # noqa
    url(r'^custom/$', 'demo.views.search_custom', name='search-custom'),
    # Demo Front JS views
    url(r'^selectize/$', 'demo.views.selectize', name='selectize'),
Exemple #22
0
 def setUp(self):
     super(ContextTagTestCase, self).setUp()
     # Login for alice
     self.client.login(email=self.alice.email)
     self.search_url = get_namespace() + ':agnocomplete'
 def setUp(self):
     super(ContextTagTestCase, self).setUp()
     # Login for alice
     self.client.login(email=self.alice.email)
     self.search_url = get_namespace() + ':agnocomplete'
 def setUp(self):
     super(NamespaceGeneric, self).setUp()
     self.catalog_url_name = get_namespace() + ':catalog'
     self.ac_url_name = get_namespace() + ':agnocomplete'
 def setUp(self):
     super().setUp()
     self.search_url = get_namespace() + ':agnocomplete'