this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Test cases for activity definitions (#3190)

* fix:updated the availability_stats filtering lookup with date

* feat:implemented setup

* feat:added create testcases for activity definition

* feat:added update testcases

* feat:added common slug validation

* feat:added list testcases

* feat:added common slug validation

* fix:slug validation

* fix:slug validation

* fix:added some minor changes

* fix:added slug tests

* fix:add facility check in the slug validation

* refact:added changes as per the new updates

* fix:removed invalid flag usage

* revert care/emr/resources/activity_definition/spec.py

---------

Co-authored-by: Aakash Singh <mail@singhaakash.dev>

authored by

Nandkishor R
Aakash Singh
and committed by
GitHub
a0bfe6dd bd89cee8

+1297 -3
+2 -3
care/emr/api/viewsets/activity_definition.py
··· 78 78 ) 79 79 if not obj: 80 80 error_msg = ( 81 - f"Specimen Definition with id {specimen_requirement} not found" 81 + f"Specimen Definition with slug {specimen_requirement} not found" 82 82 ) 83 83 raise ValidationError(error_msg) 84 84 ids.append(obj.id) ··· 93 93 ) 94 94 if not obj: 95 95 error_msg = ( 96 - f"Observation Definition with id {observation_result} not found" 96 + f"Observation Definition with slug {observation_result} not found" 97 97 ) 98 98 raise ValidationError(error_msg) 99 99 ids.append(obj.id) ··· 155 155 get_object_or_404( 156 156 ResourceCategory, slug=instance.category, facility=facility 157 157 ) 158 - 159 158 return super().validate_data(instance, model_obj) 160 159 161 160 def perform_create(self, instance):
+1295
care/emr/tests/test_activity_definition_api.py
··· 1 + import uuid 2 + 3 + from django.urls import reverse 4 + from model_bakery import baker 5 + 6 + from care.emr.resources.activity_definition.spec import ( 7 + ActivityDefinitionCategoryOptions, 8 + ActivityDefinitionKindOptions, 9 + ActivityDefinitionStatusOptions, 10 + ) 11 + from care.security.permissions.activity_definition import ActivityDefinitionPermissions 12 + from care.utils.tests.base import CareAPITestBase 13 + 14 + 15 + class ActivityDefinitionAPITestBase(CareAPITestBase): 16 + def setUp(self): 17 + super().setUp() 18 + self.user = self.create_user(username="TestUser") 19 + self.superuser = self.create_super_user(username="SuperUser") 20 + self.facility = self.create_facility(name="Test Facility", user=self.superuser) 21 + self.facility_organization = self.create_facility_organization( 22 + name="Test Facility Organization", facility=self.facility, org_type="root" 23 + ) 24 + self.role = self.create_role_with_permissions( 25 + permissions=[ 26 + ActivityDefinitionPermissions.can_read_activity_definition.name, 27 + ActivityDefinitionPermissions.can_write_activity_definition.name, 28 + ] 29 + ) 30 + self.base_url = self.get_base_url(facility=self.facility.external_id) 31 + self.facility_location = self.create_facility_location( 32 + facility=self.facility, name="Test Facility Location" 33 + ) 34 + self.resource_category = self.create_resource_category( 35 + facility=self.facility, slug="resource-category", title="Resource Category" 36 + ) 37 + 38 + def generate_activity_definition_data( 39 + self, 40 + title=None, 41 + status=None, 42 + category=None, 43 + kind=None, 44 + classification=None, 45 + **kwargs, 46 + ): 47 + return { 48 + "title": title or "Test Activity Definition", 49 + "derived_from_uri": None, 50 + "status": status or ActivityDefinitionStatusOptions.active.value, 51 + "description": "This is a test activity definition.", 52 + "usage": "Test usage", 53 + "category": category or self.resource_category.slug, 54 + "classification": classification 55 + or ActivityDefinitionCategoryOptions.laboratory.value, 56 + "kind": kind or ActivityDefinitionKindOptions.service_request.value, 57 + "code": {"system": "http://example.com", "code": "12345"}, 58 + "body_site": None, 59 + "diagnostic_report_codes": [], 60 + **kwargs, 61 + } 62 + 63 + def create_activity_definition(self, facility, slug, **kwargs): 64 + data = self.generate_activity_definition_data(**kwargs) 65 + return baker.make( 66 + "emr.ActivityDefinition", 67 + **data, 68 + facility=facility, 69 + slug=f"f-{facility.external_id}-{slug}", 70 + specimen_requirements=[self.generate_specimen_definition(facility).id], 71 + observation_result_requirements=[ 72 + self.generate_observation_definition(facility).id 73 + ], 74 + healthcare_service=self.generate_healthcare_service(facility), 75 + charge_item_definitions=[self.charge_item_definition(facility).id], 76 + ) 77 + 78 + def get_details_url(self, facility=None, slug=None): 79 + return reverse( 80 + "activity_definition-detail", 81 + kwargs={"facility_external_id": facility, "slug": slug}, 82 + ) 83 + 84 + def get_base_url(self, facility=None): 85 + return reverse( 86 + "activity_definition-list", 87 + kwargs={"facility_external_id": facility}, 88 + ) 89 + 90 + def generate_specimen_definition(self, facility): 91 + return baker.make( 92 + "emr.SpecimenDefinition", 93 + slug=f"f-{facility.external_id}-specimen-definition", 94 + title="Test Specimen Definition", 95 + description="This is a test specimen definition.", 96 + facility=facility, 97 + ) 98 + 99 + def generate_observation_definition(self, facility): 100 + return baker.make( 101 + "emr.ObservationDefinition", 102 + slug=f"f-{facility.external_id}-observation-definition", 103 + title="Test Observation Definition", 104 + description="This is a test observation definition.", 105 + facility=facility, 106 + ) 107 + 108 + def generate_healthcare_service(self, facility): 109 + return baker.make( 110 + "emr.HealthcareService", name="Test Healthcare Service", facility=facility 111 + ) 112 + 113 + def charge_item_definition(self, facility): 114 + return baker.make( 115 + "emr.ChargeItemDefinition", 116 + slug=f"f-{facility.external_id}-charge-item-definition", 117 + title="Test Charge Item Definition", 118 + description="This is a test charge item definition.", 119 + facility=facility, 120 + ) 121 + 122 + def create_facility_location(self, facility, **kwargs): 123 + return baker.make("emr.FacilityLocation", facility=facility, **kwargs) 124 + 125 + def create_resource_category(self, facility, slug=None, **kwargs): 126 + return baker.make( 127 + "emr.ResourceCategory", 128 + facility=facility, 129 + slug=f"f-{facility.external_id}-{slug or 'resource-category'}", 130 + resource_type="test-resource-type", 131 + **kwargs, 132 + ) 133 + 134 + # Test cases for create activity definition 135 + 136 + def test_create_activity_definition_as_superuser(self): 137 + """Test creating an activity definition as a superuser""" 138 + 139 + self.client.force_authenticate(user=self.superuser) 140 + data = self.generate_activity_definition_data( 141 + slug_value="test-activity-definition", 142 + specimen_requirements=[ 143 + self.generate_specimen_definition(self.facility).slug 144 + ], 145 + observation_result_requirements=[ 146 + self.generate_observation_definition(self.facility).slug 147 + ], 148 + healthcare_service=self.generate_healthcare_service( 149 + self.facility 150 + ).external_id, 151 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 152 + locations=[self.facility_location.external_id], 153 + ) 154 + response = self.client.post(self.base_url, data, format="json") 155 + self.assertEqual(response.status_code, 200) 156 + get_response = self.client.get( 157 + self.get_details_url( 158 + facility=self.facility.external_id, 159 + slug=response.data["slug"], 160 + ) 161 + ) 162 + self.assertEqual(get_response.status_code, 200) 163 + self.assertEqual(get_response.data["id"], response.data["id"]) 164 + 165 + def test_create_activity_definition_as_user_with_permissions(self): 166 + """Test creating an activity definition as a user with permissions""" 167 + self.attach_role_facility_organization_user( 168 + user=self.user, 169 + facility_organization=self.facility_organization, 170 + role=self.role, 171 + ) 172 + self.client.force_authenticate(user=self.user) 173 + data = self.generate_activity_definition_data( 174 + slug_value="test-activity-definition", 175 + specimen_requirements=[ 176 + self.generate_specimen_definition(self.facility).slug 177 + ], 178 + observation_result_requirements=[ 179 + self.generate_observation_definition(self.facility).slug 180 + ], 181 + healthcare_service=self.generate_healthcare_service( 182 + self.facility 183 + ).external_id, 184 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 185 + locations=[self.facility_location.external_id], 186 + ) 187 + response = self.client.post(self.base_url, data, format="json") 188 + self.assertEqual(response.status_code, 200) 189 + get_response = self.client.get( 190 + self.get_details_url( 191 + facility=self.facility.external_id, 192 + slug=response.data["slug"], 193 + ) 194 + ) 195 + self.assertEqual(get_response.status_code, 200) 196 + self.assertEqual(get_response.data["id"], response.data["id"]) 197 + 198 + def test_create_activity_definition_as_user_without_permissions(self): 199 + """Test creating an activity definition as a user without permissions""" 200 + self.client.force_authenticate(user=self.user) 201 + data = self.generate_activity_definition_data( 202 + slug_value="test-activity-definition", 203 + specimen_requirements=[ 204 + self.generate_specimen_definition(self.facility).slug 205 + ], 206 + observation_result_requirements=[ 207 + self.generate_observation_definition(self.facility).slug 208 + ], 209 + healthcare_service=self.generate_healthcare_service( 210 + self.facility 211 + ).external_id, 212 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 213 + locations=[self.facility_location.external_id], 214 + ) 215 + response = self.client.post(self.base_url, data, format="json") 216 + self.assertEqual(response.status_code, 403) 217 + 218 + def test_create_activity_definition_with_invalid_facility(self): 219 + """Test creating an activity definition with an invalid facility""" 220 + self.client.force_authenticate(user=self.superuser) 221 + data = self.generate_activity_definition_data( 222 + slug_value="test-activity-definition", 223 + specimen_requirements=[ 224 + self.generate_specimen_definition(self.facility).slug 225 + ], 226 + observation_result_requirements=[ 227 + self.generate_observation_definition(self.facility).slug 228 + ], 229 + healthcare_service=self.generate_healthcare_service( 230 + self.facility 231 + ).external_id, 232 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 233 + locations=[self.facility_location.external_id], 234 + ) 235 + response = self.client.post( 236 + self.get_base_url(facility="invalid-facility-id"), data, format="json" 237 + ) 238 + self.assertEqual(response.status_code, 404) 239 + 240 + def test_create_activity_definition_with_invalid_specimen(self): 241 + """Test creating an activity definition with an invalid specimen""" 242 + self.client.force_authenticate(user=self.superuser) 243 + another_facility = self.create_facility( 244 + name="Another Facility", user=self.superuser 245 + ) 246 + invalid_specimen = self.generate_specimen_definition(another_facility) 247 + data = self.generate_activity_definition_data( 248 + slug_value="test-activity-definition", 249 + specimen_requirements=[invalid_specimen.slug], 250 + observation_result_requirements=[ 251 + self.generate_observation_definition(self.facility).slug 252 + ], 253 + healthcare_service=self.generate_healthcare_service( 254 + self.facility 255 + ).external_id, 256 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 257 + locations=[self.facility_location.external_id], 258 + ) 259 + response = self.client.post(self.base_url, data, format="json") 260 + self.assertEqual(response.status_code, 400) 261 + self.assertContains( 262 + response, 263 + f"Specimen Definition with slug {invalid_specimen.slug} not found", 264 + status_code=400, 265 + ) 266 + 267 + def test_create_activity_definition_with_invalid_observation(self): 268 + """Test creating an activity definition with an invalid observation""" 269 + self.client.force_authenticate(user=self.superuser) 270 + another_facility = self.create_facility( 271 + name="Another Facility", user=self.superuser 272 + ) 273 + invalid_observation = self.generate_observation_definition(another_facility) 274 + data = self.generate_activity_definition_data( 275 + slug_value="test-activity-definition", 276 + specimen_requirements=[ 277 + self.generate_specimen_definition(self.facility).slug 278 + ], 279 + observation_result_requirements=[invalid_observation.slug], 280 + healthcare_service=self.generate_healthcare_service( 281 + self.facility 282 + ).external_id, 283 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 284 + locations=[self.facility_location.external_id], 285 + ) 286 + response = self.client.post(self.base_url, data, format="json") 287 + self.assertEqual(response.status_code, 400) 288 + self.assertContains( 289 + response, 290 + f"Observation Definition with slug {invalid_observation.slug} not found", 291 + status_code=400, 292 + ) 293 + 294 + def test_create_activity_definition_with_invalid_location(self): 295 + """Test creating an activity definition with an invalid location""" 296 + self.client.force_authenticate(user=self.superuser) 297 + invalid_location_id = uuid.uuid4() 298 + data = self.generate_activity_definition_data( 299 + slug_value="test-activity-definition", 300 + specimen_requirements=[ 301 + self.generate_specimen_definition(self.facility).slug 302 + ], 303 + observation_result_requirements=[ 304 + self.generate_observation_definition(self.facility).slug 305 + ], 306 + healthcare_service=self.generate_healthcare_service( 307 + self.facility 308 + ).external_id, 309 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 310 + locations=[invalid_location_id], 311 + ) 312 + response = self.client.post(self.base_url, data, format="json") 313 + self.assertEqual(response.status_code, 400) 314 + self.assertContains( 315 + response, f"Location with id {invalid_location_id}", status_code=400 316 + ) 317 + 318 + def test_create_activity_definition_with_invalid_charge_item(self): 319 + """Test creating an activity definition with an invalid charge item""" 320 + self.client.force_authenticate(user=self.superuser) 321 + another_facility = self.create_facility( 322 + name="Another Facility", user=self.superuser 323 + ) 324 + invalid_charge_item = self.charge_item_definition(another_facility) 325 + data = self.generate_activity_definition_data( 326 + slug_value="test-activity-definition", 327 + specimen_requirements=[ 328 + self.generate_specimen_definition(self.facility).slug 329 + ], 330 + observation_result_requirements=[ 331 + self.generate_observation_definition(self.facility).slug 332 + ], 333 + healthcare_service=self.generate_healthcare_service( 334 + self.facility 335 + ).external_id, 336 + charge_item_definitions=[invalid_charge_item.slug], 337 + locations=[self.facility_location.external_id], 338 + ) 339 + response = self.client.post(self.base_url, data, format="json") 340 + self.assertEqual(response.status_code, 400) 341 + self.assertContains( 342 + response, 343 + f"Charge Item Definition with slug {invalid_charge_item.slug} not found", 344 + status_code=400, 345 + ) 346 + 347 + def test_create_activity_definition_with_invalid_healthcare_service(self): 348 + """Test creating an activity definition with an invalid healthcare service""" 349 + self.client.force_authenticate(user=self.superuser) 350 + another_facility = self.create_facility( 351 + name="Another Facility", user=self.superuser 352 + ) 353 + invalid_healthcare_service_id = self.generate_healthcare_service( 354 + another_facility 355 + ).external_id 356 + data = self.generate_activity_definition_data( 357 + slug_value="test-activity-definition", 358 + specimen_requirements=[ 359 + self.generate_specimen_definition(self.facility).slug 360 + ], 361 + observation_result_requirements=[ 362 + self.generate_observation_definition(self.facility).slug 363 + ], 364 + healthcare_service=invalid_healthcare_service_id, 365 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 366 + locations=[self.facility_location.external_id], 367 + ) 368 + response = self.client.post(self.base_url, data, format="json") 369 + self.assertEqual(response.status_code, 400) 370 + self.assertContains( 371 + response, 372 + "Healthcare Service must be from the same facility", 373 + status_code=400, 374 + ) 375 + 376 + def test_create_activity_definition_with_duplicate_slug(self): 377 + """Test creating an activity definition with a duplicate slug in the same facility""" 378 + self.client.force_authenticate(user=self.superuser) 379 + self.create_activity_definition( 380 + slug="duplicate-slug", 381 + facility=self.facility, 382 + category=self.resource_category, 383 + ) 384 + data = self.generate_activity_definition_data( 385 + slug_value="duplicate-slug", 386 + specimen_requirements=[ 387 + self.generate_specimen_definition(self.facility).slug 388 + ], 389 + observation_result_requirements=[ 390 + self.generate_observation_definition(self.facility).slug 391 + ], 392 + healthcare_service=self.generate_healthcare_service( 393 + self.facility 394 + ).external_id, 395 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 396 + locations=[self.facility_location.external_id], 397 + ) 398 + response = self.client.post(self.base_url, data, format="json") 399 + self.assertEqual(response.status_code, 400) 400 + self.assertContains( 401 + response, 402 + "Activity Definition with this slug already exists.", 403 + status_code=400, 404 + ) 405 + 406 + def test_create_activity_definition_with_duplicate_slug_different_facility(self): 407 + """Test creating an activity definition with a duplicate slug in a different facility""" 408 + self.client.force_authenticate(user=self.superuser) 409 + another_facility = self.create_facility( 410 + name="Another Facility", user=self.superuser 411 + ) 412 + self.create_activity_definition( 413 + slug="duplicate-slug", 414 + facility=another_facility, 415 + category=self.resource_category, 416 + ) 417 + data = self.generate_activity_definition_data( 418 + slug_value="test-activity-definition", 419 + specimen_requirements=[ 420 + self.generate_specimen_definition(self.facility).slug 421 + ], 422 + observation_result_requirements=[ 423 + self.generate_observation_definition(self.facility).slug 424 + ], 425 + healthcare_service=self.generate_healthcare_service( 426 + self.facility 427 + ).external_id, 428 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 429 + locations=[self.facility_location.external_id], 430 + ) 431 + response = self.client.post(self.base_url, data, format="json") 432 + self.assertEqual(response.status_code, 200) 433 + get_response = self.client.get( 434 + self.get_details_url( 435 + facility=self.facility.external_id, 436 + slug=response.data["slug"], 437 + ) 438 + ) 439 + self.assertEqual(get_response.status_code, 200) 440 + self.assertEqual(get_response.data["id"], response.data["id"]) 441 + 442 + def test_create_activity_definition_without_category(self): 443 + """Test creating an activity definition without category""" 444 + self.client.force_authenticate(user=self.superuser) 445 + data = self.generate_activity_definition_data( 446 + slug_value="test-activity-definition", 447 + specimen_requirements=[ 448 + self.generate_specimen_definition(self.facility).slug 449 + ], 450 + observation_result_requirements=[ 451 + self.generate_observation_definition(self.facility).slug 452 + ], 453 + healthcare_service=self.generate_healthcare_service( 454 + self.facility 455 + ).external_id, 456 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 457 + locations=[self.facility_location.external_id], 458 + ) 459 + data.pop("category") 460 + response = self.client.post(self.base_url, data, format="json") 461 + self.assertEqual(response.status_code, 400) 462 + self.assertIn("Field required", response.data["errors"][0]["msg"]) 463 + 464 + # Test cases for update activity definition 465 + 466 + def test_update_activity_definition_as_superuser(self): 467 + """Test updating an activity definition as a superuser""" 468 + self.client.force_authenticate(user=self.superuser) 469 + facility_location2 = self.create_facility_location(facility=self.facility) 470 + activity_definition = self.create_activity_definition( 471 + facility=self.facility, 472 + category=self.resource_category, 473 + slug="Test-Activity-Definition", 474 + ) 475 + data = self.generate_activity_definition_data( 476 + slug_value="updated-definition", 477 + title="Updated Activity Definition", 478 + status=ActivityDefinitionStatusOptions.retired.value, 479 + specimen_requirements=[ 480 + self.generate_specimen_definition(self.facility).slug 481 + ], 482 + observation_result_requirements=[ 483 + self.generate_observation_definition(self.facility).slug 484 + ], 485 + healthcare_service=self.generate_healthcare_service( 486 + self.facility 487 + ).external_id, 488 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 489 + locations=[ 490 + self.facility_location.external_id, 491 + facility_location2.external_id, 492 + ], 493 + ) 494 + response = self.client.put( 495 + self.get_details_url( 496 + facility=self.facility.external_id, 497 + slug=activity_definition.slug, 498 + ), 499 + data, 500 + format="json", 501 + ) 502 + self.assertEqual(response.status_code, 200) 503 + get_response = self.client.get( 504 + self.get_details_url( 505 + facility=self.facility.external_id, 506 + slug=response.data["slug"], 507 + ) 508 + ) 509 + self.assertEqual(get_response.status_code, 200) 510 + get_response_data = self.client.get( 511 + self.get_details_url( 512 + facility=self.facility.external_id, 513 + slug=response.data["slug"], 514 + ) 515 + ).data 516 + self.assertEqual(get_response_data["title"], "Updated Activity Definition") 517 + self.assertEqual( 518 + get_response_data["status"], ActivityDefinitionStatusOptions.retired.value 519 + ) 520 + self.assertEqual( 521 + get_response_data["specimen_requirements"], 522 + response.data["specimen_requirements"], 523 + ) 524 + self.assertEqual( 525 + get_response_data["observation_result_requirements"], 526 + response.data["observation_result_requirements"], 527 + ) 528 + self.assertEqual( 529 + get_response_data["healthcare_service"], response.data["healthcare_service"] 530 + ) 531 + self.assertEqual( 532 + get_response_data["charge_item_definitions"], 533 + response.data["charge_item_definitions"], 534 + ) 535 + self.assertEqual(get_response_data["locations"], response.data["locations"]) 536 + 537 + def test_update_activity_definition_as_user_with_permissions(self): 538 + """Test updating an activity definition as a user with permissions""" 539 + self.attach_role_facility_organization_user( 540 + user=self.user, 541 + facility_organization=self.facility_organization, 542 + role=self.role, 543 + ) 544 + self.client.force_authenticate(user=self.user) 545 + facility_location2 = self.create_facility_location(facility=self.facility) 546 + activity_definition = self.create_activity_definition( 547 + facility=self.facility, 548 + category=self.resource_category, 549 + slug="Test-Activity-Definition", 550 + ) 551 + data = self.generate_activity_definition_data( 552 + slug_value="updated-definition", 553 + title="Updated Activity Definition", 554 + status=ActivityDefinitionStatusOptions.retired.value, 555 + specimen_requirements=[ 556 + self.generate_specimen_definition(self.facility).slug 557 + ], 558 + observation_result_requirements=[ 559 + self.generate_observation_definition(self.facility).slug 560 + ], 561 + healthcare_service=self.generate_healthcare_service( 562 + self.facility 563 + ).external_id, 564 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 565 + locations=[ 566 + self.facility_location.external_id, 567 + facility_location2.external_id, 568 + ], 569 + ) 570 + response = self.client.put( 571 + self.get_details_url( 572 + facility=self.facility.external_id, 573 + slug=activity_definition.slug, 574 + ), 575 + data, 576 + format="json", 577 + ) 578 + self.assertEqual(response.status_code, 200) 579 + get_response = self.client.get( 580 + self.get_details_url( 581 + facility=self.facility.external_id, 582 + slug=response.data["slug"], 583 + ) 584 + ) 585 + self.assertEqual(get_response.status_code, 200) 586 + get_response_data = self.client.get( 587 + self.get_details_url( 588 + facility=self.facility.external_id, 589 + slug=response.data["slug"], 590 + ) 591 + ).data 592 + self.assertEqual(get_response_data["title"], "Updated Activity Definition") 593 + self.assertEqual( 594 + get_response_data["status"], ActivityDefinitionStatusOptions.retired.value 595 + ) 596 + self.assertEqual( 597 + get_response_data["specimen_requirements"], 598 + response.data["specimen_requirements"], 599 + ) 600 + self.assertEqual( 601 + get_response_data["observation_result_requirements"], 602 + response.data["observation_result_requirements"], 603 + ) 604 + self.assertEqual( 605 + get_response_data["healthcare_service"], response.data["healthcare_service"] 606 + ) 607 + self.assertEqual( 608 + get_response_data["charge_item_definitions"], 609 + response.data["charge_item_definitions"], 610 + ) 611 + self.assertEqual(get_response_data["locations"], response.data["locations"]) 612 + 613 + def test_update_activity_definition_as_user_without_permissions(self): 614 + """Test updating an activity definition as a user without permissions""" 615 + self.client.force_authenticate(user=self.user) 616 + activity_definition = self.create_activity_definition( 617 + facility=self.facility, 618 + category=self.resource_category, 619 + slug="Test-Activity-Definition", 620 + ) 621 + data = self.generate_activity_definition_data( 622 + slug_value="updated-definition", 623 + title="Updated Activity Definition", 624 + status=ActivityDefinitionStatusOptions.retired.value, 625 + specimen_requirements=[ 626 + self.generate_specimen_definition(self.facility).slug 627 + ], 628 + observation_result_requirements=[ 629 + self.generate_observation_definition(self.facility).slug 630 + ], 631 + healthcare_service=self.generate_healthcare_service( 632 + self.facility 633 + ).external_id, 634 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 635 + locations=[self.facility_location.external_id], 636 + ) 637 + response = self.client.put( 638 + self.get_details_url( 639 + facility=self.facility.external_id, 640 + slug=activity_definition.slug, 641 + ), 642 + data, 643 + format="json", 644 + ) 645 + self.assertEqual(response.status_code, 403) 646 + 647 + def test_update_activity_definition_with_invalid_facility(self): 648 + """Test updating an activity definition with an invalid facility""" 649 + self.client.force_authenticate(user=self.superuser) 650 + activity_definition = self.create_activity_definition( 651 + facility=self.facility, 652 + category=self.resource_category, 653 + slug="Test-Activity-Definition", 654 + ) 655 + data = self.generate_activity_definition_data( 656 + slug_value="updated-definition", 657 + title="Updated Activity Definition", 658 + status=ActivityDefinitionStatusOptions.retired.value, 659 + specimen_requirements=[ 660 + self.generate_specimen_definition(self.facility).slug 661 + ], 662 + observation_result_requirements=[ 663 + self.generate_observation_definition(self.facility).slug 664 + ], 665 + healthcare_service=self.generate_healthcare_service( 666 + self.facility 667 + ).external_id, 668 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 669 + locations=[self.facility_location.external_id], 670 + ) 671 + response = self.client.put( 672 + self.get_details_url( 673 + facility="invalid-facility-id", 674 + slug=activity_definition.slug, 675 + ), 676 + data, 677 + format="json", 678 + ) 679 + self.assertEqual(response.status_code, 404) 680 + self.assertContains( 681 + response, "No Facility matches the given query.", status_code=404 682 + ) 683 + 684 + def test_update_activity_definition_with_invalid_specimen(self): 685 + """Test updating an activity definition with an invalid specimen""" 686 + self.client.force_authenticate(user=self.superuser) 687 + activity_definition = self.create_activity_definition( 688 + facility=self.facility, 689 + category=self.resource_category, 690 + slug="Test-Activity-Definition", 691 + ) 692 + another_facility = self.create_facility( 693 + name="Another Facility", user=self.superuser 694 + ) 695 + invalid_specimen = self.generate_specimen_definition(another_facility) 696 + data = self.generate_activity_definition_data( 697 + slug_value="updated-definition", 698 + title="Updated Activity Definition", 699 + status=ActivityDefinitionStatusOptions.retired.value, 700 + specimen_requirements=[invalid_specimen.slug], 701 + observation_result_requirements=[ 702 + self.generate_observation_definition(self.facility).slug 703 + ], 704 + healthcare_service=self.generate_healthcare_service( 705 + self.facility 706 + ).external_id, 707 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 708 + locations=[self.facility_location.external_id], 709 + ) 710 + response = self.client.put( 711 + self.get_details_url( 712 + facility=self.facility.external_id, 713 + slug=activity_definition.slug, 714 + ), 715 + data, 716 + format="json", 717 + ) 718 + self.assertEqual(response.status_code, 400) 719 + self.assertContains( 720 + response, 721 + f"Specimen Definition with slug {invalid_specimen.slug} not found", 722 + status_code=400, 723 + ) 724 + 725 + def test_update_activity_definition_with_invalid_observation(self): 726 + """Test updating an activity definition with an invalid observation""" 727 + self.client.force_authenticate(user=self.superuser) 728 + activity_definition = self.create_activity_definition( 729 + facility=self.facility, 730 + category=self.resource_category, 731 + slug="Test-Activity-Definition", 732 + ) 733 + another_facility = self.create_facility( 734 + name="Another Facility", user=self.superuser 735 + ) 736 + invalid_observation = self.generate_observation_definition(another_facility) 737 + 738 + data = self.generate_activity_definition_data( 739 + slug_value="updated-definition", 740 + title="Updated Activity Definition", 741 + status=ActivityDefinitionStatusOptions.retired.value, 742 + specimen_requirements=[ 743 + self.generate_specimen_definition(self.facility).slug 744 + ], 745 + observation_result_requirements=[invalid_observation.slug], 746 + healthcare_service=self.generate_healthcare_service( 747 + self.facility 748 + ).external_id, 749 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 750 + locations=[self.facility_location.external_id], 751 + ) 752 + response = self.client.put( 753 + self.get_details_url( 754 + facility=self.facility.external_id, 755 + slug=activity_definition.slug, 756 + ), 757 + data, 758 + format="json", 759 + ) 760 + self.assertEqual(response.status_code, 400) 761 + self.assertContains( 762 + response, 763 + f"Observation Definition with slug {invalid_observation.slug} not found", 764 + status_code=400, 765 + ) 766 + 767 + def test_update_activity_definition_with_invalid_location(self): 768 + """Test updating an activity definition with an invalid location""" 769 + self.client.force_authenticate(user=self.superuser) 770 + activity_definition = self.create_activity_definition( 771 + facility=self.facility, 772 + category=self.resource_category, 773 + slug="Test-Activity-Definition", 774 + ) 775 + invalid_location_id = uuid.uuid4() 776 + data = self.generate_activity_definition_data( 777 + slug_value="updated-definition", 778 + title="Updated Activity Definition", 779 + status=ActivityDefinitionStatusOptions.retired.value, 780 + specimen_requirements=[ 781 + self.generate_specimen_definition(self.facility).slug 782 + ], 783 + observation_result_requirements=[ 784 + self.generate_observation_definition(self.facility).slug 785 + ], 786 + healthcare_service=self.generate_healthcare_service( 787 + self.facility 788 + ).external_id, 789 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 790 + locations=[invalid_location_id], 791 + ) 792 + response = self.client.put( 793 + self.get_details_url( 794 + facility=self.facility.external_id, 795 + slug=activity_definition.slug, 796 + ), 797 + data, 798 + format="json", 799 + ) 800 + self.assertEqual(response.status_code, 400) 801 + self.assertContains( 802 + response, 803 + f"Location with id {invalid_location_id} not found", 804 + status_code=400, 805 + ) 806 + 807 + def test_update_activity_definition_with_invalid_charge_item(self): 808 + """Test updating an activity definition with an invalid charge item""" 809 + self.client.force_authenticate(user=self.superuser) 810 + activity_definition = self.create_activity_definition( 811 + facility=self.facility, 812 + category=self.resource_category, 813 + slug="Test-Activity-Definition", 814 + ) 815 + another_facility = self.create_facility( 816 + name="Another Facility", user=self.superuser 817 + ) 818 + invalid_charge_item = self.charge_item_definition(another_facility) 819 + data = self.generate_activity_definition_data( 820 + slug_value="updated-definition", 821 + title="Updated Activity Definition", 822 + status=ActivityDefinitionStatusOptions.retired.value, 823 + specimen_requirements=[ 824 + self.generate_specimen_definition(self.facility).slug 825 + ], 826 + observation_result_requirements=[ 827 + self.generate_observation_definition(self.facility).slug 828 + ], 829 + healthcare_service=self.generate_healthcare_service( 830 + self.facility 831 + ).external_id, 832 + charge_item_definitions=[invalid_charge_item.slug], 833 + locations=[self.facility_location.external_id], 834 + ) 835 + response = self.client.put( 836 + self.get_details_url( 837 + facility=self.facility.external_id, 838 + slug=activity_definition.slug, 839 + ), 840 + data, 841 + format="json", 842 + ) 843 + self.assertEqual(response.status_code, 400) 844 + self.assertContains( 845 + response, 846 + f"Charge Item Definition with slug {invalid_charge_item.slug} not found", 847 + status_code=400, 848 + ) 849 + 850 + def test_update_activity_definition_with_invalid_healthcare_service(self): 851 + """Test updating an activity definition with an invalid healthcare service""" 852 + self.client.force_authenticate(user=self.superuser) 853 + activity_definition = self.create_activity_definition( 854 + facility=self.facility, 855 + category=self.resource_category, 856 + slug="Test-Activity-Definition", 857 + ) 858 + another_facility = self.create_facility( 859 + name="Another Facility", user=self.superuser 860 + ) 861 + invalid_healthcare_service_id = self.generate_healthcare_service( 862 + another_facility 863 + ).external_id 864 + data = self.generate_activity_definition_data( 865 + slug_value="updated-definition", 866 + title="Updated Activity Definition", 867 + status=ActivityDefinitionStatusOptions.retired.value, 868 + specimen_requirements=[ 869 + self.generate_specimen_definition(self.facility).slug 870 + ], 871 + observation_result_requirements=[ 872 + self.generate_observation_definition(self.facility).slug 873 + ], 874 + healthcare_service=invalid_healthcare_service_id, 875 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 876 + locations=[self.facility_location.external_id], 877 + ) 878 + response = self.client.put( 879 + self.get_details_url( 880 + facility=self.facility.external_id, 881 + slug=activity_definition.slug, 882 + ), 883 + data, 884 + format="json", 885 + ) 886 + self.assertEqual(response.status_code, 400) 887 + self.assertContains( 888 + response, 889 + "Healthcare Service must be from the same facility", 890 + status_code=400, 891 + ) 892 + 893 + def test_update_activity_definition_with_healthcare_service_in_same_facility(self): 894 + """Test updating an activity definition with a healthcare service in the same facility""" 895 + self.client.force_authenticate(user=self.superuser) 896 + activity_definition = self.create_activity_definition( 897 + facility=self.facility, 898 + category=self.resource_category, 899 + slug="Test-Activity-Definition", 900 + ) 901 + healthcare_service_id = self.generate_healthcare_service( 902 + self.facility 903 + ).external_id 904 + data = self.generate_activity_definition_data( 905 + slug_value="updated-definition", 906 + title="Updated Activity Definition", 907 + status=ActivityDefinitionStatusOptions.retired.value, 908 + specimen_requirements=[ 909 + self.generate_specimen_definition(self.facility).slug 910 + ], 911 + observation_result_requirements=[ 912 + self.generate_observation_definition(self.facility).slug 913 + ], 914 + healthcare_service=healthcare_service_id, 915 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 916 + locations=[self.facility_location.external_id], 917 + ) 918 + response = self.client.put( 919 + self.get_details_url( 920 + facility=self.facility.external_id, 921 + slug=activity_definition.slug, 922 + ), 923 + data, 924 + format="json", 925 + ) 926 + self.assertEqual(response.status_code, 200) 927 + get_response = self.client.get( 928 + self.get_details_url( 929 + facility=self.facility.external_id, 930 + slug=response.data["slug"], 931 + ) 932 + ) 933 + self.assertEqual(get_response.status_code, 200) 934 + self.assertEqual( 935 + get_response.data["healthcare_service"]["id"], str(healthcare_service_id) 936 + ) 937 + 938 + def test_update_activity_definition_with_duplicate_slug(self): 939 + """Test updating an activity definition with a duplicate slug in the same facility""" 940 + self.client.force_authenticate(user=self.superuser) 941 + self.create_activity_definition( 942 + slug="duplicate-slug", 943 + facility=self.facility, 944 + category=self.resource_category, 945 + ) 946 + activity_definition = self.create_activity_definition( 947 + facility=self.facility, 948 + category=self.resource_category, 949 + slug="Test-Activity-Definition", 950 + ) 951 + data = self.generate_activity_definition_data( 952 + slug_value="duplicate-slug", 953 + title="Updated Activity Definition", 954 + status=ActivityDefinitionStatusOptions.retired.value, 955 + specimen_requirements=[ 956 + self.generate_specimen_definition(self.facility).slug 957 + ], 958 + observation_result_requirements=[ 959 + self.generate_observation_definition(self.facility).slug 960 + ], 961 + healthcare_service=self.generate_healthcare_service( 962 + self.facility 963 + ).external_id, 964 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 965 + locations=[self.facility_location.external_id], 966 + ) 967 + response = self.client.put( 968 + self.get_details_url( 969 + facility=self.facility.external_id, 970 + slug=activity_definition.slug, 971 + ), 972 + data, 973 + format="json", 974 + ) 975 + self.assertEqual(response.status_code, 400) 976 + self.assertContains( 977 + response, 978 + "Activity Definition with this slug already exists.", 979 + status_code=400, 980 + ) 981 + 982 + def test_update_activity_definition_with_duplicate_slug_different_facility(self): 983 + """Test updating an activity definition with a duplicate slug in a different facility""" 984 + self.client.force_authenticate(user=self.superuser) 985 + another_facility = self.create_facility( 986 + name="Another Facility", user=self.superuser 987 + ) 988 + self.create_activity_definition( 989 + slug="duplicate-slug", 990 + facility=another_facility, 991 + category=self.resource_category, 992 + ) 993 + activity_definition = self.create_activity_definition( 994 + facility=self.facility, 995 + category=self.resource_category, 996 + slug="Test-Activity-Definition", 997 + ) 998 + data = self.generate_activity_definition_data( 999 + slug_value="duplicate-slug", 1000 + title="Updated Activity Definition", 1001 + status=ActivityDefinitionStatusOptions.retired.value, 1002 + specimen_requirements=[ 1003 + self.generate_specimen_definition(self.facility).slug 1004 + ], 1005 + observation_result_requirements=[ 1006 + self.generate_observation_definition(self.facility).slug 1007 + ], 1008 + healthcare_service=self.generate_healthcare_service( 1009 + self.facility 1010 + ).external_id, 1011 + charge_item_definitions=[self.charge_item_definition(self.facility).slug], 1012 + locations=[self.facility_location.external_id], 1013 + ) 1014 + response = self.client.put( 1015 + self.get_details_url( 1016 + facility=self.facility.external_id, 1017 + slug=activity_definition.slug, 1018 + ), 1019 + data, 1020 + format="json", 1021 + ) 1022 + self.assertEqual(response.status_code, 200) 1023 + get_response = self.client.get( 1024 + self.get_details_url( 1025 + facility=self.facility.external_id, 1026 + slug=response.data["slug"], 1027 + ) 1028 + ) 1029 + self.assertEqual(get_response.status_code, 200) 1030 + self.assertEqual(get_response.data["id"], response.data["id"]) 1031 + 1032 + # Test cases for list activity definitions 1033 + 1034 + def test_list_activity_definitions_as_superuser(self): 1035 + """Test listing activity definitions as a superuser""" 1036 + self.client.force_authenticate(user=self.superuser) 1037 + activity_definition1 = self.create_activity_definition( 1038 + facility=self.facility, 1039 + slug="test-activity-definition", 1040 + category=self.resource_category, 1041 + ) 1042 + activity_definition2 = self.create_activity_definition( 1043 + facility=self.facility, 1044 + slug="test-activity-definition-2", 1045 + category=self.resource_category, 1046 + ) 1047 + response = self.client.get(self.base_url, format="json") 1048 + self.assertEqual(response.status_code, 200) 1049 + self.assertEqual(len(response.data["results"]), 2) 1050 + self.assertEqual( 1051 + response.data["results"][1]["slug"], str(activity_definition1.slug) 1052 + ) 1053 + self.assertEqual( 1054 + response.data["results"][0]["slug"], str(activity_definition2.slug) 1055 + ) 1056 + 1057 + def test_list_activity_definitions_as_user_with_permissions(self): 1058 + """Test listing activity definitions as a user with permissions""" 1059 + self.attach_role_facility_organization_user( 1060 + user=self.user, 1061 + facility_organization=self.facility_organization, 1062 + role=self.role, 1063 + ) 1064 + self.client.force_authenticate(user=self.user) 1065 + activity_definition1 = self.create_activity_definition( 1066 + facility=self.facility, 1067 + slug="test-activity-definition", 1068 + category=self.resource_category, 1069 + ) 1070 + activity_definition2 = self.create_activity_definition( 1071 + facility=self.facility, 1072 + slug="test-activity-definition-2", 1073 + category=self.resource_category, 1074 + ) 1075 + response = self.client.get(self.base_url, format="json") 1076 + self.assertEqual(response.status_code, 200) 1077 + self.assertEqual(len(response.data["results"]), 2) 1078 + self.assertEqual( 1079 + response.data["results"][1]["slug"], str(activity_definition1.slug) 1080 + ) 1081 + self.assertEqual( 1082 + response.data["results"][0]["slug"], str(activity_definition2.slug) 1083 + ) 1084 + 1085 + def test_list_activity_definitions_as_user_without_permissions(self): 1086 + """Test listing activity definitions as a user without permissions""" 1087 + self.client.force_authenticate(user=self.user) 1088 + self.create_activity_definition( 1089 + facility=self.facility, 1090 + slug="test-activity-definition", 1091 + category=self.resource_category, 1092 + ) 1093 + self.create_activity_definition( 1094 + facility=self.facility, 1095 + slug="test-activity-definition-2", 1096 + category=self.resource_category, 1097 + ) 1098 + response = self.client.get(self.base_url, format="json") 1099 + self.assertEqual(response.status_code, 403) 1100 + self.assertContains( 1101 + response, 1102 + "Access Denied to Activity Definition", 1103 + status_code=403, 1104 + ) 1105 + 1106 + def test_list_activity_definition_with_status_filter(self): 1107 + """Test listing activity definitions with status filter""" 1108 + self.client.force_authenticate(user=self.superuser) 1109 + activity_definition1 = self.create_activity_definition( 1110 + facility=self.facility, 1111 + slug="test-activity-definition", 1112 + status=ActivityDefinitionStatusOptions.active.value, 1113 + category=self.resource_category, 1114 + ) 1115 + self.create_activity_definition( 1116 + facility=self.facility, 1117 + slug="test-activity-definition-2", 1118 + status=ActivityDefinitionStatusOptions.retired.value, 1119 + category=self.resource_category, 1120 + ) 1121 + response = self.client.get( 1122 + self.base_url, 1123 + {"status": ActivityDefinitionStatusOptions.active.value}, 1124 + format="json", 1125 + ) 1126 + self.assertEqual(response.status_code, 200) 1127 + self.assertEqual(len(response.data["results"]), 1) 1128 + self.assertEqual( 1129 + response.data["results"][0]["slug"], str(activity_definition1.slug) 1130 + ) 1131 + self.assertEqual( 1132 + response.data["results"][0]["status"], 1133 + ActivityDefinitionStatusOptions.active.value, 1134 + ) 1135 + 1136 + def test_list_activity_definition_with_title_filter(self): 1137 + """Test listing activity definitions with title filter""" 1138 + self.client.force_authenticate(user=self.superuser) 1139 + activity_definition1 = self.create_activity_definition( 1140 + facility=self.facility, 1141 + slug="test-activity-definition", 1142 + title="Test Activity Definition", 1143 + category=self.resource_category, 1144 + ) 1145 + self.create_activity_definition( 1146 + facility=self.facility, 1147 + slug="test-activity-definition-2", 1148 + title="Another Activity Definition", 1149 + category=self.resource_category, 1150 + ) 1151 + response = self.client.get( 1152 + self.base_url, {"title": "Test Activity Definition"}, format="json" 1153 + ) 1154 + self.assertEqual(response.status_code, 200) 1155 + self.assertEqual(len(response.data["results"]), 1) 1156 + self.assertEqual( 1157 + response.data["results"][0]["slug"], str(activity_definition1.slug) 1158 + ) 1159 + self.assertEqual( 1160 + response.data["results"][0]["title"], "Test Activity Definition" 1161 + ) 1162 + 1163 + def test_list_activity_definition_with_category_filter(self): 1164 + """Test filtering activity definitions by dummy category filter.""" 1165 + 1166 + self.client.force_authenticate(user=self.superuser) 1167 + 1168 + activity_definition_1 = self.create_activity_definition( 1169 + facility=self.facility, 1170 + slug="test-activity-definition", 1171 + category=self.resource_category, 1172 + ) 1173 + activity_definition_2 = self.create_activity_definition( 1174 + facility=self.facility, 1175 + slug="test-activity-definition-2", 1176 + category=self.resource_category, 1177 + ) 1178 + response = self.client.get( 1179 + self.base_url, {"category": self.resource_category.slug}, format="json" 1180 + ) 1181 + self.assertEqual(response.status_code, 200) 1182 + self.assertEqual(len(response.data["results"]), 2) 1183 + self.assertEqual( 1184 + response.data["results"][0]["slug"], str(activity_definition_2.slug) 1185 + ) 1186 + self.assertEqual( 1187 + response.data["results"][1]["slug"], str(activity_definition_1.slug) 1188 + ) 1189 + self.assertEqual( 1190 + response.data["results"][0]["category"]["id"], 1191 + str(self.resource_category.external_id), 1192 + ) 1193 + 1194 + def test_list_activity_definition_with_kind_filter(self): 1195 + """Test listing activity definitions with kind filter""" 1196 + self.client.force_authenticate(user=self.superuser) 1197 + self.create_activity_definition( 1198 + facility=self.facility, 1199 + slug="test-activity-definition", 1200 + kind="Test Kind", 1201 + category=self.resource_category, 1202 + ) 1203 + self.create_activity_definition( 1204 + facility=self.facility, 1205 + slug="test-activity-definition-2", 1206 + kind="Another Kind", 1207 + category=self.resource_category, 1208 + ) 1209 + response = self.client.get(self.base_url, {"kind": "Test Kind"}, format="json") 1210 + self.assertEqual(response.status_code, 200) 1211 + self.assertEqual(len(response.data["results"]), 1) 1212 + self.assertEqual( 1213 + response.data["results"][0]["slug"], 1214 + f"f-{self.facility.external_id}-test-activity-definition", 1215 + ) 1216 + self.assertEqual(response.data["results"][0]["kind"], "Test Kind") 1217 + 1218 + def test_list_activity_definition_with_invalid_facility(self): 1219 + self.client.force_authenticate(user=self.superuser) 1220 + response = self.client.get( 1221 + self.get_base_url(facility="invalid-facility-id"), format="json" 1222 + ) 1223 + self.assertEqual(response.status_code, 404) 1224 + self.assertContains( 1225 + response, 1226 + "No Facility matches the given query.", 1227 + status_code=404, 1228 + ) 1229 + 1230 + def test_list_activity_definition_with_include_children_with_is_child_false(self): 1231 + """ 1232 + Test to list activity definitions with dummy filter include_children set to false to view only the activity definitions in the parent category. 1233 + """ 1234 + self.client.force_authenticate(user=self.superuser) 1235 + activity_definition = self.create_activity_definition( 1236 + facility=self.facility, 1237 + slug="parent-activity", 1238 + category=self.resource_category, 1239 + ) 1240 + child_resource_category = self.create_resource_category( 1241 + facility=self.facility, 1242 + slug="child-category", 1243 + parent=self.resource_category, 1244 + is_child=True, 1245 + ) 1246 + self.create_activity_definition( 1247 + facility=self.facility, 1248 + slug="sub-activity-definition", 1249 + category=child_resource_category, 1250 + title="Sub Category Activity Definition", 1251 + ) 1252 + response = self.client.get( 1253 + self.base_url, 1254 + {"include_children": "false", "category": self.resource_category.slug}, 1255 + format="json", 1256 + ) 1257 + self.assertEqual(response.status_code, 200) 1258 + self.assertEqual(len(response.data["results"]), 1) 1259 + self.assertEqual( 1260 + response.data["results"][0]["id"], str(activity_definition.external_id) 1261 + ) 1262 + 1263 + def test_list_activity_definition_with_include_children_with_is_child_true(self): 1264 + """ 1265 + Test to list activity definitions with dummy filter include_children set to true to view only the activity definitions in child categories. 1266 + """ 1267 + self.client.force_authenticate(user=self.superuser) 1268 + self.create_activity_definition( 1269 + facility=self.facility, 1270 + slug="parent-activity", 1271 + category=self.resource_category, 1272 + ) 1273 + child_resource_category = self.create_resource_category( 1274 + facility=self.facility, 1275 + slug="child-category", 1276 + parent=self.resource_category, 1277 + is_child=True, 1278 + ) 1279 + child_activity_definition = self.create_activity_definition( 1280 + facility=self.facility, 1281 + slug="sub-activity-definition", 1282 + category=child_resource_category, 1283 + title="Sub Category Activity Definition", 1284 + ) 1285 + response = self.client.get( 1286 + self.base_url, 1287 + {"include_children": "true", "category": self.resource_category.slug}, 1288 + format="json", 1289 + ) 1290 + self.assertEqual(response.status_code, 200) 1291 + self.assertEqual(len(response.data["results"]), 1) 1292 + self.assertEqual( 1293 + response.data["results"][0]["id"], 1294 + str(child_activity_definition.external_id), 1295 + )