How to use the sortinghat.core.models.Organization.objects.create 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_db.py View on Github external
def test_no_identity(self):
        """Test if an empty set is returned when there identity does not exist"""

        individual_a = Individual.objects.create(mk='AAAA')
        example_org = Organization.objects.create(name='Example')

        Enrollment.objects.create(individual=individual_a, organization=example_org,
                                  start=datetime.datetime(1999, 1, 1, tzinfo=UTC),
                                  end=datetime.datetime(2000, 1, 1, tzinfo=UTC))

        # Tests
        enrollments = db.search_enrollments_in_period('BBBB', 'Example',
                                                      from_date=datetime.datetime(1999, 1, 1, tzinfo=UTC),
                                                      to_date=datetime.datetime(2000, 1, 1, tzinfo=UTC))
        self.assertEqual(len(enrollments), 0)
github chaoss / grimoirelab-sortinghat / tests / test_schema.py View on Github external
def test_add_domain(self):
        """Check if a new domain is added"""

        Organization.objects.create(name='Example')

        client = graphene.test.Client(schema)
        executed = client.execute(self.SH_ADD_DOMAIN,
                                  context_value=self.context_value)

        # Check result
        dom = executed['data']['addDomain']['domain']
        self.assertEqual(dom['domain'], 'example.net')
        self.assertEqual(dom['isTopDomain'], True)
        self.assertEqual(dom['organization']['name'], 'Example')

        # Check database
        org = Organization.objects.get(name='Example')
        domains = org.domains.all()
        self.assertEqual(len(domains), 1)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_delete_enrollment(self):
        """Check whether it deletes an enrollment"""

        from_date = datetime.datetime(1999, 1, 1, tzinfo=UTC)
        first_period = datetime.datetime(2000, 1, 1, tzinfo=UTC)
        second_period = datetime.datetime(2010, 1, 1, tzinfo=UTC)
        to_date = datetime.datetime(2010, 1, 1, tzinfo=UTC)

        jsmith = Individual.objects.create(mk='AAAA')
        Identity.objects.create(uuid='0001', name='John Smith',
                                individual=jsmith)

        example_org = Organization.objects.create(name='Example')
        Enrollment.objects.create(individual=jsmith, organization=example_org,
                                  start=from_date, end=first_period)
        enrollment = Enrollment.objects.create(individual=jsmith, organization=example_org,
                                               start=second_period, end=to_date)

        bitergia_org = Organization.objects.create(name='Bitergia')
        Enrollment.objects.create(individual=jsmith, organization=bitergia_org,
                                  start=first_period, end=second_period)

        # Check data and remove enrollment
        jsmith.refresh_from_db()
        self.assertEqual(len(jsmith.identities.all()), 1)
        self.assertEqual(len(jsmith.enrollments.all()), 3)

        db.delete_enrollment(self.trxl, enrollment)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_operations(self):
        """Check if the right operations are created when deleting a domain"""

        timestamp = datetime_utcnow()
        mk = '1234567890ABCDFE'

        # Load initial dataset
        individual = Individual.objects.create(mk=mk)
        org = Organization.objects.create(name='Example')

        start = datetime.datetime(1999, 1, 1, tzinfo=UTC)
        end = datetime.datetime(2000, 1, 1, tzinfo=UTC)

        # Add the enrollment
        db.add_enrollment(self.trxl, individual, org, start=start, end=end)

        transactions = Transaction.objects.filter(name='enroll')
        trx = transactions[0]

        operations = Operation.objects.filter(trx=trx)
        self.assertEqual(len(operations), 1)

        op1 = operations[0]
        self.assertIsInstance(op1, Operation)
        self.assertEqual(op1.op_type, Operation.OpType.ADD.value)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_from_date_none(self):
        """Check if an enrollment cannot be added when from_date is None"""

        individual = Individual.objects.create(mk='1234567890ABCDFE')
        org = Organization.objects.create(name='Example')

        with self.assertRaisesRegex(ValueError, START_DATE_NONE_ERROR):
            db.add_enrollment(self.trxl, individual, org,
                              start=None, end=datetime.datetime(1999, 1, 1, tzinfo=UTC))

        # Check if operations have not been generated after the failure
        operations = Operation.objects.all()
        self.assertEqual(len(operations), 0)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_locked_individual(self):
        """Check if if fails when the individual is locked"""

        jsmith = Individual.objects.create(mk='AAAA', is_locked=True)
        org = Organization.objects.create(name='Example')
        start = datetime.datetime(1999, 1, 1, tzinfo=UTC)
        end = datetime.datetime(2000, 1, 1, tzinfo=UTC)

        msg = INDIVIDUAL_LOCKED_ERROR.format(mk='AAAA')
        with self.assertRaisesRegex(LockedIdentityError, msg):
            db.add_enrollment(self.trxl, jsmith, org, start=start, end=end)
github chaoss / grimoirelab-sortinghat / tests / test_schema.py View on Github external
def test_pagination(self):
        """Check whether it returns the organizations searched when using pagination"""

        org1 = Organization.objects.create(name='Example')
        org2 = Organization.objects.create(name='Bitergia')
        org3 = Organization.objects.create(name='LibreSoft')

        client = graphene.test.Client(schema)
        test_query = SH_ORGS_QUERY_PAGINATION % (1, 2)
        executed = client.execute(test_query,
                                  context_value=self.context_value)

        orgs = executed['data']['organizations']['entities']
        self.assertEqual(len(orgs), 2)

        # As organizations are sorted by name, the first two will be org2 and org1
        org = orgs[0]
        self.assertEqual(org['name'], org2.name)

        org = orgs[1]
        self.assertEqual(org['name'], org1.name)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_no_organization(self):
        """Test if an empty set is returned when there organization does not exist"""

        individual_a = Individual.objects.create(mk='AAAA')
        example_org = Organization.objects.create(name='Example')

        Enrollment.objects.create(individual=individual_a, organization=example_org,
                                  start=datetime.datetime(1999, 1, 1, tzinfo=UTC),
                                  end=datetime.datetime(2000, 1, 1, tzinfo=UTC))

        # Tests
        enrollments = db.search_enrollments_in_period('AAAA', 'Bitergia',
                                                      from_date=datetime.datetime(1999, 1, 1, tzinfo=UTC),
                                                      to_date=datetime.datetime(2000, 1, 1, tzinfo=UTC))
        self.assertEqual(len(enrollments), 0)
github chaoss / grimoirelab-sortinghat / tests / test_schema.py View on Github external
def test_unique_identities(self):
        """Check if it returns the registry of unique identities"""

        cn = Country.objects.create(code='US',
                                    name='United States of America',
                                    alpha3='USA')

        org_ex = Organization.objects.create(name='Example')
        org_bit = Organization.objects.create(name='Bitergia')

        uid = UniqueIdentity.objects.create(uuid='a9b403e150dd4af8953a52a4bb841051e4b705d9')
        Profile.objects.create(name=None,
                               email='jsmith@example.com',
                               is_bot=True,
                               gender='M',
                               country=cn,
                               uidentity=uid)
        Identity.objects.create(id='A001',
                                name='John Smith',
                                email='jsmith@example.com',
                                username='jsmith',
                                source='scm',
                                uidentity=uid)
        Identity.objects.create(id='A002',
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_no_enrollments_in_period(self):
        """Test if an empty set is returned when there are not enrollments for a given period"""

        individual_a = Individual.objects.create(mk='AAAA')
        example_org = Organization.objects.create(name='Example')

        Enrollment.objects.create(individual=individual_a, organization=example_org,
                                  start=datetime.datetime(1999, 1, 1, tzinfo=UTC),
                                  end=datetime.datetime(2000, 1, 1, tzinfo=UTC))

        # Tests
        enrollments = db.search_enrollments_in_period('AAAA', 'Example',
                                                      from_date=datetime.datetime(2000, 2, 1, tzinfo=UTC),
                                                      to_date=datetime.datetime(2009, 1, 1, tzinfo=UTC))
        self.assertEqual(len(enrollments), 0)