Coverage for cc_modules/tests/cc_taskschedulereports_tests.py: 6%

1"""

2 camcops_server/cc_modules/tests/cc_taskschedulereports_tests.py

3

4===============================================================================

5

6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

8

9 This file is part of CamCOPS.

10

11 CamCOPS is free software: you can redistribute it and/or modify

12 it under the terms of the GNU General Public License as published by

13 the Free Software Foundation, either version 3 of the License, or

14 (at your option) any later version.

15

16 CamCOPS is distributed in the hope that it will be useful,

17 but WITHOUT ANY WARRANTY; without even the implied warranty of

18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

19 GNU General Public License for more details.

20

21 You should have received a copy of the GNU General Public License

22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.

23

24===============================================================================

25

26**Test server reports on CamCOPS scheduled tasks.**

27

28"""

29

30 from pendulum import datetime

31

32 from camcops_server.cc_modules.cc_testfactories import (

33 EmailFactory,

34 GroupFactory,

35 PatientTaskScheduleFactory,

36 PatientTaskScheduleEmailFactory,

37 ServerCreatedPatientFactory,

38 TaskScheduleFactory,

39 TaskScheduleItemFactory,

40 UserFactory,

41 UserGroupMembershipFactory,

42)

43 from camcops_server.cc_modules.cc_unittest import BasicDatabaseTestCase

44

45 from camcops_server.cc_modules.cc_taskschedulereports import (

46 TaskAssignmentReport,

47)

48

49

50 class TaskAssignmentReportTests(BasicDatabaseTestCase):

51 YEAR_COLUMN = 0

52 MONTH_COLUMN = 1

53 GROUP_COLUMN = 2

54 SCHEDULE_COLUMN = 3

55 PATIENTS_COLUMN = 4

56 TASKS_COLUMN = 5

57 EMAILS_COLUMN = 6

58

59 def setUp(self) -> None:

60 super().setUp()

61

62 self.group_a = GroupFactory(name="group_a")

63 self.group_b = GroupFactory(name="group_b")

64

65 self.ts1 = TaskScheduleFactory(name="ts1", group=self.group_a)

66 self.ts1_task_names = ["bmi", "phq9"]

67 for task_name in self.ts1_task_names:

68 TaskScheduleItemFactory(

69 task_schedule=self.ts1, task_table_name=task_name

70 )

71

72 self.ts2 = TaskScheduleFactory(name="ts2", group=self.group_a)

73 self.ts2_task_names = [

74 "cisr",

75 "wsas",

76 "audit",

77 "pcl5",

78 "phq9",

79 "gad7",

80 ]

81 for task_name in self.ts2_task_names:

82 TaskScheduleItemFactory(

83 task_schedule=self.ts2, task_table_name=task_name

84 )

85

86 self.ts3 = TaskScheduleFactory(name="ts3", group=self.group_b)

87 self.ts3_task_names = [

88 "phq9",

89 "gad7",

90 "wsas",

91 "eq5d5l",

92 ]

93 for task_name in self.ts3_task_names:

94 TaskScheduleItemFactory(

95 task_schedule=self.ts3, task_table_name=task_name

96 )

97

98 self.august = datetime(2022, 8, 1, 12)

99 self.september = datetime(2022, 9, 1, 12)

100 self.october = datetime(2022, 10, 1, 12)

101 self.november = datetime(2022, 11, 1, 12)

102

103 self.report = TaskAssignmentReport()

104

105 def test_column_names(self) -> None:

106 result = self.report.get_rows_colnames(self.req)

107

108 self.assertEqual(

109 result.column_names,

110 [

111 "year",

112 "month",

113 "group_name",

114 "schedule_name",

115 "patients_created",

116 "tasks_assigned",

117 "emails_sent",

118 ],

119 )

120

121 def test_task_patient_counts_for_no_registered_patients(self) -> None:

122 sep_patients = []

123 oct_patients = []

124 nov_patients = []

125 ts1_patients = []

126 ts2_patients = []

127 ts3_patients = []

128 for i in range(0, 3):

129 patient = ServerCreatedPatientFactory(

130 _when_added_exact=self.november

131 )

132 nov_patients.append(patient)

133 ts1_patients.append(patient)

134 PatientTaskScheduleFactory(task_schedule=self.ts1, patient=patient)

135

136 for i in range(0, 4):

137 patient = ServerCreatedPatientFactory(

138 _when_added_exact=self.october

139 )

140 oct_patients.append(patient)

141 ts2_patients.append(patient)

142 PatientTaskScheduleFactory(task_schedule=self.ts2, patient=patient)

143

144 for i in range(0, 5):

145 patient = ServerCreatedPatientFactory(

146 _when_added_exact=self.september

147 )

148 sep_patients.append(patient)

149 ts3_patients.append(patient)

150 PatientTaskScheduleFactory(task_schedule=self.ts3, patient=patient)

151

152 result = self.report.get_rows_colnames(self.req)

153

154 # patients created, no tasks completed

155 row = 0

156 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

157 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 11)

158 self.assertEqual(

159 result.rows[row][self.GROUP_COLUMN], self.group_a.name

160 )

161 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts1.name)

162 self.assertEqual(

163 result.rows[row][self.PATIENTS_COLUMN], len(nov_patients)

164 )

165 self.assertEqual(result.rows[row][self.TASKS_COLUMN], 0)

166 row += 1

167

168 # patients created, no tasks completed

169 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

170 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 10)

171 self.assertEqual(

172 result.rows[row][self.GROUP_COLUMN], self.group_a.name

173 )

174 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts2.name)

175 self.assertEqual(

176 result.rows[row][self.PATIENTS_COLUMN], len(oct_patients)

177 )

178 self.assertEqual(result.rows[row][self.TASKS_COLUMN], 0)

179 row += 1

180

181 # patients created, no tasks completed

182 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

183 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 9)

184 self.assertEqual(

185 result.rows[row][self.GROUP_COLUMN], self.group_b.name

186 )

187 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts3.name)

188 self.assertEqual(

189 result.rows[row][self.PATIENTS_COLUMN], len(sep_patients)

190 )

191 self.assertEqual(result.rows[row][self.TASKS_COLUMN], 0)

192 row += 1

193

194 # tasks assigned to patients not yet registered

195 # it should not be possible to have patients without a

196 # creation date (_when_added_exact attribute)

197 self.assertIsNone(result.rows[row][self.YEAR_COLUMN])

198 self.assertIsNone(result.rows[row][self.MONTH_COLUMN])

199 self.assertEqual(

200 result.rows[row][self.GROUP_COLUMN], self.group_a.name

201 )

202 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts1.name)

203 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0, 0)

204 self.assertEqual(

205 result.rows[row][self.TASKS_COLUMN],

206 len(self.ts1_task_names) * len(ts1_patients),

207 )

208 row += 1

209

210 # tasks assigned to patients not yet registered

211 self.assertIsNone(result.rows[row][self.YEAR_COLUMN])

212 self.assertIsNone(result.rows[row][self.MONTH_COLUMN])

213 self.assertEqual(

214 result.rows[row][self.GROUP_COLUMN], self.group_a.name

215 )

216 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts2.name)

217 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0, 0)

218 self.assertEqual(

219 result.rows[row][self.TASKS_COLUMN],

220 len(self.ts2_task_names) * len(ts2_patients),

221 )

222 row += 1

223

224 # tasks assigned to patients not yet registered

225 self.assertIsNone(result.rows[row][self.YEAR_COLUMN])

226 self.assertIsNone(result.rows[row][self.MONTH_COLUMN])

227 self.assertEqual(

228 result.rows[row][self.GROUP_COLUMN], self.group_b.name

229 )

230 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts3.name)

231 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0, 0)

232 self.assertEqual(

233 result.rows[row][self.TASKS_COLUMN],

234 len(self.ts3_task_names) * len(ts3_patients),

235 )

236 row += 1

237

238 # Check there's nothing else

239 self.assertEqual(len(result.rows), row)

240

241 def test_task_patient_counts_for_some_registered_patients(self) -> None:

242 ts1_unregistered_patients = []

243 ts2_unregistered_patients = []

244 ts3_unregistered_patients = []

245 ts1_aug_created_patients = []

246 ts2_aug_created_patients = []

247 ts3_aug_created_patients = []

248 ts1_sep_registered_patients = []

249 ts2_sep_registered_patients = []

250 ts3_sep_registered_patients = []

251 ts1_oct_registered_patients = []

252 ts2_oct_registered_patients = []

253 ts3_oct_registered_patients = []

254

255 for i in range(0, 1):

256 patient = ServerCreatedPatientFactory(

257 _when_added_exact=self.august

258 )

259 ts1_aug_created_patients.append(patient)

260 PatientTaskScheduleFactory(task_schedule=self.ts1, patient=patient)

261 ts1_unregistered_patients.append(patient)

262

263 for i in range(0, 2):

264 patient = ServerCreatedPatientFactory(

265 _when_added_exact=self.august

266 )

267 ts2_aug_created_patients.append(patient)

268 PatientTaskScheduleFactory(task_schedule=self.ts2, patient=patient)

269 ts2_unregistered_patients.append(patient)

270

271 for i in range(0, 3):

272 patient = ServerCreatedPatientFactory(

273 _when_added_exact=self.august

274 )

275 ts3_aug_created_patients.append(patient)

276 PatientTaskScheduleFactory(task_schedule=self.ts3, patient=patient)

277 ts3_unregistered_patients.append(patient)

278

279 for i in range(0, 4):

280 patient = ServerCreatedPatientFactory(

281 _when_added_exact=self.august

282 )

283 ts1_aug_created_patients.append(patient)

284 PatientTaskScheduleFactory(

285 task_schedule=self.ts1,

286 start_datetime=self.september,

287 patient=patient,

288 )

289 ts1_sep_registered_patients.append(patient)

290

291 for i in range(0, 5):

292 patient = ServerCreatedPatientFactory(

293 _when_added_exact=self.august

294 )

295 ts2_aug_created_patients.append(patient)

296 PatientTaskScheduleFactory(

297 task_schedule=self.ts2,

298 start_datetime=self.september,

299 patient=patient,

300 )

301 ts2_sep_registered_patients.append(patient)

302

303 for i in range(0, 6):

304 patient = ServerCreatedPatientFactory(

305 _when_added_exact=self.august

306 )

307 ts3_aug_created_patients.append(patient)

308 PatientTaskScheduleFactory(

309 task_schedule=self.ts3,

310 start_datetime=self.september,

311 patient=patient,

312 )

313 ts3_sep_registered_patients.append(patient)

314

315 for i in range(0, 7):

316 patient = ServerCreatedPatientFactory(

317 _when_added_exact=self.august

318 )

319 ts1_aug_created_patients.append(patient)

320 PatientTaskScheduleFactory(

321 task_schedule=self.ts1,

322 start_datetime=self.october,

323 patient=patient,

324 )

325 ts1_oct_registered_patients.append(patient)

326

327 for i in range(0, 8):

328 patient = ServerCreatedPatientFactory(

329 _when_added_exact=self.august

330 )

331 ts2_aug_created_patients.append(patient)

332 PatientTaskScheduleFactory(

333 task_schedule=self.ts2,

334 start_datetime=self.october,

335 patient=patient,

336 )

337 ts2_oct_registered_patients.append(patient)

338

339 for i in range(0, 9):

340 patient = ServerCreatedPatientFactory(

341 _when_added_exact=self.august

342 )

343 ts3_aug_created_patients.append(patient)

344 PatientTaskScheduleFactory(

345 task_schedule=self.ts3,

346 start_datetime=self.october,

347 patient=patient,

348 )

349 ts3_oct_registered_patients.append(patient)

350

351 result = self.report.get_rows_colnames(self.req)

352

353 row = 0

354 # tasks assigned to ts1 patients

355 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

356 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 10)

357 self.assertEqual(

358 result.rows[row][self.GROUP_COLUMN], self.group_a.name

359 )

360 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts1.name)

361 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

362 self.assertEqual(

363 result.rows[row][self.TASKS_COLUMN],

364 len(self.ts1_task_names) * len(ts1_oct_registered_patients),

365 )

366 row += 1

367

368 # tasks assigned to ts2 patients

369 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

370 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 10)

371 self.assertEqual(

372 result.rows[row][self.GROUP_COLUMN], self.group_a.name

373 )

374 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts2.name)

375 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

376 self.assertEqual(

377 result.rows[row][self.TASKS_COLUMN],

378 len(self.ts2_task_names) * len(ts2_oct_registered_patients),

379 )

380 row += 1

381

382 # tasks assigned to ts3 patients

383 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

384 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 10)

385 self.assertEqual(

386 result.rows[row][self.GROUP_COLUMN], self.group_b.name

387 )

388 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts3.name)

389 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

390 self.assertEqual(

391 result.rows[row][self.TASKS_COLUMN],

392 len(self.ts3_task_names) * len(ts3_oct_registered_patients),

393 )

394 row += 1

395

396 # tasks assigned to ts1 patients

397 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

398 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 9)

399 self.assertEqual(

400 result.rows[row][self.GROUP_COLUMN], self.group_a.name

401 )

402 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts1.name)

403 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

404 self.assertEqual(

405 result.rows[row][self.TASKS_COLUMN],

406 len(self.ts1_task_names) * len(ts1_sep_registered_patients),

407 )

408 row += 1

409

410 # tasks assigned to ts2 patients

411 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

412 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 9)

413 self.assertEqual(

414 result.rows[row][self.GROUP_COLUMN], self.group_a.name

415 )

416 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts2.name)

417 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

418 self.assertEqual(

419 result.rows[row][self.TASKS_COLUMN],

420 len(self.ts2_task_names) * len(ts2_sep_registered_patients),

421 )

422 row += 1

423

424 # tasks assigned to ts3 patients

425 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

426 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 9)

427 self.assertEqual(

428 result.rows[row][self.GROUP_COLUMN], self.group_b.name

429 )

430 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts3.name)

431 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

432 self.assertEqual(

433 result.rows[row][self.TASKS_COLUMN],

434 len(self.ts3_task_names) * len(ts3_sep_registered_patients),

435 )

436 row += 1

437

438 # ts1 patients created, no tasks

439 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

440 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 8)

441 self.assertEqual(

442 result.rows[row][self.GROUP_COLUMN], self.group_a.name

443 )

444 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts1.name)

445 self.assertEqual(

446 result.rows[row][self.PATIENTS_COLUMN],

447 len(ts1_aug_created_patients),

448 )

449 self.assertEqual(result.rows[row][self.TASKS_COLUMN], 0)

450 row += 1

451

452 # ts2 patients created, no tasks

453 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

454 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 8)

455 self.assertEqual(

456 result.rows[row][self.GROUP_COLUMN], self.group_a.name

457 )

458 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts2.name)

459 self.assertEqual(

460 result.rows[row][self.PATIENTS_COLUMN],

461 len(ts2_aug_created_patients),

462 )

463 self.assertEqual(result.rows[row][self.TASKS_COLUMN], 0)

464 row += 1

465

466 # tasks assigned to ts3 patients

467 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

468 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 8)

469 self.assertEqual(

470 result.rows[row][self.GROUP_COLUMN], self.group_b.name

471 )

472 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts3.name)

473 self.assertEqual(

474 result.rows[row][self.PATIENTS_COLUMN],

475 len(ts3_aug_created_patients),

476 )

477 self.assertEqual(result.rows[row][self.TASKS_COLUMN], 0)

478 row += 1

479

480 # tasks assigned to ts1 patients not yet registered

481 self.assertIsNone(result.rows[row][self.YEAR_COLUMN])

482 self.assertIsNone(result.rows[row][self.MONTH_COLUMN])

483 self.assertEqual(

484 result.rows[row][self.GROUP_COLUMN], self.group_a.name

485 )

486 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts1.name)

487 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

488 self.assertEqual(

489 result.rows[row][self.TASKS_COLUMN],

490 len(self.ts1_task_names) * len(ts1_unregistered_patients),

491 )

492 row += 1

493

494 # tasks assigned to ts2 patients not yet registered

495 self.assertIsNone(result.rows[row][self.YEAR_COLUMN])

496 self.assertIsNone(result.rows[row][self.MONTH_COLUMN])

497 self.assertEqual(

498 result.rows[row][self.GROUP_COLUMN], self.group_a.name

499 )

500 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts2.name)

501 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

502 self.assertEqual(

503 result.rows[row][self.TASKS_COLUMN],

504 len(self.ts2_task_names) * len(ts2_unregistered_patients),

505 )

506 row += 1

507

508 # tasks assigned to ts3 patients not yet registered

509 self.assertIsNone(result.rows[row][self.YEAR_COLUMN])

510 self.assertIsNone(result.rows[row][self.MONTH_COLUMN])

511 self.assertEqual(

512 result.rows[row][self.GROUP_COLUMN], self.group_b.name

513 )

514 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts3.name)

515 self.assertEqual(result.rows[row][self.PATIENTS_COLUMN], 0)

516 self.assertEqual(

517 result.rows[row][self.TASKS_COLUMN],

518 len(self.ts3_task_names) * len(ts3_unregistered_patients),

519 )

520 row += 1

521

522 self.assertEqual(len(result.rows), row)

523

524 def test_email_counts(self) -> None:

525 ts1_emails = []

526 ts2_emails = []

527 ts3_emails = []

528

529 for i in range(0, 1):

530 patient = ServerCreatedPatientFactory(

531 _when_added_exact=self.september

532 )

533 pts = PatientTaskScheduleFactory(

534 task_schedule=self.ts1,

535 patient=patient,

536 start_datetime=self.september,

537 )

538 email = EmailFactory(sent_at_utc=self.september, sent=True)

539 ts1_emails.append(

540 PatientTaskScheduleEmailFactory(

541 patient_task_schedule=pts, email=email

542 )

543 )

544 email = EmailFactory(sent_at_utc=self.september, sent=True)

545 ts1_emails.append(

546 PatientTaskScheduleEmailFactory(

547 patient_task_schedule=pts, email=email

548 )

549 )

550

551 for i in range(0, 2):

552 patient = ServerCreatedPatientFactory(

553 _when_added_exact=self.september

554 )

555 pts = PatientTaskScheduleFactory(

556 task_schedule=self.ts2,

557 patient=patient,

558 start_datetime=self.september,

559 )

560 email = EmailFactory(sent_at_utc=self.september, sent=True)

561 ts2_emails.append(

562 PatientTaskScheduleEmailFactory(

563 patient_task_schedule=pts, email=email

564 )

565 )

566

567 for i in range(0, 3):

568 patient = ServerCreatedPatientFactory(

569 _when_added_exact=self.september

570 )

571 pts = PatientTaskScheduleFactory(

572 task_schedule=self.ts3,

573 patient=patient,

574 start_datetime=self.september,

575 )

576 email = EmailFactory(sent_at_utc=self.september, sent=True)

577 ts3_emails.append(

578 PatientTaskScheduleEmailFactory(

579 patient_task_schedule=pts, email=email

580 )

581 )

582 # These should not be included (sent=False)

583 email = EmailFactory(sent_at_utc=self.september, sent=False)

584 PatientTaskScheduleEmailFactory(

585 patient_task_schedule=pts, email=email

586 )

587

588 result = self.report.get_rows_colnames(self.req)

589

590 row = 0

591 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

592 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 9)

593 self.assertEqual(

594 result.rows[row][self.GROUP_COLUMN], self.group_a.name

595 )

596 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts1.name)

597 self.assertEqual(result.rows[row][self.EMAILS_COLUMN], len(ts1_emails))

598 row += 1

599

600 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

601 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 9)

602 self.assertEqual(

603 result.rows[row][self.GROUP_COLUMN], self.group_a.name

604 )

605 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts2.name)

606 self.assertEqual(result.rows[row][self.EMAILS_COLUMN], len(ts2_emails))

607 row += 1

608

609 self.assertEqual(result.rows[row][self.YEAR_COLUMN], 2022)

610 self.assertEqual(result.rows[row][self.MONTH_COLUMN], 9)

611 self.assertEqual(

612 result.rows[row][self.GROUP_COLUMN], self.group_b.name

613 )

614 self.assertEqual(result.rows[row][self.SCHEDULE_COLUMN], self.ts3.name)

615 self.assertEqual(result.rows[row][self.EMAILS_COLUMN], len(ts3_emails))

616 row += 1

617

618 self.assertEqual(len(result.rows), row)

619

620 def test_groups_restricted_when_not_superuser(self) -> None:

621 user = UserFactory()

622 UserGroupMembershipFactory(

623 group_id=self.ts1.group.id, user_id=user.id, may_run_reports=True

624 )

625

626 self.req._debugging_user = user

627

628 # Should include these

629 for i in range(0, 3):

630 patient = ServerCreatedPatientFactory(

631 _when_added_exact=self.september, _group=self.ts1.group

632 )

633 PatientTaskScheduleFactory(

634 task_schedule=self.ts1,

635 patient=patient,

636 start_datetime=self.september,

637 )

638

639 # Should ignore these

640 for i in range(0, 2):

641 patient = ServerCreatedPatientFactory(

642 _when_added_exact=self.september, _group=self.ts3.group

643 )

644 PatientTaskScheduleFactory(

645 task_schedule=self.ts3,

646 patient=patient,

647 start_datetime=self.september,

648 )

649

650 result = self.report.get_rows_colnames(self.req)

651 self.assertEqual(len(result.rows), 1)