How to use the sortinghat.api.edit_profile function in sortinghat

To help you get started, weā€™ve selected a few sortinghat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
"""Check if it creates an new profile"""

        api.add_unique_identity(self.db, 'John Smith')

        with self.db.connect() as session:
            # Add a country
            us = Country(code='US', name='United States of America', alpha3='USA')
            session.add(us)

            # There are not profiles for the given uuid yet
            prf = session.query(Profile).\
                filter(Profile.uuid == 'John Smith').first()
            self.assertEqual(prf, None)

        # Add the new profile
        api.edit_profile(self.db, 'John Smith', name='Smith, J.', email='',
                         is_bot=True, country_code='US')

        with self.db.connect() as session:
            uid = session.query(UniqueIdentity).\
                filter(UniqueIdentity.uuid == 'John Smith').first()

            prf = uid.profile

            self.assertEqual(prf.uuid, 'John Smith')
            self.assertEqual(prf.name, 'Smith, J.')
            # This should be converted to None
            self.assertEqual(prf.email, None)
            self.assertEqual(prf.is_bot, True)
            self.assertEqual(prf.country_code, 'US')
            self.assertEqual(prf.country.code, 'US')
            self.assertEqual(prf.country.name, 'United States of America')
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_delete_unique_identities(self):
        """Check whether it deletes a set of unique identities"""

        # First, add a set of unique identities, including some
        # identities, organizations and enrollments
        api.add_unique_identity(self.db, 'John Smith')
        api.add_identity(self.db, 'scm', 'jsmith@example',
                         uuid='John Smith')
        api.add_identity(self.db, 'scm', 'jsmith@example', 'John Smith',
                         uuid='John Smith')

        api.add_unique_identity(self.db, 'John Doe')
        api.edit_profile(self.db, 'John Doe', name='John Doe', is_bot=False)

        api.add_unique_identity(self.db, 'Jane Rae')

        api.add_organization(self.db, 'Example')
        api.add_enrollment(self.db, 'John Smith', 'Example')
        api.add_enrollment(self.db, 'John Doe', 'Example')

        api.add_organization(self.db, 'Bitergia')
        api.add_enrollment(self.db, 'John Smith', 'Bitergia')

        api.add_organization(self.db, 'LibreSoft')
        api.add_enrollment(self.db, 'Jane Rae', 'LibreSoft')

        # Delete the first identity
        api.delete_unique_identity(self.db, 'John Smith')
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_unique_identities(self):
        """Check if it returns the registry of unique identities"""

        # Add a country
        with self.db.connect() as session:
            us = Country(code='US', name='United States of America', alpha3='USA')
            session.add(us)

        # Add some identities
        jsmith_uuid = api.add_identity(self.db, 'scm', 'jsmith@example.com',
                                       'John Smith', 'jsmith')
        api.add_identity(self.db, 'scm', 'jsmith@bitergia.com', uuid=jsmith_uuid)
        api.add_identity(self.db, 'mls', 'jsmith@bitergia.com', uuid=jsmith_uuid)
        api.edit_profile(self.db, jsmith_uuid, email='jsmith@example.com',
                         is_bot=True, country_code='US')


        jdoe_uuid = api.add_identity(self.db, 'scm', 'jdoe@example.com',
                                     'John Doe', 'jdoe')
        api.add_identity(self.db, 'scm', 'jdoe@libresoft.es', uuid=jdoe_uuid)

        # Tests
        uidentities = api.unique_identities(self.db)
        self.assertEqual(len(uidentities), 2)

        # Test John Smith unique identity
        uid = uidentities[0]
        self.assertEqual(uid.uuid, 'a9b403e150dd4af8953a52a4bb841051e4b705d9')

        self.assertEqual(uid.profile.uuid, 'a9b403e150dd4af8953a52a4bb841051e4b705d9')
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_update_profile(self):
        """Check if it updates an existing profile"""

        with self.db.connect() as session:
            # Add a country
            us = Country(code='US', name='United States of America', alpha3='USA')
            session.add(us)

        # Add a unique identity with a profile
        api.add_unique_identity(self.db, 'John Smith')
        api.edit_profile(self.db, 'John Smith', name='Smith, J.',
                         is_bot=True)

        with self.db.connect() as session:
            uid = session.query(UniqueIdentity).\
                filter(UniqueIdentity.uuid == 'John Smith').first()

            prf = uid.profile

            self.assertEqual(prf.uuid, 'John Smith')
            self.assertEqual(prf.name, 'Smith, J.')
            self.assertEqual(prf.email, None)
            self.assertEqual(prf.is_bot, True)
            self.assertEqual(prf.country_code, None)
            self.assertEqual(prf.country, None)

        # Update some fields
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_not_found_uuid(self):
        """Check if it fails editing a profile of a unique identity that does not exists"""

        # It should raise an error when the registry is empty
        self.assertRaises(NotFoundError, api.edit_profile,
                          self.db, 'John Smith')

        # Add a pair of unique identities first
        api.add_unique_identity(self.db, 'Jonh Smith')
        api.add_unique_identity(self.db, 'John Doe')

        # The error should be the same
        self.assertRaises(NotFoundError, api.edit_profile,
                          self.db, 'Jane Rae')
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / load.py View on Github external
# We need a name for each profile, so if no one was defined,
        # use email or username to complete it.
        if not name:
            if email:
                name = email.split('@')[0]
            elif username:
                # filter email addresses on username fields
                name = username.split('@')[0]
            else:
                name = None

        kw = {'name': name,
              'email': email}

        api.edit_profile(self.db, uuid, **kw)

        self.log("-- profile %s updated" % uuid, verbose)
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / load.py View on Github external
def __create_profile(self, profile, uuid, verbose):
        """Create profile information from a profile object"""

        # Set parameters to edit
        kw = profile.to_dict()
        kw['country_code'] = profile.country_code

        # Remove unused keywords
        kw.pop('uuid')
        kw.pop('country')

        api.edit_profile(self.db, uuid, **kw)

        self.log("-- profile %s updated" % uuid, verbose)
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / autogender.py View on Github external
msg = "Skipping '%s' name (%s) due to a connection error. Error: %s"
                    msg = msg % (firstname, profile.uuid, str(e))
                    self.warning(msg)
                    continue

                gender_data = {
                    'gender': gender,
                    'gender_acc': acc
                }
                name_cache[firstname] = gender_data

            if not gender_data['gender']:
                continue

            try:
                api.edit_profile(self.db, profile.uuid, **gender_data)
                self.display('autogender.tmpl',
                             uuid=profile.uuid, name=profile.name,
                             gender_data=gender_data)
            except (NotFoundError, InvalidValueError) as e:
                self.error(str(e))
                return e.code

        return CMD_SUCCESS