Пример #1
0
def test_select2_modelform_meta_with_blank_attrs_argument(
        Select2Mock, Select2MultipleMock):
    utils.select2_modelform_meta(m.TestFieldsModel)
    Select2Mock.assert_called_with(select2attrs=None)
    assert Select2Mock.call_count == 2
    Select2MultipleMock.assert_called_with(select2attrs=None)
    assert Select2MultipleMock.call_count == 1
Пример #2
0
def test_select2_modelform_meta_with_attrs_argument(Select2Mock, Select2MultipleMock):
    attrs = {"attribute": True}
    utils.select2_modelform_meta(m.TestFieldsModel, attrs=attrs)
    Select2Mock.assert_called_with(select2attrs=attrs)
    assert Select2Mock.call_count == 2
    Select2MultipleMock.assert_called_with(select2attrs=attrs)
    assert Select2MultipleMock.call_count == 1
Пример #3
0
def test_select2_modelform_meta_with_blank_attrs_argument(
        Select2Mock, Select2MultipleMock):
    utils.select2_modelform_meta(m.TestFieldsModel)
    Select2Mock.assert_called_with(select2attrs=None)
    assert Select2Mock.call_count == 2
    Select2MultipleMock.assert_called_with(select2attrs=None)
    assert Select2MultipleMock.call_count == 1
Пример #4
0
def test_select2_modelform_meta_kwargs():
    cm = utils.select2_modelform_meta(m.TestFieldsModel)
    assert cm.exclude == []
    cm = utils.select2_modelform_meta(m.TestFieldsModel, fields=["text"])
    assert cm.fields == ["text"]
    cm = utils.select2_modelform_meta(m.TestFieldsModel, exclude=["text"])
    assert cm.exclude == ["text"]
Пример #5
0
def test_select2_modelform_meta_with_attrs_argument(Select2Mock,
                                                    Select2MultipleMock):
    attrs = {'attribute': True}
    utils.select2_modelform_meta(m.TestFieldsModel, attrs=attrs)
    Select2Mock.assert_called_with(select2attrs=attrs)
    assert Select2Mock.call_count == 2
    Select2MultipleMock.assert_called_with(select2attrs=attrs)
    assert Select2MultipleMock.call_count == 1
Пример #6
0
def test_select2_modelform_meta_kwargs():
    cm = utils.select2_modelform_meta(m.TestFieldsModel)
    assert cm.exclude == []
    cm = utils.select2_modelform_meta(
        m.TestFieldsModel,
        fields=['text'],
    )
    assert cm.fields == ['text']
    cm = utils.select2_modelform_meta(
        m.TestFieldsModel,
        exclude=['text'],
    )
    assert cm.exclude == ['text']
Пример #7
0
def test_select2_modelform_meta_with_arguments():
    cm = utils.select2_modelform_meta(
        m.TestFieldsModel,
        meta_fields={"extra_field": 1},
        widgets={"text": forms.TextInput, "fk_field": forms.TextInput},  # must change to Select2
    )
    assert cm.extra_field == 1
    assert cm.widgets["text"] == forms.TextInput
    assert isinstance(cm.widgets["fk_field"], widgets.Select2)
Пример #8
0
def test_select2_modelform_meta_widgets_without_arguments():
    cm = utils.select2_modelform_meta(m.TestFieldsModel)
    assert cm.__name__ == 'Meta'
    assert cm.__bases__ == (object, )
    assert cm.model == m.TestFieldsModel
    assert cm.widgets != {}
    assert isinstance(cm.widgets['fk_field'], widgets.Select2)
    assert isinstance(cm.widgets['choice_field'], widgets.Select2)
    assert isinstance(cm.widgets['m2m_field'], widgets.Select2Multiple)
    assert 'text' not in cm.widgets
Пример #9
0
def test_select2_modelform_meta_widgets_without_arguments():
    cm = utils.select2_modelform_meta(m.TestFieldsModel)
    assert cm.__name__ == 'Meta'
    assert cm.__bases__ == (object,)
    assert cm.model == m.TestFieldsModel
    assert cm.widgets != {}
    assert isinstance(cm.widgets['fk_field'], widgets.Select2)
    assert isinstance(cm.widgets['choice_field'], widgets.Select2)
    assert isinstance(cm.widgets['m2m_field'], widgets.Select2Multiple)
    assert 'text' not in cm.widgets
Пример #10
0
def test_select2_modelform_meta_with_arguments():
    cm = utils.select2_modelform_meta(
        m.TestFieldsModel,
        meta_fields={'extra_field': 1},
        widgets={
            'text': forms.TextInput,
            'fk_field': forms.TextInput,  # must change to Select2
        },
    )
    assert cm.extra_field == 1
    assert cm.widgets['text'] == forms.TextInput
    assert isinstance(cm.widgets['fk_field'], widgets.Select2)
Пример #11
0
def test_select2_modelform_meta_with_arguments():
    cm = utils.select2_modelform_meta(
        m.TestFieldsModel,
        meta_fields={'extra_field': 1},
        widgets={
            'text': forms.TextInput,
            'fk_field': forms.TextInput,  # must change to Select2
        },
    )
    assert cm.extra_field == 1
    assert cm.widgets['text'] == forms.TextInput
    assert isinstance(cm.widgets['fk_field'], widgets.Select2)
Пример #12
0
def test_select2_modelform_meta_empty_widgets():
    cm = utils.select2_modelform_meta(m.EmptyModel)
    assert cm.__name__ == 'Meta'
    assert cm.__bases__ == (object, )
    assert cm.model == m.EmptyModel
    assert cm.widgets == {}
Пример #13
0
def test_select2_modelform_meta_empty_widgets():
    cm = utils.select2_modelform_meta(m.EmptyModel)
    assert cm.__name__ == 'Meta'
    assert cm.__bases__ == (object,)
    assert cm.model == m.EmptyModel
    assert cm.widgets == {}