def test_unique_alpha3(self): """Check whether alpha3 codes are unique""" with self.assertRaisesRegexp(IntegrityError, DUP_CHECK_ERROR): c1 = Country(code='ES', name='Spain', alpha3='ESP') self.session.add(c1) c2 = Country(code='E', name='Spain', alpha3='ESP') self.session.add(c2) self.session.commit()
def load_test_dataset(self): with self.db.connect() as session: us = Country(code='US', name='United States of America', alpha3='USA') es = Country(code='ES', name='Spain', alpha3='ESP') gb = Country(code='GB', name='United Kingdom', alpha3='GBR') session.add(es) session.add(us) session.add(gb)
def test_to_dict(self): """Test output of to_dict() method""" c = Country(code='ES', name='Spain', alpha3='ESP') self.session.add(c) # Tests d = c.to_dict() self.assertIsInstance(d, dict) self.assertEqual(d['code'], 'ES') self.assertEqual(d['name'], 'Spain') self.assertEqual(d['alpha3'], 'ESP')
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) api.add_unique_identity(self.db, 'John Smith') api.add_identity(self.db, 'scm', '*****@*****.**', uuid='John Smith') api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', uuid='John Smith') api.edit_profile(self.db, 'John Smith', name='John Smith', is_bot=False) api.add_unique_identity(self.db, 'John Doe') api.add_identity(self.db, 'scm', '*****@*****.**', uuid='John Doe') api.edit_profile(self.db, 'John Doe', email='*****@*****.**', is_bot=True, country_code='US') 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')
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)
def _load_test_dataset(self): import datetime self.db.clear() # 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', '*****@*****.**', 'John Smith', 'jsmith') api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', uuid=jsmith_uuid) api.edit_profile(self.db, jsmith_uuid, email='*****@*****.**', is_bot=True) # Add Joe Roe identity jroe_uuid = api.add_identity(self.db, 'scm', '*****@*****.**', 'Jane Roe', 'jroe') api.add_identity(self.db, 'scm', '*****@*****.**', uuid=jroe_uuid) api.add_identity(self.db, 'unknown', '*****@*****.**', uuid=jroe_uuid) api.edit_profile(self.db, jroe_uuid, name='Jane Roe', email='*****@*****.**', 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, '*****@*****.**') api.add_to_matching_blacklist(self.db, 'John Smith')
def test_none_alpha3_country(self): """Check whether countries without alpha3 code can be stored""" with self.assertRaisesRegex(IntegrityError, NULL_CHECK_ERROR): c = Country(code='ES', name='Spain') self.session.add(c) self.session.commit()
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)
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 identity api.add_identity(self.db, 'scm', '*****@*****.**', 'Jane Roe', 'jroe')
def test_none_alpha3_country(self): """Check whether countries without alpha3 code can be stored""" if sys.version_info[0] >= 3: # Python 3 expected = IntegrityError else: # Python 2 expected = OperationalError with self.assertRaisesRegexp(expected, NULL_CHECK_ERROR): c = Country(code='ES', name='Spain') self.session.add(c) self.session.commit()
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 identities api.add_identity(self.db, 'scm', '*****@*****.**', 'Jane Roe', 'jroe') jsmith_uuid = api.add_identity(self.db, 'mls', '*****@*****.**', None, None) api.add_identity(self.db, 'its', '*****@*****.**', None, 'jsmith', uuid=jsmith_uuid) api.add_identity(self.db, 'mls', '*****@*****.**', 'John Smith', 'jsmith', uuid=jsmith_uuid) api.add_identity(self.db, 'mls', '*****@*****.**', 'J S', None, uuid=jsmith_uuid) jdoe_uuid = api.add_identity(self.db, 'scm', '*****@*****.**', None, 'jdoe') api.add_identity(self.db, 'its', None, None, 'jdoe', uuid=jdoe_uuid)
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')