'Test that the correct EnterpriseCustomer, if any, is returned when
the user is in the middle of a third-party auth pipeline.'

@override_settings(ENABLE_ENTERPRISE_INTEGRATION=True)
@mock.patch('openedx.features.enterprise_support.api.EnterpriseCustomer')
@mock.patch('openedx.features.enterprise_support.api.Registry')
@mock.patch('openedx.features.enterprise_support.api.get_partial_pipeline')
def test_get_enterprise_customer_for_request_from_pipeline(self, pipeline_mock, registry_mock, ec_class_mock):

    def get_ec_mock(**kwargs):
        by_provider_id_kw = 'enterprise_customer_identity_provider__provider_id'
        provider_id = kwargs.get(by_provider_id_kw, '')
        uuid = kwargs.get('uuid', '')
        if ((uuid == 'real-uuid') or (provider_id == 'real-provider-id')):
            return 'this-is-actually-an-enterprise-customer'
    ec_class_mock.DoesNotExist = Exception
    ec_class_mock.objects.get.side_effect = get_ec_mock
    pipeline_mock.return_value = {'fake_pipeline': 'sofake'}
    provider_mock = registry_mock.get_from_pipeline.return_value
    provider_mock.provider_id = 'real-provider-id'
    request = mock.MagicMock()
    self.assertEqual(enterprise_customer_for_request(request), 'this-is-actually-an-enterprise-customer')
