<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Script to migrate nodes with invalid categories."""

import logging

from modularodm import Q
from nose.tools import *
from tests.base import OsfTestCase

from website import models
from website.app import init_app
from scripts import utils as scripts_utils
from tests.factories import AuthUserFactory


logger = logging.getLogger(__name__)


def main():
    init_app(routes=False)
    logger.info("migrating personal to profileWebsites")
            
    for user in get_users_with_social_field():
        logger.info(repr(user))
        logger.info(repr(user.social))
        if not user.social.get('profileWebsites', None):
            user.social['profileWebsites'] = []
            if user.social.get('personal'):
                migrate_personal_to_profile_websites(user)
        logger.info(repr(user.social))
        user.save()


def get_users_with_social_field():
    return models.User.find(
        Q('social', 'ne', {})
    )


def migrate_personal_to_profile_websites(user):
    user.social['profileWebsites'].append(user.social.get('personal'))


class TestMigrateProfileWebsites(OsfTestCase):

    def setUp(self):<commit_msg>improve logging<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Script to migrate single value personal to profile_websites list."""

import logging

from modularodm import Q
from nose.tools import *
from tests.base import OsfTestCase

from website import models
from website.app import init_app
from scripts import utils as scripts_utils
from tests.factories import AuthUserFactory


logger = logging.getLogger(__name__)


def main():
    init_app(routes=False)
    logger.info("migrating personal to profileWebsites")
            
    for user in get_users_with_social_field():
        logger.info(repr(user))
        logger.info("Migrating User: %s" % repr(user._id))
        if not user.social.get('profileWebsites', None):
            user.social['profileWebsites'] = []
            if user.social.get('personal'):
                migrate_personal_to_profile_websites(user)
        logger.info(repr(user.social))
        user.save()


def get_users_with_social_field():
    return models.User.find(
        Q('social', 'ne', {})
    )


def migrate_personal_to_profile_websites(user):
    user.social['profileWebsites'].append(user.social.get('personal'))


class TestMigrateProfileWebsites(OsfTestCase):

    def setUp(self):
{'fraction_non_alphanumeric': 0.10975112199102408, 'fraction_numerical': 0.0008159934720522236, 'mean_word_length': 3.5917602996254683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6538160', 'n_tokens_mistral': 747, 'n_tokens_neox': 726, 'n_words': 165}