| 1528 | return Post, Blog, lazy_posts |
| 1529 | |
| 1530 | def test_lazy_add(self): |
| 1531 | Post, Blog, lazy_posts = self._fixture() |
| 1532 | |
| 1533 | p1, p2, p3 = Post("post 1"), Post("post 2"), Post("post 3") |
| 1534 | lazy_posts.return_value = attributes.PASSIVE_NO_RESULT |
| 1535 | |
| 1536 | b = Blog("blog 1") |
| 1537 | b1_state = attributes.instance_state(b) |
| 1538 | |
| 1539 | p = Post("post 4") |
| 1540 | |
| 1541 | p.blog = b |
| 1542 | eq_( |
| 1543 | lazy_posts.mock_calls, |
| 1544 | [call(b1_state, attributes.PASSIVE_NO_FETCH)], |
| 1545 | ) |
| 1546 | |
| 1547 | p = Post("post 5") |
| 1548 | |
| 1549 | # setting blog doesn't call 'posts' callable, calls with no fetch |
| 1550 | p.blog = b |
| 1551 | eq_( |
| 1552 | lazy_posts.mock_calls, |
| 1553 | [ |
| 1554 | call(b1_state, attributes.PASSIVE_NO_FETCH), |
| 1555 | call(b1_state, attributes.PASSIVE_NO_FETCH), |
| 1556 | ], |
| 1557 | ) |
| 1558 | |
| 1559 | lazy_posts.return_value = [p1, p2, p3] |
| 1560 | |
| 1561 | # calling backref calls the callable, populates extra posts |
| 1562 | eq_(b.posts, [p1, p2, p3, Post("post 4"), Post("post 5")]) |
| 1563 | eq_( |
| 1564 | lazy_posts.mock_calls, |
| 1565 | [ |
| 1566 | call(b1_state, attributes.PASSIVE_NO_FETCH), |
| 1567 | call(b1_state, attributes.PASSIVE_NO_FETCH), |
| 1568 | call(b1_state, attributes.PASSIVE_OFF), |
| 1569 | ], |
| 1570 | ) |
| 1571 | |
| 1572 | def test_lazy_history_collection(self): |
| 1573 | Post, Blog, lazy_posts = self._fixture() |