(db)
| 207 | |
| 208 | @pytest.mark.asyncio |
| 209 | async def test_self_ref(db): |
| 210 | root = await Employee.create(name="Root") |
| 211 | loose = await Employee.create(name="Loose") |
| 212 | _1 = await Employee.create(name="1. First H1", manager=root) |
| 213 | _2 = await Employee.create(name="2. Second H1", manager=root) |
| 214 | _1_1 = await Employee.create(name="1.1. First H2", manager=_1) |
| 215 | _1_1_1 = await Employee.create(name="1.1.1. First H3", manager=_1_1) |
| 216 | _2_1 = await Employee.create(name="2.1. Second H2", manager=_2) |
| 217 | _2_2 = await Employee.create(name="2.2. Third H2", manager=_2) |
| 218 | |
| 219 | await _1.talks_to.add(_2, _1_1_1, loose) |
| 220 | await _2_1.gets_talked_to.add(_2_2, _1_1, loose) |
| 221 | |
| 222 | LOOSE_TEXT = "Loose (to: 2.1. Second H2) (from: 1. First H1)" |
| 223 | ROOT_TEXT = """Root (to: ) (from: ) |
| 224 | 1. First H1 (to: 1.1.1. First H3, 2. Second H1, Loose) (from: ) |
| 225 | 1.1. First H2 (to: 2.1. Second H2) (from: ) |
| 226 | 1.1.1. First H3 (to: ) (from: 1. First H1) |
| 227 | 2. Second H1 (to: ) (from: 1. First H1) |
| 228 | 2.1. Second H2 (to: ) (from: 1.1. First H2, 2.2. Third H2, Loose) |
| 229 | 2.2. Third H2 (to: 2.1. Second H2) (from: )""" |
| 230 | |
| 231 | # Evaluated off creation objects |
| 232 | assert await loose.full_hierarchy__async_for() == LOOSE_TEXT |
| 233 | assert await loose.full_hierarchy__fetch_related() == LOOSE_TEXT |
| 234 | assert await root.full_hierarchy__async_for() == ROOT_TEXT |
| 235 | assert await root.full_hierarchy__fetch_related() == ROOT_TEXT |
| 236 | |
| 237 | # Evaluated off new objects -> Result is identical |
| 238 | root2 = await Employee.get(name="Root") |
| 239 | loose2 = await Employee.get(name="Loose") |
| 240 | assert await loose2.full_hierarchy__async_for() == LOOSE_TEXT |
| 241 | assert await loose2.full_hierarchy__fetch_related() == LOOSE_TEXT |
| 242 | assert await root2.full_hierarchy__async_for() == ROOT_TEXT |
| 243 | assert await root2.full_hierarchy__fetch_related() == ROOT_TEXT |
| 244 | |
| 245 | |
| 246 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected
searching dependent graphs…