Unverified Commit 14cb287e by Asad Iqbal Committed by GitHub

Merge pull request #16665 from edx/asadiqbal08/ENT-751

[ENT-751] Update the SailThru var with Enterprise learner information
parents 1c0124aa 390c5368
......@@ -2343,7 +2343,7 @@ INSTALLED_APPS = [
'openedx.features.course_bookmarks',
'openedx.features.course_experience',
'openedx.features.course_search',
'openedx.features.enterprise_support',
'openedx.features.enterprise_support.apps.EnterpriseSupportConfig',
'openedx.features.learner_profile',
'experiments',
......
"""
Configuration for enterprise_support
"""
from django.apps import AppConfig
class EnterpriseSupportConfig(AppConfig):
"""
Configuration class for enterprise_support
"""
name = 'openedx.features.enterprise_support'
def ready(self):
# Import signals to activate signal handler for enterprise.
from . import signals # pylint: disable=unused-import, unused-variable
"""
This module contains signals related to enterprise.
"""
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from enterprise.models import EnterpriseCustomerUser
from email_marketing.tasks import update_user # pylint: disable=import-error
@receiver(post_save, sender=EnterpriseCustomerUser)
def update_email_marketing_user_with_enterprise_flag(sender, instance, **kwargs): # pylint: disable=unused-argument, invalid-name
"""
Enable the is_enterprise_learner flag in SailThru vars.
"""
user = User.objects.get(id=instance.user_id)
# perform update asynchronously
update_user.delay(sailthru_vars={'is_enterprise_learner': True}, email=user.email)
"""
Factoryboy factories.
"""
from __future__ import absolute_import, unicode_literals
from uuid import UUID
import factory
from faker import Factory as FakerFactory
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
from enterprise.models import (
EnterpriseCustomer,
EnterpriseCustomerUser,
)
FAKER = FakerFactory.create()
class EnterpriseCustomerFactory(factory.django.DjangoModelFactory):
"""
EnterpriseCustomer factory.
Creates an instance of EnterpriseCustomer with minimal boilerplate - uses this class' attributes as default
parameters for EnterpriseCustomer constructor.
"""
class Meta(object):
"""
Meta for EnterpriseCustomerFactory.
"""
model = EnterpriseCustomer
uuid = factory.LazyAttribute(lambda x: UUID(FAKER.uuid4())) # pylint: disable=no-member
name = factory.LazyAttribute(lambda x: FAKER.company()) # pylint: disable=no-member
active = True
site = factory.SubFactory(SiteFactory)
catalog = factory.LazyAttribute(lambda x: FAKER.random_int(min=0, max=1000000)) # pylint: disable=no-member
enable_data_sharing_consent = True
enforce_data_sharing_consent = EnterpriseCustomer.AT_ENROLLMENT
class EnterpriseCustomerUserFactory(factory.django.DjangoModelFactory):
"""
EnterpriseCustomer factory.
Creates an instance of EnterpriseCustomerUser with minimal boilerplate - uses this class' attributes as default
parameters for EnterpriseCustomerUser constructor.
"""
class Meta(object):
"""
Meta for EnterpriseCustomerFactory.
"""
model = EnterpriseCustomerUser
enterprise_customer = factory.SubFactory(EnterpriseCustomerFactory)
user_id = factory.LazyAttribute(lambda x: FAKER.pyint()) # pylint: disable=no-member
"""Tests of email marketing signal handlers."""
import logging
import ddt
from django.test import TestCase
from mock import patch
from student.tests.factories import UserFactory
from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerFactory, EnterpriseCustomerUserFactory
log = logging.getLogger(__name__)
LOGGER_NAME = "enterprise_support.signals"
TEST_EMAIL = "test@edx.org"
@ddt.ddt
class EnterpriseSupportSignals(TestCase):
"""
Tests for the enterprise support signals.
"""
def setUp(self):
self.user = UserFactory.create(username='test', email=TEST_EMAIL)
super(EnterpriseSupportSignals, self).setUp()
@patch('openedx.features.enterprise_support.signals.update_user.delay')
def test_register_user(self, mock_update_user):
"""
make sure marketing enterprise user call invokes update_user
"""
enterprise_customer = EnterpriseCustomerFactory()
EnterpriseCustomerUserFactory(
user_id=self.user.id,
enterprise_customer=enterprise_customer
)
self.assertTrue(mock_update_user.called)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment