How to use the sortinghat.api.add_organization 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_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_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
        api.delete_enrollment(self.db, 'John Smith', 'Example',
                              datetime.datetime(1970, 1, 1),
                              datetime.datetime(1995, 1, 1))
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_get_domains(self):
        """Check if it returns the registry of domains"""

        # Add some domains
        api.add_organization(self.db, 'Example')
        api.add_domain(self.db, 'Example', 'example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'u.example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'es.u.example.com')
        api.add_domain(self.db, 'Example', 'en.u.example.com')

        api.add_organization(self.db, 'Bitergia')
        api.add_domain(self.db, 'Bitergia', 'bitergia.com')
        api.add_domain(self.db, 'Bitergia', 'bitergia.org')

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

        doms = api.domains(self.db)
        self.assertEqual(len(doms), 6)

        dom0 = doms[0]
        self.assertIsInstance(dom0, Domain)
        self.assertEqual(dom0.domain, 'bitergia.com')
        self.assertEqual(dom0.organization.name, 'Bitergia')

        dom1 = doms[1]
        self.assertIsInstance(dom1, Domain)
        self.assertEqual(dom1.domain, 'bitergia.org')
        self.assertEqual(dom1.organization.name, 'Bitergia')

        dom2 = doms[2]
        self.assertIsInstance(dom2, Domain)
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_top_domains(self):
        """Check top domains option"""

        # Add some domains
        api.add_organization(self.db, 'Example')
        api.add_domain(self.db, 'Example', 'example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'u.example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'es.u.example.com')
        api.add_domain(self.db, 'Example', 'en.u.example.com')

        api.add_organization(self.db, 'Bitergia')
        api.add_domain(self.db, 'Bitergia', 'bitergia.com')
        api.add_domain(self.db, 'Bitergia', 'bitergia.org')

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

        # Look only for top domains
        doms = api.domains(self.db, top=True)
        self.assertEqual(len(doms), 2)

        dom0 = doms[0]
        self.assertIsInstance(dom0, Domain)
        self.assertEqual(dom0.domain, 'example.com')
        self.assertEqual(dom0.organization.name, 'Example')

        dom1 = doms[1]
        self.assertIsInstance(dom1, Domain)
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
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')

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

            identities = session.query(Identity).join(UniqueIdentity).\
                filter(UniqueIdentity.uuid == 'John Smith').all()
            self.assertEqual(len(identities), 0)

            enrollments = session.query(Enrollment).join(UniqueIdentity).\
                filter(UniqueIdentity.uuid == 'John Smith').all()
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')
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:
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_top_domains(self):
        """Check top domains option"""

        # Add some domains
        api.add_organization(self.db, 'Example')
        api.add_domain(self.db, 'Example', 'example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'u.example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'es.u.example.com')
        api.add_domain(self.db, 'Example', 'en.u.example.com')

        api.add_organization(self.db, 'Bitergia')
        api.add_domain(self.db, 'Bitergia', 'bitergia.com')
        api.add_domain(self.db, 'Bitergia', 'bitergia.org')

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

        # Look only for top domains
        doms = api.domains(self.db, top=True)
        self.assertEqual(len(doms), 2)

        dom0 = doms[0]
        self.assertIsInstance(dom0, Domain)
        self.assertEqual(dom0.domain, 'example.com')
        self.assertEqual(dom0.organization.name, 'Example')

        dom1 = doms[1]
        self.assertIsInstance(dom1, Domain)
        self.assertEqual(dom1.domain, 'u.example.com')
        self.assertEqual(dom1.organization.name, 'Example')

        # Look top domains of the given domain
github chaoss / grimoirelab-sortinghat / tests / test_cmd_export.py View on Github external
def load_test_dataset(self):
        # Add country
        with self.db.connect() as session:
            # Add a country
            us = Country(code='US', name='United States of America', alpha3='USA')
            session.add(us)

        # Add organizations
        api.add_organization(self.db, 'Example')
        api.add_domain(self.db, 'Example', 'example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'example.net', is_top_domain=True)

        api.add_organization(self.db, 'Bitergia')
        api.add_domain(self.db, 'Bitergia', 'bitergia.net', is_top_domain=True)
        api.add_domain(self.db, 'Bitergia', 'bitergia.com', is_top_domain=True)
        api.add_domain(self.db, 'Bitergia', 'api.bitergia.com', is_top_domain=False)
        api.add_domain(self.db, 'Bitergia', 'test.bitergia.com', is_top_domain=False)

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

        # Add John Smith identity
        jsmith_uuid = api.add_identity(self.db, 'scm', 'jsmith@example.com',
                                       'John Smith', 'jsmith')
        api.add_identity(self.db, 'scm', 'jsmith@example.com', 'John Smith',
                         uuid=jsmith_uuid)
github chaoss / grimoirelab-sortinghat / tests / test_api.py View on Github external
def test_get_registry_term(self):
        """Check if it returns the info about orgs using a search term"""

        api.add_organization(self.db, 'Example')
        api.add_domain(self.db, 'Example', 'example.com')
        api.add_domain(self.db, 'Example', 'example.org')
        api.add_organization(self.db, 'Bitergia')
        api.add_domain(self.db, 'Bitergia', 'bitergia.com')
        api.add_organization(self.db, 'My Example')
        api.add_domain(self.db, 'My Example', 'myexample.com')

        # This query have to return two organizations
        orgs = api.registry(self.db, 'Example')
        self.assertEqual(len(orgs), 2)

        # Example organization
        org = orgs[0]
        self.assertIsInstance(org, Organization)
        self.assertEqual(org.name, 'Example')
        self.assertEqual(len(org.domains), 2)

        domains = org.domains
        domains.sort(key=lambda x: x.domain)

        dom = domains[0]