Modernize INCR-210 user_api/management (#20435)
This commit is contained in:
committed by
Jeremy Bowman
parent
1d5a72ac33
commit
920ce74877
@@ -16,14 +16,16 @@ If the user/org combo does not currently exist in the table, a row will be creat
|
||||
will be have the 'email-optin' tag set to 'False'.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import csv
|
||||
import logging
|
||||
import time
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import connections
|
||||
from django.db.utils import DatabaseError
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from six.moves import range
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@ Use this mgmt command when a user requests retirement mistakenly, then requests
|
||||
for the retirement request to be cancelled. The command can't cancel a retirement
|
||||
that has already commenced - only pending retirements.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import logging
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from openedx.core.djangoapps.user_api.accounts.utils import generate_password
|
||||
from openedx.core.djangoapps.user_api.models import UserRetirementStatus
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -4,34 +4,30 @@ Enrolls the user in the DemoX course.
|
||||
Optionally takes in username, email, and course UUID arguments.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
from pytz import UTC
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
from consent.models import DataSharingConsent
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.base import BaseCommand
|
||||
from enterprise.models import (
|
||||
EnterpriseCourseEnrollment,
|
||||
EnterpriseCustomer,
|
||||
EnterpriseCustomerUser,
|
||||
PendingEnterpriseCustomerUser,
|
||||
PendingEnterpriseCustomerUser
|
||||
)
|
||||
from entitlements.models import CourseEntitlement, CourseEntitlementSupportDetail
|
||||
from integrated_channels.sap_success_factors.models import SapSuccessFactorsLearnerDataTransmissionAudit
|
||||
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from openedx.core.djangoapps.course_groups.models import UnregisteredLearnerCohortAssignments, CourseUserGroup
|
||||
from pytz import UTC
|
||||
|
||||
from entitlements.models import CourseEntitlement, CourseEntitlementSupportDetail
|
||||
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
|
||||
from openedx.core.djangoapps.course_groups.models import CourseUserGroup, UnregisteredLearnerCohortAssignments
|
||||
from openedx.core.djangoapps.profile_images.images import create_profile_images
|
||||
from openedx.core.djangoapps.profile_images.tests.helpers import make_image_file
|
||||
from student.models import (
|
||||
CourseEnrollment,
|
||||
PendingEmailChange,
|
||||
UserProfile,
|
||||
CourseEnrollmentAllowed
|
||||
)
|
||||
from student.models import CourseEnrollment, CourseEnrollmentAllowed, PendingEmailChange, UserProfile
|
||||
|
||||
from ...models import UserOrgTag
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ When reports are generated, we need to handle:
|
||||
The command will always use the read replica database if one is configured.
|
||||
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import contextlib
|
||||
import csv
|
||||
@@ -34,6 +34,7 @@ from django.db import connections
|
||||
from django.utils import timezone
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from six import text_type
|
||||
from six.moves import range
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
@@ -43,7 +44,7 @@ LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def chunks(sequence, chunk_size):
|
||||
return (sequence[index: index + chunk_size] for index in xrange(0, len(sequence), chunk_size))
|
||||
return (sequence[index: index + chunk_size] for index in range(0, len(sequence), chunk_size))
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
"""
|
||||
Migrates user preferences from one language code to another in batches. Dark lang preferences are not affected.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import logging
|
||||
from time import sleep
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db.models import Q, Max
|
||||
from django.db.models import Max, Q
|
||||
|
||||
from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
|
||||
from openedx.core.djangoapps.user_api.models import UserPreference
|
||||
|
||||
|
||||
DEFAULT_CHUNK_SIZE = 10000
|
||||
DEFAULT_SLEEP_TIME_SECS = 10
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ need to be configurable by open source partners and modifying the
|
||||
with a variety of unpleasant follow-on effects for the partner when
|
||||
upgrading the model at a later date.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import copy
|
||||
import logging
|
||||
@@ -20,7 +20,6 @@ from django.db.models import F
|
||||
|
||||
from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
START_STATE = 'PENDING'
|
||||
|
||||
@@ -3,16 +3,17 @@ Management command to sync platform users with hubspot
|
||||
./manage.py lms sync_hubspot_contacts
|
||||
./manage.py lms sync_hubspot_contacts --initial-sync-days=7 --batch-size=20
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
import time
|
||||
import traceback
|
||||
import urlparse
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import six.moves.urllib.parse
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils.html import escapejs
|
||||
|
||||
from edx_rest_api_client.client import EdxRestApiClient
|
||||
from slumber.exceptions import HttpClientError, HttpServerError
|
||||
|
||||
@@ -137,7 +138,7 @@ class Command(BaseCommand):
|
||||
contacts.append(contact)
|
||||
|
||||
api_key = site_conf.get_value('HUBSPOT_API_KEY')
|
||||
client = EdxRestApiClient(urlparse.urljoin(HUBSPOT_API_BASE_URL, 'contacts/v1/contact'))
|
||||
client = EdxRestApiClient(six.moves.urllib.parse.urljoin(HUBSPOT_API_BASE_URL, 'contacts/v1/contact'))
|
||||
try:
|
||||
client.batch.post(contacts, hapikey=api_key)
|
||||
return len(contacts)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"""
|
||||
Test the test_bulk_user_org_email_optout management command
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
from contextlib import contextmanager
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from django.core.management import call_command
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Test the cancel_user_retirement_request management command
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Tests for the email opt-in list management command. """
|
||||
import os.path
|
||||
import tempfile
|
||||
import shutil
|
||||
from __future__ import absolute_import
|
||||
|
||||
import csv
|
||||
import os.path
|
||||
import shutil
|
||||
import tempfile
|
||||
from collections import defaultdict
|
||||
|
||||
import ddt
|
||||
@@ -11,16 +13,16 @@ from django.contrib.auth.models import User
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
from six import text_type
|
||||
from six.moves import range
|
||||
|
||||
from openedx.core.djangoapps.user_api.management.commands import email_opt_in_list
|
||||
from openedx.core.djangoapps.user_api.models import UserOrgTag
|
||||
from openedx.core.djangoapps.user_api.preferences.api import update_email_opt_in
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from student.models import CourseEnrollment
|
||||
from student.tests.factories import CourseEnrollmentFactory, UserFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from student.tests.factories import UserFactory, CourseEnrollmentFactory
|
||||
from student.models import CourseEnrollment
|
||||
|
||||
from openedx.core.djangoapps.user_api.preferences.api import update_email_opt_in
|
||||
from openedx.core.djangoapps.user_api.models import UserOrgTag
|
||||
from openedx.core.djangoapps.user_api.management.commands import email_opt_in_list
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
"""
|
||||
Test the populate_retirement_states management command
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import copy
|
||||
|
||||
import pytest
|
||||
from django.core.management import CommandError, call_command
|
||||
|
||||
from django.core.management import call_command, CommandError
|
||||
|
||||
from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus
|
||||
from openedx.core.djangoapps.user_api.management.commands.populate_retirement_states import START_STATE
|
||||
from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus
|
||||
from student.tests.factories import UserFactory
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
"""
|
||||
Test the sync_hubspot_contacts management command
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from datetime import timedelta
|
||||
from mock import patch
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
from django.utils.six import StringIO
|
||||
from mock import patch
|
||||
from six.moves import range
|
||||
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory
|
||||
from openedx.core.djangoapps.user_api.management.commands.sync_hubspot_contacts import Command as sync_command
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from student.models import UserAttribute, UserProfile
|
||||
from student.tests.factories import UserFactory
|
||||
|
||||
|
||||
Reference in New Issue
Block a user