def test_to_dict(self):
        """Test output of to_dict() method"""

        uid = UniqueIdentity(uuid='John Smith')
        self.session.add(uid)

        c = Country(code='US', name='United States of America', alpha3='USA')
        self.session.add(c)

        prf = Profile(uuid='John Smith', name='Smith, J.',
                      email='*****@*****.**', is_bot=True,
                      country_code='US')

        self.session.add(prf)
        self.session.commit()

        # Tests
        d = prf.to_dict()

        self.assertIsInstance(d, dict)
        self.assertEqual(d['uuid'], 'John Smith')
        self.assertEqual(d['name'], 'Smith, J.')
        self.assertEqual(d['email'], '*****@*****.**')
        self.assertEqual(d['is_bot'], True)
        self.assertEqual(d['country']['code'], 'US')
        self.assertEqual(d['country']['name'], 'United States of America')

        # No country set
        prf = Profile(uuid='John Smith', name='Smith, J.',
                      email='*****@*****.**', is_bot=True,
                      country_code=None)

        d = prf.to_dict()
        self.assertEqual(d['country'], None)
Exemple #2
0
    def test_unique_profile(self):
        """Check if there is only one profile for each unique identity"""

        uid = UniqueIdentity(uuid='John Smith')
        self.session.add(uid)

        prf1 = Profile(uuid='John Smith', name='John Smith')
        prf2 = Profile(uuid='John Smith', name='Smith, J.')

        with self.assertRaisesRegexp(IntegrityError, DUP_CHECK_ERROR):
            self.session.add(prf1)
            self.session.add(prf2)
            self.session.commit()
Exemple #3
0
    def test_is_bot_invalid_type(self):
        """Check invalid values on is_bot bool column"""

        with self.assertRaisesRegexp(StatementError, INVALID_DATATYPE_ERROR):
            uid = UniqueIdentity(uuid='John Smith')
            self.session.add(uid)

            prf = Profile(uuid='John Smith', name='John Smith', is_bot='True')

            self.session.add(prf)
            self.session.commit()
Exemple #4
0
    def test_to_dict(self):
        """Test output of to_dict() method"""

        uid = UniqueIdentity(uuid='John Smith')
        self.session.add(uid)

        c = Country(code='US', name='United States of America', alpha3='USA')
        self.session.add(c)

        prf = Profile(uuid='John Smith', name='Smith, J.',
                      email='*****@*****.**', is_bot=True,
                      country_code='US')

        self.session.add(prf)
        self.session.commit()

        # Tests
        d = prf.to_dict()

        self.assertIsInstance(d, dict)
        self.assertEqual(d['uuid'], 'John Smith')
        self.assertEqual(d['name'], 'Smith, J.')
        self.assertEqual(d['email'], '*****@*****.**')
        self.assertEqual(d['is_bot'], True)
        self.assertEqual(d['country']['code'], 'US')
        self.assertEqual(d['country']['name'], 'United States of America')

        # No country set
        prf = Profile(uuid='John Smith', name='Smith, J.',
                      email='*****@*****.**', is_bot=True,
                      country_code=None)

        d = prf.to_dict()
        self.assertEqual(d['country'], None)
Exemple #5
0
    def test_get_profile_sh(self):
        """Test whether a profile from sortinghat model is correctly retrieved as a dict"""

        p = Profile()
        p.name = 'pepe'
        p.email = '*****@*****.**'
        p.gender = 'male'
        p.gender_acc = 100
        uidentity = UniqueIdentity()
        uidentity.profile = p

        vals = {'00000': uidentity}

        def side_effect(uuid):
            return vals[uuid]
        self._enrich.get_unique_identity = MagicMock(side_effect=side_effect)

        profile = self._enrich.get_profile_sh('00000')
        self.assertEqual(profile['name'], uidentity.profile.name)
        self.assertEqual(profile['email'], uidentity.profile.email)
        self.assertEqual(profile['gender'], uidentity.profile.gender)
        self.assertEqual(profile['gender_acc'], uidentity.profile.gender_acc)
Exemple #6
0
    def test_to_dict(self):
        """Test output of to_dict() method"""

        c = Country(code='US', name='United States of America', alpha3='USA')
        self.session.add(c)

        uid = UniqueIdentity(uuid='John Smith')
        self.session.add(uid)

        id1 = Identity(id='A',
                       name='John Smith',
                       email='*****@*****.**',
                       username='******',
                       source='scm',
                       uuid='John Smith')
        id2 = Identity(id='B',
                       name=None,
                       email='*****@*****.**',
                       username=None,
                       source='scm',
                       uuid='John Smith')

        self.session.add(id1)
        self.session.add(id2)
        self.session.commit()

        # Tests
        d = uid.to_dict()

        self.assertIsInstance(d, dict)
        self.assertEqual(d['uuid'], 'John Smith')

        self.assertEqual(d['profile'], None)

        identities = d['identities']
        self.assertEqual(len(identities), 2)

        d0 = d['identities'][0]
        self.assertEqual(d0['id'], 'A')
        self.assertEqual(d0['name'], 'John Smith')
        self.assertEqual(d0['email'], '*****@*****.**')
        self.assertEqual(d0['username'], 'jsmith')
        self.assertEqual(d0['source'], 'scm')
        self.assertEqual(d0['uuid'], 'John Smith')

        d1 = d['identities'][1]
        self.assertEqual(d1['id'], 'B')
        self.assertEqual(d1['name'], None)
        self.assertEqual(d1['email'], '*****@*****.**')
        self.assertEqual(d1['username'], None)
        self.assertEqual(d1['source'], 'scm')
        self.assertEqual(d1['uuid'], 'John Smith')

        prf = Profile(uuid='John Smith',
                      name='Smith, J.',
                      email='*****@*****.**',
                      is_bot=True,
                      country_code='US')

        # Add profile information
        self.session.add(prf)
        self.session.commit()

        d = uid.to_dict()

        dp = d['profile']
        self.assertEqual(dp['uuid'], 'John Smith')
        self.assertEqual(dp['name'], 'Smith, J.')
        self.assertEqual(dp['email'], '*****@*****.**')
        self.assertEqual(dp['is_bot'], True)
        self.assertEqual(dp['country']['code'], 'US')
        self.assertEqual(dp['country']['name'], 'United States of America')