File: test_admin.py

package info (click to toggle)
python-django-pint 0.7.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: python: 1,531; makefile: 28; sh: 12
file content (43 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest

import django.contrib.admin
from django.contrib.admin import ModelAdmin
from django.db.models import Model
from django.forms import Field, ModelForm

from typing import Dict

from quantityfield.widgets import QuantityWidget
from tests.dummyapp import models


@pytest.mark.parametrize(
    "model, field",
    [
        (models.FloatFieldSaveModel, "weight"),
        (models.IntFieldSaveModel, "weight"),
        (models.BigIntFieldSaveModel, "weight"),
        (models.DecimalFieldSaveModel, "weight"),
        (models.HayBale, "weight"),
        (models.HayBale, "weight_int"),
        (models.HayBale, "weight_bigint"),
        (models.EmptyHayBaleFloat, "weight"),
        (models.EmptyHayBaleInt, "weight"),
        (models.EmptyHayBaleBigInt, "weight"),
        (models.EmptyHayBaleDecimal, "weight"),
        (models.CustomUregHayBale, "custom"),
        (models.CustomUregHayBale, "custom_int"),
        (models.CustomUregHayBale, "custom_bigint"),
        (models.CustomUregDecimalHayBale, "custom_decimal"),
        (models.ChoicesDefinedInModel, "weight"),
        (models.ChoicesDefinedInModelInt, "weight"),
    ],
)
def test_admin_widgets(model: Model, field: str):
    """
    Test that all admin pages deliver the correct widget
    """
    admin: ModelAdmin = django.contrib.admin.site._registry[model]
    form: ModelForm = admin.get_form({})()
    form_fields: Dict[str, Field] = form.fields
    assert type(form_fields[field].widget) == QuantityWidget  # noqa