oncall-engine/engine/apps/schedules/tests
Vadim Stepanov 3c00345f54
Fix Grafana teams sync (#1652)
# What this PR does
Sometimes plugin sync fails with the following exception:
```
Cannot delete or update a parent row: a foreign key constraint fails (`schedules_oncallschedule`, CONSTRAINT `alerts_oncallschedul_team_id_4e633f4b_fk_user_mana` FOREIGN KEY (`team_id`) REFERENCES `user_management_team` (`id`))'
```

How to reproduce:
1. Create a new Grafana team
2. Create two schedules with different types (e.g. ICal and Web) and
assign both schedules to the new team
3. Delete the team in Grafana
4. Trigger plugin sync, the sync will fail with the exception above

This happens because the `OnCallSchedule` Django model is a polymorphic
model and there's a [known
bug](https://github.com/django-polymorphic/django-polymorphic/issues/229)
in `django-polymorphic` with deleting related objects when using
`SET_NULL` and `CASCADE`. This PR adds non-polymorphic versions of
`SET_NULL` and `CASCADE` to use in schedule FKs as per this
[comment](https://github.com/django-polymorphic/django-polymorphic/issues/229#issuecomment-398434412).

This also applies to two other schedule FKs: `organization` and
`user_group`, which are not working properly as well.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-03-28 18:26:24 +00:00
..
calendars Make emails case-insensitive for ICal schedules (#1297) 2023-02-06 12:11:13 +00:00
__init__.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
conftest.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
factories.py Initial web schedule model and serializers. Add override shift type. 2022-07-05 12:41:55 -03:00
test_amixr_users_in_ical.py World, meet OnCall! 2022-06-03 08:09:47 -06:00
test_custom_on_call_shift.py Update override delete-related updates (#1599) 2023-03-23 15:45:27 +00:00
test_ical_proxy.py Add multiple ical all-day event for testing 2022-11-03 14:36:42 -03:00
test_ical_utils.py Do not include event repetitions terminated before start (until rrule) 2022-11-30 08:56:19 -03:00
test_on_call_schedule.py Fix Grafana teams sync (#1652) 2023-03-28 18:26:24 +00:00
test_quality_score.py Improve schedule quality feature (#1602) 2023-03-27 11:03:16 +00:00
test_tasks_refresh_ical_files.py Matiasb/fix task refresh ical when empty value (#1401) 2023-02-24 21:16:09 +00:00