Ejemplo n.º 1
0
 def test_get(self, client, artists):
     artist = artists[0]
     form = AlbumModelSelect2WidgetForm()
     assert form.as_p()
     field_id = signing.dumps(id(form.fields['artist'].widget))
     url = reverse('django_select2-json')
     response = client.get(url, {'field_id': field_id, 'term': artist.title})
     assert response.status_code == 200
     data = json.loads(response.content.decode('utf-8'))
     assert data['results']
     assert {'id': artist.pk, 'text': smart_text(artist)} in data['results']
Ejemplo n.º 2
0
 def test_get(self, client, artists):
     artist = artists[0]
     form = AlbumModelSelect2WidgetForm()
     assert form.as_p()
     field_id = form.fields["artist"].widget.field_id
     url = reverse("django_select2:auto-json")
     response = client.get(url, {
         "field_id": field_id,
         "term": artist.title
     })
     assert response.status_code == 200
     data = json.loads(response.content.decode("utf-8"))
     assert data["results"]
     assert {"id": artist.pk, "text": smart_str(artist)} in data["results"]
Ejemplo n.º 3
0
 def test_url_check(self, client, artists):
     artist = artists[0]
     form = AlbumModelSelect2WidgetForm()
     assert form.as_p()
     field_id = signing.dumps(id(form.fields['artist'].widget))
     cache_key = form.fields['artist'].widget._get_cache_key()
     widget_dict = cache.get(cache_key)
     widget_dict['url'] = 'yet/another/url'
     cache.set(cache_key, widget_dict)
     url = reverse('django_select2-json')
     response = client.get(url, {
         'field_id': field_id,
         'term': artist.title
     })
     assert response.status_code == 404
Ejemplo n.º 4
0
    def test_label_from_instance(self, artists, client):
        url = reverse('django_select2-json')

        form = AlbumModelSelect2WidgetForm()
        form.fields['artist'].widget = ArtistCustomTitleWidget()
        assert form.as_p()
        field_id = signing.dumps(id(form.fields['artist'].widget))

        artist = artists[0]
        response = client.get(url, {'field_id': field_id, 'term': artist.title})
        assert response.status_code == 200

        data = json.loads(response.content.decode('utf-8'))
        assert data['results']
        assert {'id': artist.pk, 'text': smart_text(artist.title.upper())} in data['results']
Ejemplo n.º 5
0
 def test_url_check(self, client, artists):
     artist = artists[0]
     form = AlbumModelSelect2WidgetForm()
     assert form.as_p()
     field_id = form.fields["artist"].widget.field_id
     cache_key = form.fields["artist"].widget._get_cache_key()
     widget_dict = cache.get(cache_key)
     widget_dict["url"] = "yet/another/url"
     cache.set(cache_key, widget_dict)
     url = reverse("django_select2:auto-json")
     response = client.get(url, {
         "field_id": field_id,
         "term": artist.title
     })
     assert response.status_code == 404
Ejemplo n.º 6
0
    def test_label_from_instance(self, artists, client):
        url = reverse("django_select2:auto-json")

        form = AlbumModelSelect2WidgetForm()
        form.fields["artist"].widget = ArtistCustomTitleWidget()
        assert form.as_p()
        field_id = form.fields["artist"].widget.field_id

        artist = artists[0]
        response = client.get(url, {
            "field_id": field_id,
            "term": artist.title
        })
        assert response.status_code == 200

        data = json.loads(response.content.decode("utf-8"))
        assert data["results"]
        assert {
            "id": artist.pk,
            "text": smart_str(artist.title.upper())
        } in data["results"]