Skip to content

Commit cc16ffd

Browse files
committed
added test case
1 parent 39d995b commit cc16ffd

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_api/test_api_sqla_with_includes.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,41 @@ async def test_update_to_many_relationships(self, async_session: AsyncSession, c
18291829
],
18301830
}
18311831

1832+
async def test_remove_to_one_relationship_using_by_update(self, async_session: AsyncSession):
1833+
resource_type = "self_relationship"
1834+
app = build_app_custom(
1835+
model=SelfRelationship,
1836+
schema=SelfRelationshipSchema,
1837+
resource_type=resource_type,
1838+
)
1839+
1840+
parent_obj = SelfRelationship(name=fake.name())
1841+
child_obj = SelfRelationship(name=fake.name(), self_relationship=parent_obj)
1842+
async_session.add_all([parent_obj, child_obj])
1843+
await async_session.commit()
1844+
1845+
assert child_obj.self_relationship_id == parent_obj.id
1846+
1847+
async with AsyncClient(app=app, base_url="http://test") as client:
1848+
update_body = {
1849+
"data": {
1850+
"attributes": {
1851+
"name": fake.name(),
1852+
},
1853+
"relationships": {
1854+
"self_relationship": {
1855+
"data": None,
1856+
},
1857+
},
1858+
},
1859+
}
1860+
url = app.url_path_for(f"update_{resource_type}_detail", obj_id=child_obj.id)
1861+
res = await client.patch(url, json=update_body)
1862+
assert res.status_code == status.HTTP_200_OK, res.text
1863+
1864+
await async_session.refresh(child_obj)
1865+
assert child_obj.self_relationship_id is None
1866+
18321867

18331868
class TestPatchObjectRelationshipsToOne:
18341869
async def test_ok_when_foreign_key_of_related_object_is_nullable(

0 commit comments

Comments
 (0)