def setUp(self): if not hasattr(sys.stdout, 'getvalue'): self.fail('This test needs to be run in buffered mode') # Create a dataset to test the registry self.db = Database(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST, DB_PORT) api.add_organization(self.db, 'Example') api.add_domain(self.db, 'Example', 'example.com') api.add_domain(self.db, 'Example', 'example.org') api.add_domain(self.db, 'Example', 'example.net') api.add_organization(self.db, 'Bitergia') api.add_domain(self.db, 'Bitergia', 'bitergia.net') api.add_domain(self.db, 'Bitergia', 'bitergia.com', is_top_domain=True) api.add_organization(self.db, 'LibreSoft') # Create command self.kwargs = {'user' : DB_USER, 'password' : DB_PASSWORD, 'database' :DB_NAME, 'host' : DB_HOST, 'port' : DB_PORT} self.cmd = Organizations(**self.kwargs)
def test_registry_term(self): """Check if it returns the info about orgs using a search term""" # Add an extra organization first api.add_organization(self.db, 'MyExample') api.add_domain(self.db, 'MyExample', 'myexample.com') code = self.cmd.registry('Example') self.assertEqual(code, CMD_SUCCESS) output = sys.stdout.getvalue().strip() self.assertEqual(output, REGISTRY_OUTPUT_EXAMPLE)
def load_test_dataset(self): api.add_organization(self.db, 'Example') api.add_domain(self.db, 'Example', 'example.com') api.add_domain(self.db, 'Example', 'example.org') api.add_domain(self.db, 'Example', 'example.net') api.add_organization(self.db, 'Bitergia') api.add_domain(self.db, 'Bitergia', 'bitergia.net') api.add_domain(self.db, 'Bitergia', 'bitergia.com', is_top_domain=True) api.add_organization(self.db, 'LibreSoft')
def load_test_dataset(self): api.add_organization(self.db, 'Example') api.add_domain(self.db, 'Example', 'example.com') api.add_domain(self.db, 'Example', 'example.org') api.add_domain(self.db, 'Example', 'example.net') api.add_organization(self.db, 'Bitergia') api.add_domain(self.db, 'Bitergia', 'bitergia.net') api.add_domain(self.db, 'Bitergia', 'bitergia.com', is_top_domain=True) api.add_organization(self.db, 'LibreSoft')
def load_test_dataset(self): # Add some domains api.add_organization(self.db, 'Example') api.add_domain(self.db, 'Example', 'example.com', is_top_domain=True) api.add_organization(self.db, 'Example Alt') api.add_domain(self.db, 'Example Alt', 'u.example.com', is_top_domain=True) api.add_domain(self.db, 'Example Alt', 'es.u.example.com') api.add_domain(self.db, 'Example Alt', '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') # Add some unique identities jsmith_uuid = api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', 'jsmith') api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', uuid=jsmith_uuid) api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', 'jsmith', uuid=jsmith_uuid) api.add_enrollment(self.db, jsmith_uuid, 'Bitergia') # Add John Doe identity api.add_identity(self.db, 'unknown', None, 'John Doe', 'jdoe') # Add Jane Rae 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) # Add no valid email identity api.add_identity(self.db, 'test', 'novalidemail@')
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', '*****@*****.**', 'John Smith', 'jsmith') api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', uuid=jsmith_uuid) api.edit_profile(self.db, jsmith_uuid, email='*****@*****.**', gender="male", is_bot=True) # Add Jane 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_import_to_non_empty_registry(self): """Test load (and overwrite) process in a registry with some contents""" # First, load some data api.add_organization(self.db, 'Example') api.add_domain(self.db, 'Example', 'example.com') api.add_organization(self.db, 'Bitergia') api.add_domain(self.db, 'Bitergia', 'bitergia.net') api.add_domain(self.db, 'Bitergia', 'bitergia.com') # Import new data, overwriting existing relationships parser = self.get_parser(datadir('sortinghat_orgs_valid_alt.json')) self.cmd.import_organizations(parser, True) # Check the contents of the registry orgs = api.registry(self.db) self.assertEqual(len(orgs), 4) # Bitergia org = orgs[0] self.assertEqual(org.name, 'Bitergia') doms = org.domains self.assertEqual(len(doms), 4) dom = doms[0] self.assertEqual(dom.domain, 'api.bitergia.com') self.assertEqual(dom.is_top_domain, False) dom = doms[1] self.assertEqual(dom.domain, 'bitergia.com') self.assertEqual(dom.is_top_domain, True) dom = doms[2] self.assertEqual(dom.domain, 'bitergia.net') self.assertEqual(dom.is_top_domain, True) dom = doms[3] self.assertEqual(dom.domain, 'test.bitergia.com') self.assertEqual(dom.is_top_domain, False) # Example org = orgs[1] self.assertEqual(org.name, 'Example') doms = org.domains self.assertEqual(len(doms), 1) dom = doms[0] self.assertEqual(dom.domain, 'example.net') self.assertEqual(dom.is_top_domain, True) # GSyC/LibreSoft org = orgs[2] self.assertEqual(org.name, 'GSyC/LibreSoft') doms = org.domains self.assertEqual(len(doms), 2) dom = doms[0] self.assertEqual(dom.domain, 'example.com') self.assertEqual(dom.is_top_domain, True) dom = doms[1] self.assertEqual(dom.domain, 'libresoft.es') self.assertEqual(dom.is_top_domain, True) # Unknown org = orgs[3] self.assertEqual(org.name, 'Unknown') doms = org.domains self.assertEqual(len(doms), 0)
def test_import_to_non_empty_registry(self): """Test load (and overwrite) process in a registry with some contents""" # First, load some data api.add_organization(self.db, 'Example') api.add_domain(self.db, 'Example', 'example.com') api.add_organization(self.db, 'Bitergia') api.add_domain(self.db, 'Bitergia', 'bitergia.net') api.add_domain(self.db, 'Bitergia', 'bitergia.com') # Import new data, overwriting existing relationships parser = self.get_parser(datadir('sortinghat_orgs_valid_alt.json')) self.cmd.import_organizations(parser, True) # Check the contents of the registry orgs = api.registry(self.db) self.assertEqual(len(orgs), 4) # Bitergia org = orgs[0] self.assertEqual(org.name, 'Bitergia') doms = org.domains self.assertEqual(len(doms), 4) dom = doms[0] self.assertEqual(dom.domain, 'api.bitergia.com') self.assertEqual(dom.is_top_domain, False) dom = doms[1] self.assertEqual(dom.domain, 'bitergia.com') self.assertEqual(dom.is_top_domain, True) dom = doms[2] self.assertEqual(dom.domain, 'bitergia.net') self.assertEqual(dom.is_top_domain, True) dom = doms[3] self.assertEqual(dom.domain, 'test.bitergia.com') self.assertEqual(dom.is_top_domain, False) # Example org = orgs[1] self.assertEqual(org.name, 'Example') doms = org.domains self.assertEqual(len(doms), 1) dom = doms[0] self.assertEqual(dom.domain, 'example.net') self.assertEqual(dom.is_top_domain, True) # GSyC/LibreSoft org = orgs[2] self.assertEqual(org.name, 'GSyC/LibreSoft') doms = org.domains self.assertEqual(len(doms), 2) dom = doms[0] self.assertEqual(dom.domain, 'example.com') self.assertEqual(dom.is_top_domain, True) dom = doms[1] self.assertEqual(dom.domain, 'libresoft.es') self.assertEqual(dom.is_top_domain, True) # Unknown org = orgs[3] self.assertEqual(org.name, 'Unknown') doms = org.domains self.assertEqual(len(doms), 0)
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 _load_test_dataset(self): # Add some domains api.add_organization(self.db, 'Example') api.add_domain(self.db, 'Example', 'example.com', is_top_domain=True) api.add_organization(self.db, 'Example Alt') api.add_domain(self.db, 'Example Alt', 'u.example.com', is_top_domain=True) api.add_domain(self.db, 'Example Alt', 'es.u.example.com') api.add_domain(self.db, 'Example Alt', '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') # Add some unique identities jsmith_uuid = api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', 'jsmith') api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', uuid=jsmith_uuid) api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith', 'jsmith', uuid=jsmith_uuid) api.add_enrollment(self.db, jsmith_uuid, 'Bitergia') # Add John Doe identity api.add_identity(self.db, 'unknown', None, 'John Doe', 'jdoe') # Add Jane Rae 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)