|
19 | 19 |
|
20 | 20 | from fastapi_jsonapi.views.view_base import ViewBase |
21 | 21 | from tests.common import is_postgres_tests |
22 | | -from tests.fixtures.app import build_app_custom |
| 22 | +from tests.fixtures.app import ResourceInfoDTO, build_app_custom, build_custom_app_by_schemas |
23 | 23 | from tests.fixtures.entities import build_workplace, create_user |
24 | 24 | from tests.misc.utils import fake |
25 | 25 | from tests.models import ( |
| 26 | + Alpha, |
| 27 | + Beta, |
26 | 28 | Computer, |
27 | 29 | ContainsTimestamp, |
28 | 30 | CustomUUIDItem, |
| 31 | + Delta, |
| 32 | + Gamma, |
29 | 33 | Post, |
30 | 34 | PostComment, |
31 | 35 | SelfRelationship, |
|
34 | 38 | Workplace, |
35 | 39 | ) |
36 | 40 | from tests.schemas import ( |
| 41 | + AlphaSchema, |
| 42 | + BetaSchema, |
37 | 43 | CustomUserAttributesSchema, |
38 | 44 | CustomUUIDItemAttributesSchema, |
| 45 | + DeltaSchema, |
| 46 | + GammaSchema, |
39 | 47 | PostAttributesBaseSchema, |
40 | 48 | PostCommentAttributesBaseSchema, |
41 | 49 | SelfRelationshipSchema, |
@@ -2740,6 +2748,99 @@ async def test_join_by_relationships_works_correctly_with_many_filters_for_one_f |
2740 | 2748 | "meta": {"count": 0, "totalPages": 1}, |
2741 | 2749 | } |
2742 | 2750 |
|
| 2751 | + async def test_join_by_relationships_for_one_model_by_different_join_chains( |
| 2752 | + self, |
| 2753 | + async_session: AsyncSession, |
| 2754 | + ): |
| 2755 | + app = build_custom_app_by_schemas( |
| 2756 | + [ |
| 2757 | + ResourceInfoDTO( |
| 2758 | + path="/alpha", |
| 2759 | + resource_type="alpha", |
| 2760 | + model=Alpha, |
| 2761 | + schema_=AlphaSchema, |
| 2762 | + ), |
| 2763 | + ResourceInfoDTO( |
| 2764 | + path="/beta", |
| 2765 | + resource_type="beta", |
| 2766 | + model=Beta, |
| 2767 | + schema_=BetaSchema, |
| 2768 | + ), |
| 2769 | + ResourceInfoDTO( |
| 2770 | + path="/gamma", |
| 2771 | + resource_type="gamma", |
| 2772 | + model=Gamma, |
| 2773 | + schema_=GammaSchema, |
| 2774 | + ), |
| 2775 | + ResourceInfoDTO( |
| 2776 | + path="/delta", |
| 2777 | + resource_type="delta", |
| 2778 | + model=Delta, |
| 2779 | + schema_=DeltaSchema, |
| 2780 | + ), |
| 2781 | + ], |
| 2782 | + ) |
| 2783 | + |
| 2784 | + # acc_1 = Account(name="account-1") |
| 2785 | + # role_1 = Role(delta=acc_1) |
| 2786 | + # user_1 = User() |
| 2787 | + |
| 2788 | + delta_1 = Delta(name="delta_1") |
| 2789 | + beta_1, beta_2 = Beta(), Beta() |
| 2790 | + |
| 2791 | + gamma_1 = Gamma(delta=delta_1) |
| 2792 | + gamma_1.betas = [beta_1] |
| 2793 | + gamma_2 = Gamma(delta=delta_1) |
| 2794 | + gamma_2.betas = [beta_2] |
| 2795 | + delta_1.betas = [beta_1, beta_2] |
| 2796 | + |
| 2797 | + delta_2 = Delta(name="delta_2") |
| 2798 | + beta_3 = Beta() |
| 2799 | + beta_4 = Beta() |
| 2800 | + gamma_3 = Gamma(delta=delta_2) |
| 2801 | + gamma_3.betas = [beta_3] |
| 2802 | + gamma_4 = Gamma(delta=delta_2) |
| 2803 | + gamma_4.betas = [beta_4] |
| 2804 | + delta_2.betas = [beta_3, beta_4] |
| 2805 | + |
| 2806 | + alpha_1 = Alpha(beta=beta_1, gamma=gamma_3) |
| 2807 | + alpha_2 = Alpha(beta=beta_3, gamma=gamma_3) |
| 2808 | + |
| 2809 | + async_session.add_all( |
| 2810 | + [ |
| 2811 | + delta_1, |
| 2812 | + delta_2, |
| 2813 | + gamma_1, |
| 2814 | + gamma_2, |
| 2815 | + gamma_3, |
| 2816 | + gamma_4, |
| 2817 | + alpha_1, |
| 2818 | + alpha_2, |
| 2819 | + ], |
| 2820 | + ) |
| 2821 | + await async_session.commit() |
| 2822 | + |
| 2823 | + async with AsyncClient(app=app, base_url="http://test") as client: |
| 2824 | + params = { |
| 2825 | + "filter": json.dumps( |
| 2826 | + [ |
| 2827 | + {"name": "beta.gammas.delta.name", "op": "ilike", "val": delta_1.name}, |
| 2828 | + {"name": "gamma.delta.name", "op": "ilike", "val": delta_2.name}, |
| 2829 | + ], |
| 2830 | + ), |
| 2831 | + } |
| 2832 | + |
| 2833 | + resource_type = "alpha" |
| 2834 | + url = app.url_path_for(f"get_{resource_type}_list") |
| 2835 | + response = await client.get(url, params=params) |
| 2836 | + |
| 2837 | + assert response.status_code == status.HTTP_200_OK, response.text |
| 2838 | + assert response.json() == { |
| 2839 | + "data": [{"attributes": {}, "id": str(alpha_1.id), "type": "alpha"}], |
| 2840 | + "jsonapi": {"version": "1.0"}, |
| 2841 | + "meta": {"count": 1, "totalPages": 1}, |
| 2842 | + } |
| 2843 | + |
2743 | 2844 |
|
2744 | 2845 | ASCENDING = "" |
2745 | 2846 | DESCENDING = "-" |
|
0 commit comments