How to use the sortinghat.api.add_enrollment 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
api.add_enrollment(self.db, 'John Doe', 'Example',
                           datetime.datetime(2010, 1, 2),
                           datetime.datetime(2100, 1, 1))
        api.add_enrollment(self.db, 'John Doe', 'Example',
                           datetime.datetime(2008, 1, 1),
                           datetime.datetime(2010, 1, 1))
        api.add_enrollment(self.db, 'John Doe', 'Example',
                           datetime.datetime(1900, 1, 1),
                           datetime.datetime(2010, 1, 1))

        api.add_unique_identity(self.db, 'Jane Rae')
        api.add_organization(self.db, 'Bitergia')
        api.add_enrollment(self.db, 'Jane Rae', 'Bitergia',
                           datetime.datetime(2010, 1, 2),
                           datetime.datetime(2100, 1, 1))
        api.add_enrollment(self.db, 'Jane Rae', 'Bitergia',
                           datetime.datetime(1900, 1, 1),
                           datetime.datetime(2010, 1, 1))

        # This enrollments will not be merged
        api.add_enrollment(self.db, 'John Smith', 'Bitergia',
                           datetime.datetime(1900, 1, 1),
                           datetime.datetime(2010, 1, 1))
        api.add_enrollment(self.db, 'John Smith', 'Bitergia',
                           datetime.datetime(2008, 1, 1),
                           datetime.datetime(2100, 1, 1))

        # Tests John Smith enrollments
        api.merge_enrollments(self.db, 'John Smith', 'Example')

        with self.db.connect() as session:
            enrollments = session.query(Enrollment).\
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_empty_results(self):
        "Check cases when the result is empty"

        # 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_unique_identity(self.db, 'Jane Rae')

        api.add_organization(self.db, 'Example')
        api.add_enrollment(self.db, 'John Smith', 'Example',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2005, 1, 1))
        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, 'John Doe', 'LibreSoft')

        api.add_organization(self.db, 'GSyC')

        # Test when there are not enrollments for a uuid
        enrollments = api.enrollments(self.db,
                                      uuid='Jane Rae')
        self.assertEqual(len(enrollments), 0)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_show.py View on Github external
jroe_uuid = api.add_identity(self.db, 'scm', 'jroe@example.com',
                                     'Jane Roe', 'jroe')
        api.add_identity(self.db, 'scm', 'jroe@example.com',
                         uuid=jroe_uuid)
        api.add_identity(self.db, 'unknown', 'jroe@bitergia.com',
                         uuid=jroe_uuid)
        api.edit_profile(self.db, jroe_uuid, name='Jane Roe', email='jroe@example.com',
                         is_bot=False, country_code='US')

        # Add unique identity, this one won't have neither identities
        # nor enrollments
        api.add_unique_identity(self.db,
                                '0000000000000000000000000000000000000000')

        # Add enrollments
        api.add_enrollment(self.db, jsmith_uuid, 'Example')

        api.add_enrollment(self.db, jroe_uuid, 'Example')
        api.add_enrollment(self.db, jroe_uuid, 'Bitergia',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2000, 1, 1))
        api.add_enrollment(self.db, jroe_uuid, 'Bitergia',
                           datetime.datetime(2006, 1, 1),
                           datetime.datetime(2008, 1, 1))
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
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')
        api.add_enrollment(self.db, 'John Doe', 'Example')

        api.add_organization(self.db, 'Bitergia')
        api.add_enrollment(self.db, 'John Smith', 'Bitergia')
        api.add_enrollment(self.db, 'John Doe', 'Bitergia',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2000, 1, 1))

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

        # Merge John Smith and John Doe unique identities
        api.merge_unique_identities(self.db, 'John Smith', 'John Doe')

        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).\
                    filter(Organization.name == 'Example').first()
            self.assertEqual(org1, None)

            dom1 = session.query(Domain).\
                    filter(Domain.domain == 'example.com').first()
            self.assertEqual(dom1, None)
            dom2 = session.query(Domain).\
                    filter(Domain.domain == 'example.org').first()
            self.assertEqual(dom2, None)
github chaoss / grimoirelab-sortinghat / tests / test_cmd_export.py View on Github external
api.edit_profile(self.db, jroe_uuid, name='Jane Roe', email='jroe@example.com',
                         is_bot=False, country_code='US')

        # Add unique identity, this one won't have neither identities
        # nor enrollments
        api.add_unique_identity(self.db,
                                '0000000000000000000000000000000000000000')

        # Add enrollments
        api.add_enrollment(self.db, jsmith_uuid, 'Example')

        api.add_enrollment(self.db, jroe_uuid, 'Example')
        api.add_enrollment(self.db, jroe_uuid, 'Bitergia',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2000, 1, 1))
        api.add_enrollment(self.db, jroe_uuid, 'Bitergia',
                           datetime.datetime(2006, 1, 1),
                           datetime.datetime(2008, 1, 1))

        # Add blacklist
        api.add_to_matching_blacklist(self.db, 'jroe@example.com')
        api.add_to_matching_blacklist(self.db, 'John Smith')
github chaoss / grimoirelab-sortinghat / tests / test_cmd_log.py View on Github external
def load_test_dataset(self):
        self.db.clear()

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

        api.add_organization(self.db, 'Example')
        api.add_organization(self.db, 'Bitergia')

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

        api.add_enrollment(self.db, 'John Smith', 'Bitergia')
        api.add_enrollment(self.db, 'John Smith', 'Bitergia',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2000, 1, 1))
        api.add_enrollment(self.db, 'John Smith', 'Bitergia',
                           datetime.datetime(2006, 1, 1),
                           datetime.datetime(2008, 1, 1))
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_delete_enrollments(self):
        """Check whether it deletes a set of enrollments"""

        # 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_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_enrollment(self.db, 'John Smith', 'Bitergia',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2000, 1, 1))
        api.add_organization(self.db, 'LibreSoft')
        api.add_enrollment(self.db, 'John Doe', 'LibreSoft')
        api.add_enrollment(self.db, 'Jane Rae', 'LibreSoft')

        # Delete some enrollments
        api.delete_enrollment(self.db, 'John Doe', 'LibreSoft')
        api.delete_enrollment(self.db, 'John Doe', 'Example')

        with self.db.connect() as session:
            enrollments = session.query(Enrollment).join(Organization).\
                    filter(Organization.name == 'LibreSoft').all()
            self.assertEqual(len(enrollments), 1)
            self.assertEqual(enrollments[0].uidentity.uuid, 'Jane Rae')
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_existing_enrollment(self):
        """Check if it fails adding enrollment data that already exists"""

        # Add unique identity, organization and enrollment first
        api.add_unique_identity(self.db, 'John Smith')
        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(2000, 1, 1))
        api.add_enrollment(self.db, 'John Smith', 'Example',
                           datetime.datetime(2005, 1, 1),
                           datetime.datetime(2006, 1, 1))

        # Same dates should raise an AlreadyExistsError exception.
        self.assertRaises(AlreadyExistsError, api.add_enrollment,
                          self.db, 'John Smith', 'Example')
        self.assertRaises(AlreadyExistsError, api.add_enrollment,
                          self.db, 'John Smith', 'Example',
                          datetime.datetime(1999, 1, 1),
                          datetime.datetime(2000, 1, 1))
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_delete_enrollments(self):
        """Check whether it deletes a set of enrollments"""

        # 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_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_enrollment(self.db, 'John Smith', 'Bitergia',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2000, 1, 1))
        api.add_organization(self.db, 'LibreSoft')
        api.add_enrollment(self.db, 'John Doe', 'LibreSoft')
        api.add_enrollment(self.db, 'Jane Rae', 'LibreSoft')

        # Delete some enrollments
        api.delete_enrollment(self.db, 'John Doe', 'LibreSoft')
        api.delete_enrollment(self.db, 'John Doe', 'Example')

        with self.db.connect() as session:
            enrollments = session.query(Enrollment).join(Organization).\
                    filter(Organization.name == 'LibreSoft').all()
            self.assertEqual(len(enrollments), 1)
            self.assertEqual(enrollments[0].uidentity.uuid, 'Jane Rae')