def test_update_current_employees(session, data_source): create_new_employees_from_list(data_source) user = User.query.filter(User.email == '*****@*****.**').one() assert user.photo_url == 'www.cdn.com/SamSmith.png' assert user.meta_data == { 'department': 'Engineering', 'title': 'Engineer', 'floor': '10', 'desk': '100', 'manager': 'Bo Demillo' } local_data_employee = {user.email: user for user in User.query.all()} remote_data_employee = hash_employee_data(data_source) remote_data_employee['*****@*****.**']['photo_url'] = 'new' remote_data_employee['*****@*****.**']['department'] = 'Sales' remote_data_employee['*****@*****.**']['metadata'][ 'department'] = 'Sales' update_current_employees(local_data_employee, remote_data_employee) user = User.query.filter(User.email == '*****@*****.**').one() assert user.photo_url == 'new' assert user.meta_data['department'] == 'Sales' assert user.meta_data == { 'department': 'Sales', 'title': 'Engineer', 'floor': '10', 'desk': '100', 'manager': 'Bo Demillo' }
def test_hash_employee_data(data_source, data_source_by_key): """ Given a json object, return a dictionary by email of users. """ employees = hash_employee_data(data_source) assert len(list(employees.keys())) == 2 assert set( employees.keys()) == {'*****@*****.**', '*****@*****.**'} assert employees['*****@*****.**']['last_name'] == 'Smith'
def test_hash_employee_data_errors_with_no_email(data_source, data_source_by_key): data = data_source del data[0]['email'] with pytest.raises(KeyError): hash_employee_data(data)