How to use the sortinghat.core.models.Individual.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_gender_not_given(self):
        """Check if it fails when gender_acc is given but not the gender"""

        individual = Individual.objects.create(mk='1234567890ABCDFE')
        Profile.objects.create(individual=individual)

        with self.assertRaisesRegex(ValueError, GENDER_ACC_INVALID_ERROR):
            db.update_profile(self.trxl, individual, gender_acc=100)

        # 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_operations(self):
        """Check if the right operations are created when moving an identity"""

        timestamp = datetime_utcnow()

        from_indv = Individual.objects.create(mk='AAAA')
        to_indv = Individual.objects.create(mk='BBBB')

        identity = Identity.objects.create(uuid='0001', name='John Smith',
                                           individual=from_indv)

        # Move identity
        db.move_identity(self.trxl, identity, to_indv)

        transactions = Transaction.objects.filter(name='move_identity')
        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.UPDATE.value)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_period_invalid(self):
        """Check whether enrollments cannot be added giving invalid period ranges"""

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

        data = {
            'start': r'2001-01-01 00:00:00\+00:00',
            'end': r'1999-01-01 00:00:00\+00:00'
        }
        msg = PERIOD_INVALID_ERROR.format(**data)

        with self.assertRaisesRegex(ValueError, msg):
            db.add_enrollment(self.trxl, individual, org,
                              start=datetime.datetime(2001, 1, 1, tzinfo=UTC),
                              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_last_modified(self):
        """Check if last modification date is updated"""

        mk = '1234567890ABCDFE'

        individual = Individual.objects.create(mk=mk)
        Profile.objects.create(individual=individual)

        before_dt = datetime_utcnow()
        db.update_profile(self.trxl, individual,
                          name='John Smith', email='jsmith@example.net')
        after_dt = datetime_utcnow()

        # Tests
        individual = Individual.objects.get(mk=mk)
        self.assertLessEqual(before_dt, individual.last_modified)
        self.assertGreaterEqual(after_dt, individual.last_modified)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_individual_not_found(self):
        """Test whether it raises an exception when the individual is not found"""

        mk = 'abcdefghijklmnopqrstuvwxyz'
        uuid = '1234567890'
        individual = Individual.objects.create(mk=mk)
        Identity.objects.create(uuid=mk, source='scm', individual=individual)
        Identity.objects.create(uuid=uuid, source='mls', individual=individual)

        with self.assertRaisesRegex(NotFoundError, INDIVIDUAL_NOT_FOUND_ERROR):
            db.find_individual_by_uuid('zyxwuv')
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_db.py View on Github external
def test_find_identity(self):
        """Test if an identity is found by its UUID"""

        mk = 'abcdefghijklmnopqrstuvwxyz'
        individual = Individual.objects.create(mk=mk)
        Identity.objects.create(uuid=mk, source='scm', individual=individual)

        identity = db.find_identity(mk)
        self.assertIsInstance(identity, Identity)
        self.assertEqual(identity.uuid, mk)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_delete_organization(self):
        """Check whether it deletes an organization and its related data"""

        org_ex = Organization.objects.create(name='Example')
        Domain.objects.create(domain='example.org',
                              organization=org_ex)
        org_bit = Organization.objects.create(name='Bitergia')

        jsmith = Individual.objects.create(mk='AAAA')
        Profile.objects.create(name='John Smith',
                               email='jsmith@example.net',
                               individual=jsmith)
        Enrollment.objects.create(individual=jsmith, organization=org_ex)

        jdoe = Individual.objects.create(mk='BBBB')
        Profile.objects.create(name='John Doe',
                               email='jdoe@bitergia.com',
                               individual=jdoe)
        Enrollment.objects.create(individual=jdoe, organization=org_ex)
        Enrollment.objects.create(individual=jdoe, organization=org_bit)

        # Check data and remove organization
        org_ex.refresh_from_db()
        self.assertEqual(len(org_ex.domains.all()), 1)
        self.assertEqual(len(org_ex.enrollments.all()), 2)
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_identity_not_found(self):
        """Test whether it raises an exception when the identity is not found"""

        mk = 'abcdefghijklmnopqrstuvwxyz'
        individual = Individual.objects.create(mk=mk)
        Identity.objects.create(uuid=mk, source='scm', individual=individual)

        with self.assertRaisesRegex(NotFoundError, IDENTITY_NOT_FOUND_ERROR):
            db.find_identity('zyxwuv')
github chaoss / grimoirelab-sortinghat / tests / test_db.py View on Github external
def test_country_code_not_valid(self):
        """Check if it fails when the given country is not valid"""

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

        individual = Individual.objects.create(mk='1234567890ABCDFE')
        Profile.objects.create(individual=individual)

        msg = COUNTRY_CODE_ERROR.format(code='JKL')

        with self.assertRaisesRegex(ValueError, msg):
            db.update_profile(self.trxl, individual, country_code='JKL')

        # Check if operations have not been generated after the failure
        operations = Operation.objects.all()
        self.assertEqual(len(operations), 0)