Skip to content
Snippets Groups Projects
Commit 920ce748 authored by Evans Dianga's avatar Evans Dianga Committed by Jeremy Bowman
Browse files

Modernize INCR-210 user_api/management (#20435)

parent 1d5a72ac
Branches
Tags
No related merge requests found
Showing
with 52 additions and 43 deletions
......@@ -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):
......
"""
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)
......
"""
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
......
"""
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
......
# -*- coding: utf-8 -*-
"""Tests for the email opt-in list management command. """
from __future__ import absolute_import
import csv
import os.path
import tempfile
import shutil
import csv
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 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.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
@ddt.ddt
......
"""
Test the populate_retirement_states management command
"""
from __future__ import absolute_import
import copy
import pytest
from django.core.management import call_command, CommandError
import pytest
from django.core.management import CommandError, call_command
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
......
"""
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
......
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