def METHOD_NAME(self):
    """Test various common cases for adding and changing email contacts"""
    u, _ = User.create_with_group(
        UserInfo(
            username="someuser1",
            full_name="Some User",
            email="someuser1@example.com",
        )
    )
    db.session.commit()
    db.session.refresh(u)
    self.assert_contacts(
        u, Channel.EMAIL, [(ContactOrigin.Custom, "someuser1@example.com")]
    )
    # Adding new custom email
    # The primary email must not change after adding a new email
    u.set_emails(
        ["someuser1alt@example.com"],
        ContactOrigin.Custom,
        remove=False,
        notify_message_lists=False,
    )
    db.session.commit()
    db.session.refresh(u)
    self.assert_contacts(
        u,
        Channel.EMAIL,
        [
            (ContactOrigin.Custom, "someuser1@example.com"),
            (ContactOrigin.Custom, "someuser1alt@example.com"),
        ],
    )
    self.assert_primary_contact(
        u, Channel.EMAIL, ContactOrigin.Custom, "someuser1@example.com"
    )
    # Adding email via integration and allowing to update primary address
    # The primary email should be upgraded from custom because new integration was added
    # Previous custom email should become managed
    u.set_emails(
        ["someuser1work@example.com", "someuser1@example.com"],
        ContactOrigin.Sisu,
        can_update_primary=True,
        notify_message_lists=False,
    )
    db.session.commit()
    db.session.refresh(u)
    self.assert_primary_contact(
        u, Channel.EMAIL, ContactOrigin.Sisu, "someuser1work@example.com"
    )
    self.assert_contacts(
        u,
        Channel.EMAIL,
        [
            (ContactOrigin.Custom, "someuser1alt@example.com"),
            (ContactOrigin.Sisu, "someuser1@example.com"),
            (ContactOrigin.Sisu, "someuser1work@example.com"),
        ],
    )
    # Adding existing email via different integration
    # Primary email is the same but the email is now managed by different integration
    u.set_emails(
        ["someuser1work@example.com"],
        ContactOrigin.Haka,
        can_update_primary=True,
        notify_message_lists=False,
    )
    db.session.commit()
    db.session.refresh(u)
    self.assert_primary_contact(
        u, Channel.EMAIL, ContactOrigin.Haka, "someuser1work@example.com"
    )
    self.assert_contacts(
        u,
        Channel.EMAIL,
        [
            (ContactOrigin.Custom, "someuser1alt@example.com"),
            (ContactOrigin.Sisu, "someuser1@example.com"),
            (ContactOrigin.Haka, "someuser1work@example.com"),
        ],
    )
    # Changing primary email to custom directly should work
    u.update_email("someuser1alt@example.com", notify_message_lists=False)
    db.session.commit()
    db.session.refresh(u)
    self.assert_primary_contact(
        u, Channel.EMAIL, ContactOrigin.Custom, "someuser1alt@example.com"
    )
    # Upgrading primary email via integration must not work because primary email was changed to custom
    u.set_emails(
        ["someuser1@example.com"],
        ContactOrigin.Sisu,
        can_update_primary=True,
        notify_message_lists=False,
    )
    db.session.commit()
    db.session.refresh(u)
    self.assert_primary_contact(
        u, Channel.EMAIL, ContactOrigin.Custom, "someuser1alt@example.com"
    )
    # Changing back to managed email should resume automatic email management
    # One email changes its integration back to Sisu
    u.update_email("someuser1work@example.com", notify_message_lists=False)
    db.session.commit()
    db.session.refresh(u)
    u.set_emails(
        ["someuser1new@example.com", "someuser1work@example.com"],
        ContactOrigin.Sisu,
        can_update_primary=True,
        notify_message_lists=False,
    )
    db.session.commit()
    db.session.refresh(u)
    # The primary email does not change because the user chose to use this managed email
    self.assert_primary_contact(
        u, Channel.EMAIL, ContactOrigin.Sisu, "someuser1work@example.com"
    )
    self.assert_contacts(
        u,
        Channel.EMAIL,
        [
            (ContactOrigin.Custom, "someuser1alt@example.com"),
            (ContactOrigin.Sisu, "someuser1new@example.com"),
            (ContactOrigin.Sisu, "someuser1work@example.com"),
        ],
    )
    # Changing email directly still works like before
    # In that case email becomes verified and primary
    u.update_email(
        "someuser1differentemail@example.com", notify_message_lists=False
    )
    db.session.commit()
    db.session.refresh(u)
    self.assert_primary_contact(
        u,
        Channel.EMAIL,
        ContactOrigin.Custom,
        "someuser1differentemail@example.com",
    )
    self.assert_contacts(
        u,
        Channel.EMAIL,
        [
            (ContactOrigin.Custom, "someuser1differentemail@example.com"),
            (ContactOrigin.Custom, "someuser1alt@example.com"),
            (ContactOrigin.Sisu, "someuser1new@example.com"),
            (ContactOrigin.Sisu, "someuser1work@example.com"),
        ],
    )