Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_delete_blacklisted_entity(self):
"""Check whether it deletes a set of blacklisted entities"""
# First, add a set of blacklisted entities
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'Bitergia')
api.add_to_matching_blacklist(self.db, 'John Doe')
# Delete the first entity
api.delete_from_matching_blacklist(self.db, 'root@example.com')
with self.db.connect() as session:
mb1 = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'root@example.net').first()
self.assertEqual(mb1, None)
# Delete the last entity
api.delete_from_matching_blacklist(self.db, 'John Doe')
with self.db.connect() as session:
mb2 = session.query(MatchingBlacklist).\
def test_not_found_term(self):
"""Check whether it raises an error when the term is not found"""
# It should raise an error when the blacklist is empty
self.assertRaises(NotFoundError, api.blacklist, self.db, 'jane')
# It should do the same when there are some orgs available
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'John Smith')
self.assertRaises(NotFoundError, api.blacklist, self.db, 'jane')
def test_get_blacklist_term(self):
"""Check if it returns the info about blacklisted entities using a search term"""
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'John Smith')
api.add_to_matching_blacklist(self.db, 'Bitergia')
api.add_to_matching_blacklist(self.db, 'John Doe')
# This query have to return two entries
mbs = api.blacklist(self.db, 'ohn')
self.assertEqual(len(mbs), 2)
# John Doe
mb = mbs[0]
self.assertIsInstance(mb, MatchingBlacklist)
self.assertEqual(mb.excluded, 'John Doe')
mb = mbs[1]
self.assertIsInstance(mb, MatchingBlacklist)
self.assertEqual(mb.excluded, 'John Smith')
def test_get_blacklist(self):
"""Check if it returns the blacklist"""
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'John Smith')
api.add_to_matching_blacklist(self.db, 'Bitergia')
api.add_to_matching_blacklist(self.db, 'John Doe')
mbs = api.blacklist(self.db)
self.assertEqual(len(mbs), 4)
with self.db.connect() as session:
mb = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'root@example.com').first()
self.assertEqual(mb.excluded, 'root@example.com')
mb = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'Bitergia').first()
self.assertEqual(mb.excluded, 'Bitergia')
mb = session.query(MatchingBlacklist).\
'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, 'jroe@example.com')
api.add_to_matching_blacklist(self.db, 'John Smith')
def load_test_dataset(self):
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'John Smith')
api.add_to_matching_blacklist(self.db, 'Bitergia')
api.add_to_matching_blacklist(self.db, 'John Doe')
def test_delete_blacklisted_entity(self):
"""Check whether it deletes a set of blacklisted entities"""
# First, add a set of blacklisted entities
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'Bitergia')
api.add_to_matching_blacklist(self.db, 'John Doe')
# Delete the first entity
api.delete_from_matching_blacklist(self.db, 'root@example.com')
with self.db.connect() as session:
mb1 = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'root@example.net').first()
self.assertEqual(mb1, None)
# Delete the last entity
api.delete_from_matching_blacklist(self.db, 'John Doe')
with self.db.connect() as session:
mb2 = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'John Doe').first()
self.assertEqual(mb2, None)
def test_existing_excluded_entity(self):
"""Check if it fails adding an entity that already exists"""
# Add a pair of entities first
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'John Doe')
# Insert the first entity. It should raise AlreadyExistsError
self.assertRaises(AlreadyExistsError, api.add_to_matching_blacklist,
self.db, 'root@example.com')
def test_none_entity(self):
"""Check whether None entities cannot be added to the registry"""
self.assertRaisesRegexp(ValueError,
ENTITY_BLACKLIST_NONE_OR_EMPTY_ERROR,
api.add_to_matching_blacklist, self.db, None)
def test_get_blacklist(self):
"""Check if it returns the blacklist"""
api.add_to_matching_blacklist(self.db, 'root@example.com')
api.add_to_matching_blacklist(self.db, 'John Smith')
api.add_to_matching_blacklist(self.db, 'Bitergia')
api.add_to_matching_blacklist(self.db, 'John Doe')
mbs = api.blacklist(self.db)
self.assertEqual(len(mbs), 4)
with self.db.connect() as session:
mb = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'root@example.com').first()
self.assertEqual(mb.excluded, 'root@example.com')
mb = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'Bitergia').first()
self.assertEqual(mb.excluded, 'Bitergia')
mb = session.query(MatchingBlacklist).\
filter(MatchingBlacklist.excluded == 'John Doe').first()
self.assertEqual(mb.excluded, 'John Doe')