-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/es/sql-user-data' into autostaging
- Loading branch information
Showing
23 changed files
with
385 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,39 +6,38 @@ | |
get_user_contributions_to_touchforms_session, | ||
) | ||
from corehq.apps.custom_data_fields.models import ( | ||
PROFILE_SLUG, | ||
CustomDataFieldsDefinition, | ||
CustomDataFieldsProfile, | ||
Field, | ||
PROFILE_SLUG, | ||
) | ||
from corehq.apps.users.views.mobile.custom_data_fields import UserFieldsView | ||
from corehq.apps.users.models import CommCareUser, WebUser | ||
from corehq.apps.users.views.mobile.custom_data_fields import UserFieldsView | ||
from corehq.form_processor.models import CommCareCase | ||
|
||
|
||
class SessionUtilsTest(TestCase): | ||
|
||
def test_load_session_data_for_mobile_worker(self): | ||
user = CommCareUser( | ||
domain='cloudcare-tests', | ||
username='[email protected]', | ||
_id=uuid.uuid4().hex | ||
) | ||
user = CommCareUser.create('cloudcare-tests', '[email protected]', | ||
'password', None, None) | ||
self.addCleanup(user.delete, None, None) | ||
data = get_user_contributions_to_touchforms_session('cloudcare-tests', user) | ||
self.assertEqual('worker', data['username']) | ||
self.assertEqual(user._id, data['user_id']) | ||
self.assertTrue(isinstance(data['user_data'], dict)) | ||
self.assertTrue(data['user_data']['commcare_project'], 'cloudcare-tests') | ||
|
||
def test_default_user_data(self): | ||
user = CommCareUser( | ||
domain='cloudcare-tests', | ||
username='[email protected]', | ||
_id=uuid.uuid4().hex | ||
) | ||
user = CommCareUser.create('cloudcare-tests', '[email protected]', | ||
'password', None, None) | ||
self.addCleanup(user.delete, None, None) | ||
|
||
user_data = get_user_contributions_to_touchforms_session('cloudcare-tests', user)['user_data'] | ||
for key in ['commcare_first_name', 'commcare_last_name', 'commcare_phone_number']: | ||
self.assertEqual(None, user_data[key]) | ||
self.assertEqual('', user_data['commcare_first_name']) | ||
self.assertEqual('', user_data['commcare_last_name']) | ||
self.assertEqual(None, user_data['commcare_phone_number']) | ||
|
||
user.first_name = 'first' | ||
user.last_name = 'last' | ||
user_data = get_user_contributions_to_touchforms_session('cloudcare-tests', user)['user_data'] | ||
|
@@ -70,10 +69,7 @@ def test_user_data_profile(self): | |
self.assertEqual('supernova', user_data['word']) | ||
|
||
def test_load_session_data_for_web_user(self): | ||
user = WebUser( | ||
username='[email protected]', | ||
_id=uuid.uuid4().hex | ||
) | ||
user = WebUser.create(None, '[email protected]', '123', None, None) | ||
data = get_user_contributions_to_touchforms_session('cloudcare-tests', user) | ||
self.assertEqual('[email protected]', data['username']) | ||
self.assertEqual(user._id, data['user_id']) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
HqPermissions, | ||
) | ||
from corehq.apps.users.model_log import UserModelAction | ||
from corehq.apps.users.tests.util import patch_user_data_db_layer | ||
from corehq.apps.users.views.mobile.custom_data_fields import UserFieldsView | ||
from corehq.const import USER_CHANGE_VIA_BULK_IMPORTER | ||
from corehq.extensions.interface import disable_extensions | ||
|
@@ -677,9 +678,7 @@ def test_user_data_profile_redundant(self): | |
PROFILE_SLUG: self.profile.id, | ||
}) | ||
# Profile fields shouldn't actually be added to user_data | ||
self.assertEqual(self.user.get_user_data(self.domain.name).raw, { | ||
PROFILE_SLUG: self.profile.id, | ||
}) | ||
self.assertEqual(self.user.get_user_data(self.domain.name).raw, {}) | ||
|
||
def test_user_data_profile_blank(self): | ||
import_users_and_groups( | ||
|
@@ -2062,6 +2061,7 @@ def test_tableau_users(self, mock_request): | |
local_tableau_users.get(username='[email protected]') | ||
|
||
|
||
@patch_user_data_db_layer | ||
class TestUserChangeLogger(SimpleTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
corehq/apps/users/management/commands/populate_sql_user_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# One-off migration, November 2023 | ||
|
||
from django.contrib.auth.models import User | ||
from django.core.management.base import BaseCommand | ||
|
||
from corehq.apps.users.models import CouchUser | ||
from corehq.util.log import with_progress_bar | ||
from corehq.util.queries import queryset_to_iterator | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Populate SQL user data from couch" | ||
|
||
def handle(self, **options): | ||
queryset = get_users_without_user_data() | ||
for user in with_progress_bar(queryset_to_iterator(queryset, User), queryset.count()): | ||
populate_user_data(user) | ||
|
||
|
||
def get_users_without_user_data(): | ||
return User.objects.filter(sqluserdata__isnull=True) | ||
|
||
|
||
def populate_user_data(django_user): | ||
user = CouchUser.from_django_user(django_user, strict=True) | ||
for domain in user.domains: # get_domains? | ||
user.get_user_data(domain).save() |
Oops, something went wrong.