from django.test import TestCase from django.contrib.auth import get_user_model from rest_framework.test import APIClient from rest_framework import status from apps.diplomacy.models import RepresentativeReport, ReportStatus User = get_user_model() class Phase9DiplomacyAPITests(TestCase): """ Automated test suite for Phase 9: International Diplomacy & Field Reports (Module 6.5) - Periodic Report Submission by Field Representative - Report Listing & Region Hub Filtering - Report Detail Retrieval - Headquarters Review, Approval, and Feedback Directives """ def setUp(self): self.client = APIClient() self.representative = User.objects.create_user( email="rep.africa@astan.org", password="Password123!", fullname="Hujjat al-Islam Seyed Reza", user_type=User.UserType.REGIONAL_ADMIN, ) self.hq_admin = User.objects.create_user( email="headquarters@astan.ir", password="AdminPassword123!", fullname="Director of International Relations", user_type=User.UserType.SUPER_ADMIN, is_staff=True, ) def test_submit_field_activity_report(self): self.client.force_authenticate(user=self.representative) payload = { "title": "East Africa Q1 2026 Cultural Mission Report", "region_hub": "East Africa Regional Hub (Kenya & Tanzania)", "period": "Q1 2026", "activities_summary": "Conducted bilateral meetings with 14 community leaders and inspected educational library centers in Nairobi and Dar es Salaam.", "centers_visited_count": 14, "key_achievements": "Signed preliminary MOU for translation of 5 Razavi books into Swahili.", "challenges_and_needs": "Logistical support required for audio recording studio equipment.", } response = self.client.post("/api/v1/diplomacy/reports/", payload, format="json") self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data["status"], ReportStatus.SUBMITTED) self.assertEqual(response.data["centers_visited_count"], 14) report_id = response.data["id"] # List reports list_res = self.client.get("/api/v1/diplomacy/reports/") self.assertEqual(list_res.status_code, status.HTTP_200_OK) self.assertEqual(len(list_res.data), 1) # Headquarters reviews and approves self.client.force_authenticate(user=self.hq_admin) review_payload = { "status": ReportStatus.APPROVED, "feedback_notes": "Commendable mission outcomes. Audio studio budget has been allocated for Q2.", } review_res = self.client.patch(f"/api/v1/diplomacy/reports/{report_id}/review/", review_payload, format="json") self.assertEqual(review_res.status_code, status.HTTP_200_OK) self.assertEqual(review_res.data["status"], ReportStatus.APPROVED) self.assertEqual(review_res.data["feedback_notes"], review_payload["feedback_notes"])