def _failure_on_edit(self, class_to_edit, failure):
        if failure == "couch":
            path_to_patch = "corehq.apps.locations.models.Document.save"
            exception = ResourceConflict
        else:
            path_to_patch = "corehq.apps.locations.models.MPTTModel.save"
            exception = DatabaseError

        if class_to_edit == "couch":
            loc_constructor = couch_loc
            loc_getter = Location.get
        else:
            loc_constructor = sql_loc
            loc_getter = lambda loc_id: SQLLocation.objects.get(location_id=loc_id)

        loc_constructor("Massachusetts", self.state)
        suffolk_id = loc_constructor("Suffolk", self.county).location_id
        self.assertNumLocations(2)

        with mock.patch(path_to_patch, side_effect=exception):
            suffolk = loc_getter(suffolk_id)
            suffolk.name = "New Suffolk"
            with self.assertRaises(exception):
                suffolk.save()

        # Suffolk should still be there, and its name should be unchanged
        self.assertNumLocations(2)
        couch_suffolk = Location.get(suffolk_id)
        sql_suffolk = SQLLocation.objects.get(location_id=suffolk_id)
        self.assertLocationsEqual(couch_suffolk, sql_suffolk)
        self.assertEqual(sql_suffolk.name, "Suffolk")
Save a location using `class_to_edit` model and trigger a failure on
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/locations/tests/test_location_sync.py/TestLocationSync._failure_on_edit