def test_delete_association_when_it_is_present(self):
        firebase_admin.auth.create_user(uid='aid')
        firebase_auth_services.associate_auth_id_to_user_id(
            auth_domain.AuthIdUserIdPair('aid', 'uid'))
        self.assertFalse(firebase_auth_services.are_auth_associations_deleted(
            'uid'))

        firebase_auth_services.delete_auth_associations('uid')

        self.assertTrue(firebase_auth_services.are_auth_associations_deleted(
            'uid'))
    def test_delete_user_when_firebase_succeeds(self):
        with self.capture_logging(min_level=logging.ERROR) as logs:
            firebase_auth_services.delete_auth_associations(self.USER_ID)

        self.assertTrue(
            firebase_auth_services.are_auth_associations_deleted(self.USER_ID))
        self.assertEqual(logs, [])
    def test_present_association_is_not_considered_to_be_deleted(self):
        firebase_admin.auth.create_user(uid='aid')
        firebase_auth_services.associate_auth_id_to_user_id(
            auth_domain.AuthIdUserIdPair('aid', 'uid'))

        self.assertFalse(firebase_auth_services.are_auth_associations_deleted(
            'uid'))
    def test_delete_user_when_firebase_raises_an_error(self):
        delete_swap = self.swap_to_always_raise(
            firebase_admin.auth, 'delete_user',
            error=firebase_exceptions.InternalError('could not connect'))

        with delete_swap, self.capture_logging(min_level=logging.ERROR) as logs:
            firebase_auth_services.delete_auth_associations(self.USER_ID)

        self.assertFalse(
            firebase_auth_services.are_auth_associations_deleted(self.USER_ID))
        self.assert_only_item_is_exception(logs, 'could not connect')
    def test_is_associated_auth_id_deleted_without_init_returns_false(self):
        init_swap = self.swap_to_always_raise(
            firebase_admin, 'initialize_app',
            error=firebase_exceptions.UnknownError('could not init'))

        with init_swap, self.capture_logging(min_level=logging.ERROR) as logs:
            self.assertFalse(
                firebase_auth_services.are_auth_associations_deleted(
                    self.USER_ID))

        self.assert_only_item_is_exception(logs, 'could not init')
 def test_missing_association_is_considered_to_be_deleted(self):
     self.assertTrue(firebase_auth_services.are_auth_associations_deleted(
         'does_not_exist'))