def test_two_contacts(self): """Ensure building map of two contacts works.""" import copy from sosbeacon.event.student_marker import _hash_contact from sosbeacon.event.student_marker import _build_contact_map contacts = [{ 'name': 'joe', 'methods': [{ 'value': 123 }] }, { 'name': 'jim', 'methods': [{ 'value': 'asd' }] }] contact_map = _build_contact_map(copy.deepcopy(contacts)) good_map = { _hash_contact(contacts[0]): contacts[0], _hash_contact(contacts[1]): contacts[1], } self.assertEqual(good_map, contact_map)
def test_two_contacts(self): """Ensure building map of two contacts works.""" import copy from sosbeacon.event.student_marker import _hash_contact from sosbeacon.event.student_marker import _build_contact_map contacts = [{'name': 'joe', 'methods': [{'value': 123}]}, {'name': 'jim', 'methods': [{'value': 'asd'}]}] contact_map = _build_contact_map(copy.deepcopy(contacts)) good_map = { _hash_contact(contacts[0]): contacts[0], _hash_contact(contacts[1]): contacts[1], } self.assertEqual(good_map, contact_map)
def test_no_name_with_methods(self): """Ensure hashing with no name but with methods works.""" import hashlib from sosbeacon.event.student_marker import _hash_contact contact = {'methods': [{'value': 1}, {'value': 2}, {'value': 3}]} hashed = _hash_contact(contact) check_hash = hashlib.sha1(unicode('1|2|3|None')).hexdigest() self.assertEqual(check_hash, hashed)
def test_name_with_no_methods(self): """Ensure hashing name with no methods works.""" import hashlib from sosbeacon.event.student_marker import _hash_contact contact = {'name': 'jimmy'} hashed = _hash_contact(contact) check_hash = hashlib.sha1(unicode('jimmy')).hexdigest() self.assertEqual(check_hash, hashed)
def test_no_name_or_methods(self): """Ensure hashing with no name or methods works.""" import hashlib from sosbeacon.event.student_marker import _hash_contact contact = {} hashed = _hash_contact(contact) check_hash = hashlib.sha1(unicode(None)).hexdigest() self.assertEqual(check_hash, hashed)
def test_one_contact(self): """Ensure building map of one contact works.""" import copy from sosbeacon.event.student_marker import _hash_contact from sosbeacon.event.student_marker import _build_contact_map contacts = [{'name': 'joe', 'methods': [{'value': 123}]}] contact_map = _build_contact_map(copy.deepcopy(contacts)) contact_hash = _hash_contact(contacts[0]) self.assertEqual({contact_hash: contacts[0]}, contact_map)
def test_email_method(self): """Ensure hashing with name and methods works.""" import hashlib from sosbeacon.event.student_marker import _hash_contact contact = {'name': 'jim jones', 'methods': [{'value': '*****@*****.**'}, {'value': 2}, {'value': 3}]} hashed = _hash_contact(contact) check_hash = hashlib.sha1( unicode('2|3|jim jones|[email protected]')).hexdigest() self.assertEqual(check_hash, hashed)
def test_email_method(self): """Ensure hashing with name and methods works.""" import hashlib from sosbeacon.event.student_marker import _hash_contact contact = { 'name': 'jim jones', 'methods': [{ 'value': '*****@*****.**' }, { 'value': 2 }, { 'value': 3 }] } hashed = _hash_contact(contact) check_hash = hashlib.sha1( unicode('2|3|jim jones|[email protected]')).hexdigest() self.assertEqual(check_hash, hashed)