Exemple #1
0
def test_choices_to_django_choices_with_two_items_on_tuple():
    choices = Choices(("order_amount", "Order amount"),
                      ("attribute_name", "Some description"))

    django_choices = choices.to_django_choices()
    assert django_choices == (
        ("order_amount", "Order amount"),
        ("attribute_name", "Some description"),
    )
Exemple #2
0
def test_choices_with_mixed_tuples_quantities():
    with pytest.raises(MixedChoicesElements) as exc:
        Choices(
            ("order_amount", ),
            ("order_amount", "Order amount"),
            ("value", "attribute_name", "Some description"),
            ("value", "attribute_name", "Some description",
             "This is an error"),
        )

    assert f"choices_tuples tuples has mixed items size" == str(exc.value)
Exemple #3
0
def test_choices_attributes_with_three_items_on_tuple():
    choices = Choices(
        ("order_amount", "order_amount", "Order amount"),
        ("value", "attribute_name", "Some description"),
        (0, "inactive", "Status inactive"),
        (True, "active", "Status active"),
    )

    assert choices.order_amount == "order_amount"
    assert choices.attribute_name == "value"
    assert choices.inactive == 0
    assert choices.active is True
Exemple #4
0
def test_choices_values_list(choices, expected_list):
    choices = Choices(*choices)
    assert choices.values == expected_list
Exemple #5
0
def test_choices_empty():
    with pytest.raises(ChoicesIsEmpty) as exc:
        Choices()

    assert "choices_tuples is empty" == str(exc.value)
Exemple #6
0
def test_choices_attributes_with_two_items_on_tuple():
    choices = Choices(("order_amount", "Order amount"),
                      ("attribute_name", "Some description"))

    assert choices.order_amount == "order_amount"
    assert choices.attribute_name == "attribute_name"
Exemple #7
0
def test_choices_with_more_than_three_items(some_tuple_with_choices):
    with pytest.raises(InvalidChoicesElements) as exc:
        Choices(some_tuple_with_choices)

    assert f"choices_tuples must have 2 or 3 items only" == str(exc.value)