How to use the sortinghat.api.add_unique_identity 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
def test_not_found_identities(self):
        """Test whether it fails when uuid is not found"""

        # Add some unique identities first
        api.add_unique_identity(self.db, 'John Smith')
        api.add_identity(self.db, 'scm', 'jsmith@example.com',
                         uuid='John Smith')
        api.add_unique_identity(self.db, 'Smith J.')
        api.add_identity(self.db, 'mls', 'jsmith@example.com',
                         uuid='Smith J.')

        matcher = create_identity_matcher('default')

        self.assertRaisesRegexp(NotFoundError,
                                NOT_FOUND_ERROR % {'entity' : 'Jane Roe'},
                                api.match_identities,
                                self.db, 'Jane Roe', matcher)
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_delete_with_period_ranges(self):
        """Check whether it deletes a set of enrollments using some periods"""

        # First, add a set of uuids, organizations and enrollments
        api.add_unique_identity(self.db, 'John Smith')
        api.add_unique_identity(self.db, 'John Doe')

        api.add_organization(self.db, 'Example')
        api.add_enrollment(self.db, 'John Smith', 'Example')
        api.add_enrollment(self.db, 'John Smith', 'Example',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2010, 1, 1))
        api.add_enrollment(self.db, 'John Smith', 'Example',
                           datetime.datetime(1981, 1, 1),
                           datetime.datetime(1990, 1, 1))
        api.add_enrollment(self.db, 'John Smith', 'Example',
                           datetime.datetime(1991, 1, 1),
                           datetime.datetime(1993, 1, 1))

        # This should delete two enrolmments: 1981-1990 and 1991-1993
        # but not the one from 1999-2010 nor 1900-21000
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_not_found_unique_identities(self):
        """Test whether it fails when one of the unique identities is not found"""

        # Add some unique identities first
        api.add_unique_identity(self.db, 'John Smith')
        api.add_unique_identity(self.db, 'John Doe')

        # Check 'from_uuid' parameter
        self.assertRaisesRegexp(NotFoundError,
                                NOT_FOUND_ERROR % {'entity' : 'Jane Roe'},
                                api.merge_unique_identities,
                                self.db, 'Jane Roe', 'John Smith')

        # Check 'to_uuid' parameter
        self.assertRaisesRegexp(NotFoundError,
                                NOT_FOUND_ERROR % {'entity' : 'Jane Roe'},
                                api.merge_unique_identities,
                                self.db, 'John Smith', 'Jane Roe')

        # Even if the identities are the same and do not exist, it still
        # raises the exception
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_invalid_type_is_bot(self):
        """Check type values of is_bot parameter"""

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

        self.assertRaisesRegexp(ValueError, IS_BOT_VALUE_ERROR,
                                api.edit_profile, self.db, 'John Smith',
                                **{'is_bot' : 1})
        self.assertRaisesRegexp(ValueError, IS_BOT_VALUE_ERROR,
                                api.edit_profile, self.db, 'John Smith',
                                **{'is_bot' : 'True'})
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_not_found_country_code(self):
        """Check if it fails when the given country is not found"""

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

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

        self.assertRaisesRegexp(NotFoundError,
                                NOT_FOUND_ERROR % {'entity' : 'country code ES'},
                                api.edit_profile, self.db, 'John Smith',
                                **{'country_code' : 'ES'})
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_equal_unique_identities(self):
        """Test that all remains the same when 'from' and 'to' identities are the same"""

        # Add some unique identities and identities
        api.add_unique_identity(self.db, 'John Smith')
        api.add_identity(self.db, 'scm', 'jsmith@example.com',
                         uuid='John Smith')
        api.add_identity(self.db, 'scm', 'jsmith@example.com', 'John Smith',
                         uuid='John Smith')

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

        # Merge the same identity
        api.merge_unique_identities(self.db, 'John Smith', 'John Smith')

        # Nothing has happened
        with self.db.connect() as session:
            uidentities = session.query(UniqueIdentity).\
                order_by(UniqueIdentity.uuid).all()
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_delete_organizations(self):
        """Check whether it deletes a set of organizations"""

        # First, add a set of organizations, including some domains
        # and enrollments
        api.add_unique_identity(self.db, 'John Smith')
        api.add_unique_identity(self.db, 'John Doe')
        api.add_organization(self.db, 'Example')
        api.add_domain(self.db, 'Example', 'example.com')
        api.add_domain(self.db, 'Example', 'example.org')
        api.add_enrollment(self.db, 'John Smith', 'Example')
        api.add_enrollment(self.db, 'John Doe', 'Example')
        api.add_organization(self.db, 'Bitergia')
        api.add_domain(self.db, 'Bitergia', 'bitergia.com')
        api.add_enrollment(self.db, 'John Smith', 'Bitergia')
        api.add_organization(self.db, 'LibreSoft')

        # Delete the first organization
        api.delete_organization(self.db, 'Example')

        with self.db.connect() as session:
            org1 = session.query(Organization).\
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_equal_related_unique_identity(self):
        """Test that all remains the same when to_uuid is the unique identity related to 'from_id'"""

        # Add some unique identities and identities first
        api.add_unique_identity(self.db, 'John Smith')
        from_id = api.add_identity(self.db, 'scm', 'jsmith@example.com',
                                   uuid='John Smith')

        api.add_unique_identity(self.db, 'John Doe')
        api.add_identity(self.db, 'scm', 'jdoe@example.com',
                         uuid='John Doe')
        new_uuid = api.add_identity(self.db, 'scm', 'john.doe@example.com',
                                    uuid='John Doe')

        # Move the identity to the same unique identity
        api.move_identity(self.db, from_id, 'John Smith')

        # Nothing has happened
        with self.db.connect() as session:
            uidentities = session.query(UniqueIdentity).all()
            self.assertEqual(len(uidentities), 2)

            uid = uidentities[0]
            self.assertEqual(uid.uuid, 'John Doe')
            self.assertEqual(len(uid.identities), 2)
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_merge_identitites(self):
        """Test behavior merging unique identities"""

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

        api.add_unique_identity(self.db, 'John Smith')
        api.add_identity(self.db, 'scm', 'jsmith@example.com',
                         uuid='John Smith')
        api.add_identity(self.db, 'scm', 'jsmith@example.com', 'John Smith',
                         uuid='John Smith')
        api.edit_profile(self.db, 'John Smith', name='John Smith', is_bot=True,
                         country_code='US')

        api.add_unique_identity(self.db, 'John Doe')
        api.add_identity(self.db, 'scm', 'jdoe@example.com',
                         uuid='John Doe')
        api.edit_profile(self.db, 'John Doe', email='jdoe@example.com', 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')
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)