'Test that the correct EnterpriseCustomer, if any, is returned.'

@override_settings(ENABLE_ENTERPRISE_INTEGRATION=True)
@mock.patch('openedx.features.enterprise_support.api.EnterpriseCustomer')
@mock.patch('openedx.features.enterprise_support.api.get_partial_pipeline')
def test_enterprise_customer_for_request(self, pipeline_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'
        elif (uuid == 'not-a-uuid'):
            raise ValueError
        else:
            raise Exception
    ec_class_mock.DoesNotExist = Exception
    ec_class_mock.objects.get.side_effect = get_ec_mock
    pipeline_mock.return_value = None
    request = mock.MagicMock()
    request.GET.get.return_value = 'real-uuid'
    self.assertEqual(enterprise_customer_for_request(request), 'this-is-actually-an-enterprise-customer')
    request.GET.get.return_value = 'not-a-uuid'
    self.assertEqual(enterprise_customer_for_request(request), None)
    request.GET.get.return_value = 'fake-uuid'
    self.assertEqual(enterprise_customer_for_request(request), None)
    request.GET.get.return_value = None
    self.assertEqual(enterprise_customer_for_request(request, tpa_hint='real-provider-id'), 'this-is-actually-an-enterprise-customer')
    self.assertEqual(enterprise_customer_for_request(request, tpa_hint='fake-provider-id'), None)
    self.assertEqual(enterprise_customer_for_request(request, tpa_hint=None), None)
