-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#383] Support add segments when create case settings
- Loading branch information
1 parent
a08b19f
commit 4ac43b7
Showing
5 changed files
with
162 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import sys | ||
import pytest | ||
|
||
from fastapi import FastAPI | ||
from httpx import AsyncClient | ||
from sqlalchemy.orm import Session | ||
from tests.test_000_main import Acc | ||
|
||
from models.case import LivingIncomeStudyEnum | ||
from models.case_commodity import CaseCommodityType | ||
|
||
sys.path.append("..") | ||
|
||
non_admin_account = Acc(email="editor@akvo.org", token=None) | ||
admin_account = Acc(email="super_admin@akvo.org", token=None) | ||
|
||
|
||
class TestCaseWithSegmentRoute: | ||
@pytest.mark.asyncio | ||
async def test_create_not_private_case( | ||
self, app: FastAPI, session: Session, client: AsyncClient | ||
) -> None: | ||
payload = { | ||
"name": "Bali Rice and Corn with Segment", | ||
"description": "This is a description", | ||
"date": "2024-10-03", | ||
"year": 2024, | ||
"country": 2, | ||
"focus_commodity": 2, | ||
"currency": "USD", | ||
"area_size_unit": "hectare", | ||
"volume_measurement_unit": "liters", | ||
"cost_of_production_unit": "Per-area", | ||
"reporting_period": "Per-season", | ||
"segmentation": False, | ||
"living_income_study": LivingIncomeStudyEnum.better_income.value, | ||
"multiple_commodities": False, | ||
"other_commodities": [ | ||
{ | ||
"commodity": 3, | ||
"breakdown": True, | ||
"commodity_type": CaseCommodityType.secondary.value, | ||
"volume_measurement_unit": "liters", | ||
"area_size_unit": "hectare", | ||
} | ||
], | ||
"tags": [1], | ||
"company": 1, | ||
"segments": [ | ||
{ | ||
"name": "Segment 1 Name", | ||
"number_of_farmers": 10, | ||
}, | ||
{ | ||
"name": "Segment 2 Name", | ||
"number_of_farmers": 8, | ||
}, | ||
], | ||
} | ||
# with admin user cred | ||
res = await client.post( | ||
app.url_path_for("case:create"), | ||
headers={"Authorization": f"Bearer {admin_account.token}"}, | ||
json=payload, | ||
) | ||
assert res.status_code == 200 | ||
res = res.json() | ||
assert res == { | ||
"id": 12, | ||
"name": "Bali Rice and Corn with Segment", | ||
"description": "This is a description", | ||
"date": "2024-10-03", | ||
"year": 2024, | ||
"country": 2, | ||
"focus_commodity": 2, | ||
"currency": "USD", | ||
"area_size_unit": "hectare", | ||
"volume_measurement_unit": "liters", | ||
"cost_of_production_unit": "Per-area", | ||
"reporting_period": "Per-season", | ||
"segmentation": False, | ||
"living_income_study": "better_income", | ||
"multiple_commodities": False, | ||
"logo": None, | ||
"created_by": 1, | ||
"segments": [ | ||
{ | ||
"id": 4, | ||
"case": 12, | ||
"name": "Segment 1 Name", | ||
"region": None, | ||
"target": None, | ||
"adult": None, | ||
"child": None, | ||
}, | ||
{ | ||
"id": 5, | ||
"case": 12, | ||
"name": "Segment 2 Name", | ||
"region": None, | ||
"target": None, | ||
"adult": None, | ||
"child": None, | ||
}, | ||
], | ||
"case_commodities": [ | ||
{ | ||
"id": 13, | ||
"commodity": 2, | ||
"breakdown": True, | ||
"commodity_type": "focus", | ||
"area_size_unit": "hectare", | ||
"volume_measurement_unit": "liters", | ||
}, | ||
{ | ||
"id": 14, | ||
"commodity": 3, | ||
"breakdown": True, | ||
"commodity_type": "secondary", | ||
"area_size_unit": "hectare", | ||
"volume_measurement_unit": "liters", | ||
}, | ||
{ | ||
"id": 15, | ||
"commodity": None, | ||
"breakdown": True, | ||
"commodity_type": "diversified", | ||
"area_size_unit": "hectare", | ||
"volume_measurement_unit": "liters", | ||
}, | ||
], | ||
"private": False, | ||
"tags": [1], | ||
"company": 1, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters