示例#1
0
    def test_compare_greater_than_entities_can_compare_string_and_id(self) -> None:
        """Comparison between entities is done by the ID attribute on string IDS."""
        entity_string = Entity(id_="a")
        entity_int = Entity(id_=1)

        result = entity_string > entity_int

        assert result
示例#2
0
    def test_compare_greater_than_entities_with_string_ids(self) -> None:
        """Comparison between entities is done by the ID attribute on string IDS."""
        small = Entity(id_="a")
        big = Entity(id_="b")

        result = big > small

        assert result
示例#3
0
    def test_compare_greater_than_entities(self) -> None:
        """Comparison between entities is done by the ID attribute."""
        small = Entity(id_=2)
        big = Entity(id_=10)

        result = big > small

        assert result
示例#4
0
    def test_hash_uses_the_entity_id_and_model_name(self) -> None:
        """
        Given: A configured entity.
        When: The __hash__ method is used.
        Then: The hash of the identity and model name are used
        """
        entity = Entity(id_=1)

        result = entity.__hash__()

        assert result == hash("Entity-1")
示例#5
0
    def test_compare_less_than_entities(self) -> None:
        """Comparison between entities is done by the ID attribute.

        2 and 10 are deliberately chosen to avoid disordering if we transform id's to
        strings.
        """
        small = Entity(id_=2)
        big = Entity(id_=10)

        result = small < big

        assert result
示例#6
0
    def test_copy_creates_new_object_by_default(self) -> None:
        """
        Given: An entity
        When: copy is called
        Then: The returning entity is not the same object as the original, so if we
            change any attribute in the copy, the original is not changed.
        """
        entity = Entity()

        result = entity.copy()

        result.id_ = 3
        assert entity.id_ == -1
示例#7
0
    def test_model_name_returns_expected_name(self) -> None:
        """
        Given: An entity
        When: model_name is called
        Then: The name of the model is returned
        """
        entity = Entity()

        result = entity.model_name

        assert result == "Entity"
示例#8
0
    def test__model_name_returns_expected_name(self) -> None:
        """
        Given: An entity
        When: _model_name is called
        Then: The name of the model is returned
        """
        entity = Entity()
        with pytest.deprecated_call():

            result = entity._model_name  # noqa: W0212

        assert result == "Entity"