How to use the sortinghat.api.unique_identities 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_cmd_autoprofile.py View on Github external
def test_autocomplete_no_sources(self):
        """Check whether it does nothing when there are no identities from a source"""

        code = self.cmd.run('source1', 'source2')

        self.assertEqual(code, CMD_SUCCESS)
        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, "")

        # Unique identities remain without profiles
        uids = api.unique_identities(self.db)

        self.assertEqual(uids[0].profile.name, None)
        self.assertEqual(uids[0].profile.email, None)
        self.assertEqual(uids[1].profile.name, None)
        self.assertEqual(uids[1].profile.email, None)
        self.assertEqual(uids[2].profile.name, None)
        self.assertEqual(uids[2].profile.email, None)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_autogender.py View on Github external
def test_autogender_all(self):
        """Test whether all gener info is overwritten"""

        http_requests = setup_genderize_server()

        self.cmd.autogender(api_token='abcdefghi', genderize_all=True)

        uids = api.unique_identities(self.db)

        prf = uids[0].profile
        self.assertEqual(prf.uuid, '2a9ec221b8dd5d5a85ae0e3276b8b2c3618ee15e')
        self.assertEqual(prf.gender, 'female')
        self.assertEqual(prf.gender_acc, 100)

        prf = uids[1].profile
        self.assertEqual(prf.uuid, '3e1eccdb1e52ea56225f419d3e532fe9133c7821')
        self.assertEqual(prf.gender, 'female')
        self.assertEqual(prf.gender_acc, 100)

        prf = uids[2].profile
        self.assertEqual(prf.uuid, '539acca35c2e8502951a97d2d5af8b0857440b50')
        self.assertEqual(prf.gender, 'male')
        self.assertEqual(prf.gender_acc, 99)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_unify.py View on Github external
def test_unify_fast_matching(self):
        """Test unify method using a default matcher and fast matching mode"""

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='default', fast_matching=True)
        self.assertEqual(code, CMD_SUCCESS)

        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 5)

        # jsmith identities with same email address
        jsmith = after[0]
        self.assertEqual(jsmith.uuid, '178315df7941fc76a6ffb06fd5b00f6932ad9c41')

        identities = jsmith.identities
        identities.sort(key=lambda x: x.id)

        self.assertEqual(len(identities), 7)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_load.py View on Github external
def test_matching_no_strict(self):
        """Check if identities with no strict matching are merged"""

        # First, insert the identity that will match with one
        # from the file
        api.add_identity(self.db, 'unknown', email='jsmith@example')

        parser = self.get_parser(datadir('sortinghat_no_strict_valid.json'))

        code = self.cmd.import_identities(parser, matching='default',
                                          no_strict_matching=True)
        self.assertEqual(code, CMD_SUCCESS)

        # Check whether identities were merged
        uids = api.unique_identities(self.db)
        self.assertEqual(len(uids), 1)
        self.assertEqual(len(uids[0].identities), 2)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_unify.py View on Github external
def test_unify_email_name_matcher(self):
        """Test unify method using the email-name matcher"""

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='email-name')
        self.assertEqual(code, CMD_SUCCESS)

        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 3)

        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, UNIFY_EMAIL_NAME_OUTPUT)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_unify.py View on Github external
def test_unify_with_sources_list(self):
        """Test unify method using a sources list"""

        sources = ['mls', 'alt']

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='email-name', sources=sources)
        self.assertEqual(code, CMD_SUCCESS)

        # Only jrae identities are merged
        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 5)

        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, UNIFY_SOURCES_OUTPUT)
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
# 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')
        self.assertEqual(uid.profile.name, None)
        self.assertEqual(uid.profile.email, 'jsmith@example.com')
        self.assertEqual(uid.profile.is_bot, True)
        self.assertEqual(uid.profile.country_code, 'US')
        self.assertEqual(uid.profile.country.code, 'US')
        self.assertEqual(uid.profile.country.name, 'United States of America')

        self.assertEqual(len(uid.identities), 3)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_unify.py View on Github external
def test_unify_email_name_matcher(self):
        """Test unify method using the email-name matcher"""

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='email-name')
        self.assertEqual(code, CMD_SUCCESS)

        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 3)

        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, UNIFY_EMAIL_NAME_OUTPUT)
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / affiliate.py View on Github external
def affiliate(self):
        """Affiliate unique identities.

        This method enrolls unique identities to organizations using email
        addresses and top/sub domains data. Only new enrollments will be created.
        """
        try:
            uidentities = api.unique_identities(self.db)

            for uid in uidentities:
                uid.identities.sort(key=lambda x: x.id)

                for identity in uid.identities:
                    # Only check email address to find new affiliations
                    if not identity.email:
                        continue
                    if not EMAIL_ADDRESS_PATTERN.match(identity.email):
                        continue

                    domain = identity.email.split('@')[-1]

                    try:
                        doms = api.domains(self.db, domain=domain, top=True)
                    except NotFoundError as e:
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / show.py View on Github external
When  is set, it will only show information about those unique
        identities that have any attribute (name, email, username, source)
        which match with the given term. This parameter does not have any
        effect when  is set.

        :param uuid: unique identifier
        :param term: term to match with unique identities data
        """
        try:
            if uuid:
                uidentities = api.unique_identities(self.db, uuid)
            elif term:
                uidentities = api.search_unique_identities(self.db, term)
            else:
                uidentities = api.unique_identities(self.db)

            for uid in uidentities:
                # Add enrollments to a new property 'roles'
                enrollments = api.enrollments(self.db, uid.uuid)
                uid.roles = enrollments

            self.display('show.tmpl', uidentities=uidentities)
        except NotFoundError as e:
            self.error(str(e))
            return e.code

        return CMD_SUCCESS