How to use the sortinghat.command.CMD_SUCCESS 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_add.py View on Github external
def test_add_new_identities(self):
        """Check if everything goes OK when adding a set of new identities"""

        self.cmd.add('scm', 'jroe@example.com', 'Jane Roe', 'jrae')
        self.cmd.add('scm', 'jroe@example.com')
        self.cmd.add('unknown', 'jroe@example.com')

        # Add this identity to 'Jonh Smith' - a9b403e150dd4af8953a52a4bb841051e4b705d9
        code = self.cmd.add('mls', email='jsmith@example.com',
                            uuid='a9b403e150dd4af8953a52a4bb841051e4b705d9')
        self.assertEqual(code, CMD_SUCCESS)

        # Check output first
        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, ADD_OUTPUT)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_load.py View on Github external
uids = api.unique_identities(self.db)
        self.assertEqual(len(uids), 2)

        # We add a new identity that matches with some of the
        # already inserted
        jsmith_uuid = api.add_identity(self.db, 'unknown', email='jsmith@example.com')

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

        # This file has a new identity, only Jane Roe will match.
        parser = self.get_parser(datadir('sortinghat_valid_updated.json'))

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

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

        # Jane Roe
        uid = uids[0]
        self.assertEqual(uid.uuid, '17ab00ed3825ec2f50483e33c88df223264182ba')

        ids = self.sort_identities(uid.identities)
        self.assertEqual(len(ids), 4)

        self.assertEqual(ids[0].id, '17ab00ed3825ec2f50483e33c88df223264182ba')
        self.assertEqual(ids[1].id, '22d1b20763c6f5822bdda8508957486c547bb9de')
        self.assertEqual(ids[2].id, '322397ed782a798ffd9d0bc7e293df4292fe075d')
        self.assertEqual(ids[3].id, '8ff87accaf518070bdb494b87f4d5a10e7605b47')
github chaoss / grimoirelab-sortinghat / tests / test_cmd_blacklist.py View on Github external
"""Test add action"""

        # Remove pre-loaded dataset
        self.db.clear()

        code = self.cmd.run('--add', 'John Smith')
        self.assertEqual(code, CMD_SUCCESS)

        code = self.cmd.run('-a', 'Bitergia')
        self.assertEqual(code, CMD_SUCCESS)

        code = self.cmd.run('--add', 'John Doe')
        self.assertEqual(code, CMD_SUCCESS)

        code = self.cmd.run('-a', 'root@example.com')
        self.assertEqual(code, CMD_SUCCESS)

        code = self.cmd.run('--list')
        self.assertEqual(code, CMD_SUCCESS)

        # Check output
        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, BLACKLIST_OUTPUT)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_merge.py View on Github external
def test_none_uuids(self):
        """Check behavior merging None uuids"""

        code = self.cmd.merge(None, 'John Smith')
        self.assertEqual(code, CMD_SUCCESS)

        code = self.cmd.merge('John Smith', None)
        self.assertEqual(code, CMD_SUCCESS)

        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, MERGE_EMPTY_OUTPUT)

        output = sys.stderr.getvalue().strip()
        self.assertEqual(output, MERGE_EMPTY_OUTPUT)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_autoprofile.py View on Github external
def test_autocomplete(self):
        """Test autocomolete command"""

        code = self.cmd.run('mls', 'its')

        self.assertEqual(code, CMD_SUCCESS)
        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, PROFILE_AUTOCOMPLETE)
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / config.py View on Github external
if not os.path.isfile(filepath):
            raise RuntimeError("%s config file does not exist" % filepath)

        section, option = key.split('.')

        config = configparser.SafeConfigParser()
        config.read(filepath)

        try:
            option = config.get(section, option)
            self.display('config.tmpl', key=key, option=option)
        except (configparser.NoSectionError, configparser.NoOptionError):
            pass

        return CMD_SUCCESS
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / enroll.py View on Github external
and , where "from_date <= to_date". Default values for these
        dates are '1900-01-01' and '2100-01-01'.

        When "merge" parameter is set to True, those overlapped enrollments related
        to  and  found on the registry will be merged. The given
        enrollment will be also merged.

        :param uuid: unique identifier
        :param organization: name of the organization
        :param from_date: date when the enrollment starts
        :param to_date: date when the enrollment ends
        :param merge: merge overlapped enrollments; by default, it is set to False
        """
        # Empty or None values for uuid and organizations are not allowed
        if not uuid or not organization:
            return CMD_SUCCESS

        try:
            api.add_enrollment(self.db, uuid, organization, from_date, to_date)
            code = CMD_SUCCESS
        except (NotFoundError, InvalidValueError) as e:
            self.error(str(e))
            code = e.code
        except AlreadyExistsError as e:
            if not merge:
                msg_data = {
                    'uuid': uuid,
                    'org': organization,
                    'from_dt': str(from_date),
                    'to_dt': str(to_date)
                }
                msg = "enrollment for '%(uuid)s' at '%(org)s' (from: %(from_dt)s, to: %(to_dt)s) already exists in the registry"
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / merge.py View on Github external
from the registry. Duplicated enrollments will be also removed from the
        registry.

        Profile information will be updated with the values of  in the
        case of  values were empty. If  was set as a bot,
         will be set too.

        When  and  are equal, None or empty, the action does
        not have any effect.

        :param from_uuid: identifier of the unique identity set to merge
        :param to_uuid: identifier of the unique identity where 'from_uuid'
            will be merged
        """
        if not from_uuid or not to_uuid:
            return CMD_SUCCESS

        try:
            api.merge_unique_identities(self.db, from_uuid, to_uuid)
            self.display('merge.tmpl',
                         from_uuid=from_uuid, to_uuid=to_uuid)
        except NotFoundError as e:
            self.error(str(e))
            return e.code

        return CMD_SUCCESS
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / enroll.py View on Github external
msg = "enrollment for '%(uuid)s' at '%(org)s' (from: %(from_dt)s, to: %(to_dt)s) already exists in the registry"
                msg = msg % msg_data
                self.error(msg)
                code = e.code

        if not merge:
            return code

        try:
            api.merge_enrollments(self.db, uuid, organization)
        except (NotFoundError, InvalidValueError) as e:
            # These exceptions were checked above. If any of these raises
            # is due to something really wrong has happened
            raise RuntimeError(str(e))

        return CMD_SUCCESS
github chaoss / grimoirelab-sortinghat / sortinghat / cmd / remove.py View on Github external
if not uuid_or_id:
            return CMD_SUCCESS

        try:
            if not identity:
                api.delete_unique_identity(self.db, uuid_or_id)
            else:
                api.delete_identity(self.db, uuid_or_id)

            self.display('remove.tmpl',
                         uuid_or_id=uuid_or_id, identity=identity)
        except NotFoundError as e:
            self.error(str(e))
            return e.code

        return CMD_SUCCESS