Skip to content

Commit b494574

Browse files
committed
Add test for cached model typehint bug.
1 parent e92f551 commit b494574

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

tests/views/action_parsers/call_method/test_call_method_name.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ def test_call_method_name_with_kwarg():
5757
expected = 3
5858

5959
component = FakeComponent(component_name="test", component_id="asdf")
60-
actual = _call_method_name(component, "save_with_kwarg", args=tuple(),
61-
kwargs=MappingProxyType({"id": 2}))
60+
actual = _call_method_name(
61+
component, "save_with_kwarg", args=tuple(), kwargs=MappingProxyType({"id": 2})
62+
)
6263

6364
assert actual == expected
6465

@@ -76,23 +77,62 @@ def test_call_method_name_arg_with_model_type_annotation():
7677
assert actual == flavor.pk
7778

7879

80+
@pytest.mark.django_db
81+
def test_call_method_name_arg_with_model_type_annotation_multiple():
82+
flavor_one = Flavor()
83+
flavor_one.save()
84+
85+
flavor_two = Flavor()
86+
flavor_two.save()
87+
88+
assert flavor_one.pk != flavor_two.pk
89+
90+
component = FakeComponent(component_name="test", component_id="asdf")
91+
actual = _call_method_name(
92+
component, "save_with_model", args=(flavor_one.pk,), kwargs={}
93+
)
94+
assert actual == flavor_one.pk
95+
96+
# second call
97+
actual = _call_method_name(
98+
component, "save_with_model", args=(flavor_two.pk,), kwargs={}
99+
)
100+
assert actual == flavor_two.pk
101+
102+
# third call
103+
actual = _call_method_name(
104+
component, "save_with_model", args=(flavor_one.pk,), kwargs={}
105+
)
106+
assert actual == flavor_one.pk
107+
108+
# fourth call
109+
actual = _call_method_name(
110+
component, "save_with_model", args=(flavor_one.pk,), kwargs={}
111+
)
112+
assert actual == flavor_one.pk
113+
114+
79115
@pytest.mark.django_db
80116
def test_call_method_name_kwarg_with_model_type_annotation():
81117
flavor = Flavor()
82118
flavor.save()
83119

84120
component = FakeComponent(component_name="test", component_id="asdf")
85121
actual = _call_method_name(
86-
component, "save_with_model", args=tuple(), kwargs=MappingProxyType({"pk": flavor.pk})
122+
component,
123+
"save_with_model",
124+
args=tuple(),
125+
kwargs=MappingProxyType({"pk": flavor.pk}),
87126
)
88127

89128
assert actual == flavor.pk
90129

91130

92131
def test_call_method_name_with_kwarg_with_union_and_int():
93132
component = FakeComponent(component_name="test", component_id="asdf")
94-
actual = _call_method_name(component, "save_with_union", args=tuple(),
95-
kwargs=MappingProxyType({"id": 2}))
133+
actual = _call_method_name(
134+
component, "save_with_union", args=tuple(), kwargs=MappingProxyType({"id": 2})
135+
)
96136

97137
assert isinstance(actual, int)
98138

0 commit comments

Comments
 (0)